vtkPVFoamPatchField.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 InClass
25  vtkPVFoam
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #ifndef vtkPVFoamPatchField_H
30 #define vtkPVFoamPatchField_H
31 
32 // VTK includes
33 #include "vtkCellData.h"
34 #include "vtkFloatArray.h"
35 #include "vtkMultiBlockDataSet.h"
36 #include "vtkPointData.h"
37 #include "vtkPolyData.h"
38 
39 #include "vtkOpenFOAMTupleRemap.H"
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 template<class Type>
44 void Foam::vtkPVFoam::convertPatchField
45 (
46  const word& name,
47  const Field<Type>& ptf,
48  vtkMultiBlockDataSet* output,
49  const arrayRange& range,
50  const label datasetNo
51 )
52 {
53  const label nComp = pTraits<Type>::nComponents;
54 
55  vtkFloatArray* cellData = vtkFloatArray::New();
56  cellData->SetNumberOfTuples(ptf.size());
57  cellData->SetNumberOfComponents(nComp);
58  cellData->Allocate(nComp*ptf.size());
59  cellData->SetName(name.c_str());
60 
61  float vec[nComp];
62  forAll(ptf, i)
63  {
64  const Type& t = ptf[i];
65  for (direction d=0; d<nComp; ++d)
66  {
67  vec[d] = component(t, d);
68  }
69  vtkOpenFOAMTupleRemap<Type>(vec);
70 
71  cellData->InsertTuple(i, vec);
72  }
73 
74  vtkPolyData::SafeDownCast
75  (
76  GetDataSetFromBlock(output, range, datasetNo)
77  ) ->GetCellData()
78  ->AddArray(cellData);
79 
80  cellData->Delete();
81 }
82 
83 
84 // as above, but with PointData()
85 template<class Type>
86 void Foam::vtkPVFoam::convertPatchPointField
87 (
88  const word& name,
89  const Field<Type>& pptf,
90  vtkMultiBlockDataSet* output,
91  const arrayRange& range,
92  const label datasetNo
93 )
94 {
95  const label nComp = pTraits<Type>::nComponents;
96 
97  vtkFloatArray* pointData = vtkFloatArray::New();
98  pointData->SetNumberOfTuples(pptf.size());
99  pointData->SetNumberOfComponents(nComp);
100  pointData->Allocate(nComp*pptf.size());
101  pointData->SetName(name.c_str());
102 
103  float vec[nComp];
104  forAll(pptf, i)
105  {
106  const Type& t = pptf[i];
107  for (direction d=0; d<nComp; ++d)
108  {
109  vec[d] = component(t, d);
110  }
111  vtkOpenFOAMTupleRemap<Type>(vec);
112 
113  pointData->InsertTuple(i, vec);
114  }
115 
116  vtkPolyData::SafeDownCast
117  (
118  GetDataSetFromBlock(output, range, datasetNo)
119  ) ->GetPointData()
120  ->AddArray(pointData);
121 
122  pointData->Delete();
123 }
124 
125 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
126 
127 #endif
128 
129 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
uint8_t direction
Definition: direction.H:45
autoPtr< BasicCompressibleMomentumTransportModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const typename BasicCompressibleMomentumTransportModel::transportModel &transport)
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)