vtkPVFoamLagrangianFields.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-2025 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 vtkPVFoamLagrangianFields_H
30 #define vtkPVFoamLagrangianFields_H
31 
32 #include "vtkPVFoam.H"
33 #include "vtkPVFoamReader.h"
34 #include "vtkOpenFOAMTupleRemap.H"
35 
36 // OpenFOAM includes
37 #include "LagrangianFields.H"
40 
41 // VTK includes
42 #include "vtkFloatArray.h"
43 #include "vtkPointData.h"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 template<class Type>
48 void Foam::vtkPVFoam::convertlagrangianFields
49 (
50  const IOobjectList& objects,
51  vtkMultiBlockDataSet* output,
52  const label datasetNo
53 )
54 {
55  const arrayRange& range = arrayRangelagrangian_;
56 
57  forAllConstIter(IOobjectList, objects, iter)
58  {
59  // restrict to this IOField<Type>
60  if (iter()->headerClassName() != IOField<Type>::typeName)
61  {
62  continue;
63  }
64 
65  const IOField<Type> tf
66  (
67  reader_->GetDecomposedCase()
68  ? lagrangianReconstructors_[datasetNo]
69  .reconstructField<Type, IOField, IOField>(*iter())
70  : tmp<IOField<Type>>(new IOField<Type>(*iter()))
71  );
72 
73  convertlagrangianField
74  (
75  tf,
76  output,
77  range,
78  datasetNo
79  );
80  }
81 }
82 
83 
84 template<class Type, template<class> class GeoField>
85 void Foam::vtkPVFoam::convertLagrangianFields
86 (
87  const IOobjectList& objects,
88  vtkMultiBlockDataSet* output,
89  const label datasetNo
90 )
91 {
92  const arrayRange& range = arrayRangeLagrangian_;
93 
94  forAllConstIter(IOobjectList, objects, iter)
95  {
96  // restrict to this GeoField<Type>
97  if (iter()->headerClassName() != GeoField<Type>::typeName)
98  {
99  continue;
100  }
101 
103 
104  try
105  {
106  const GeoField<Type> tf
107  (
108  reader_->GetDecomposedCase()
109  ? LagrangianReconstructors_[datasetNo]
110  .reconstructField<GeoField<Type>>(*iter())
111  : tmp<GeoField<Type>>
112  (
113  new GeoField<Type>(*iter(), LagrangianMeshes_[datasetNo])
114  )
115  );
116 
117  convertLagrangianField<Type, GeoField>
118  (
119  tf,
120  output,
121  range,
122  datasetNo
123  );
124  }
125  catch (IOerror& err)
126  {
127  Warning<< err << endl;
128  continue;
129  }
130 
132  }
133 }
134 
135 
136 template<class Type>
137 void Foam::vtkPVFoam::convertlagrangianField
138 (
139  const IOField<Type>& tf,
140  vtkMultiBlockDataSet* output,
141  const arrayRange& range,
142  const label datasetNo
143 )
144 {
145  const label nComp = pTraits<Type>::nComponents;
146 
147  vtkFloatArray* pointData = vtkFloatArray::New();
148  pointData->SetNumberOfTuples(tf.size());
149  pointData->SetNumberOfComponents(nComp);
150  pointData->Allocate(nComp*tf.size());
151  pointData->SetName(tf.name().c_str());
152 
154  << "Converting lagrangian field: " << tf.name()
155  << " size=" << tf.size()
156  << ", nComp=" << nComp << endl;
157 
158  float vec[nComp];
159 
160  forAll(tf, i)
161  {
162  const Type& t = tf[i];
163 
164  for (direction d=0; d<nComp; ++d)
165  {
166  vec[d] = component(t, d);
167  }
168 
169  vtkOpenFOAMTupleRemap<Type>(vec);
170 
171  pointData->InsertTuple(i, vec);
172  }
173 
174  vtkPolyData::SafeDownCast
175  (
176  GetDataSetFromBlock(output, range, datasetNo)
177  ) ->GetPointData()
178  ->AddArray(pointData);
179 
180  pointData->Delete();
181 }
182 
183 
184 template<class Type, template<class> class GeoField>
185 void Foam::vtkPVFoam::convertLagrangianField
186 (
187  const GeoField<Type>& tf,
188  vtkMultiBlockDataSet* output,
189  const arrayRange& range,
190  const label datasetNo
191 )
192 {
193  static const label nComp = pTraits<Type>::nComponents;
194 
195  vtkFloatArray* pointData = vtkFloatArray::New();
196  pointData->SetNumberOfTuples(tf.primitiveField().size());
197  pointData->SetNumberOfComponents(nComp);
198  pointData->Allocate(nComp*tf.primitiveField().size());
199  pointData->SetName(tf.name().c_str());
200 
202  << "Converting Lagrangian field: " << tf.name()
203  << " size=" << tf.primitiveField().size()
204  << ", nComp=" << nComp << endl;
205 
206  float vec[nComp];
207 
208  forAll(tf.primitiveField(), i)
209  {
210  const Type& t = tf.primitiveField()[i];
211 
212  for (direction d=0; d<nComp; ++d)
213  {
214  vec[d] = component(t, d);
215  }
216 
217  vtkOpenFOAMTupleRemap<Type>(vec);
218 
219  pointData->InsertTuple(i, vec);
220  }
221 
222  vtkPolyData::SafeDownCast
223  (
224  GetDataSetFromBlock(output, range, datasetNo)
225  ) ->GetPointData()
226  ->AddArray(pointData);
227 
228  pointData->Delete();
229 }
230 
231 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
232 
233 #endif
234 
235 // ************************************************************************* //
scalar range
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:492
static const char *const typeName
Definition: Field.H:106
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
void throwExceptions()
Definition: error.H:115
void dontThrowExceptions()
Definition: error.H:120
const tensorField & tf
#define DebugInFunction
Report an information message using Foam::Info.
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
String typeName(const std::type_info &info)
Return the un-mangled name given the standard type info.
void component(GeometricField< typename GeometricField< Type, GeoMesh, PrimitiveField1 >::cmptType, GeoMesh, PrimitiveField1 > &gcf, const GeometricField< Type, GeoMesh, PrimitiveField2 > &gf, const direction d)
IOerror FatalIOError
tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const word &name, const dimensionSet &dimensions)
uint8_t direction
Definition: direction.H:45
messageStream Warning
objects