vtkPVFoamPointFields.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-2026 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 vtkPVFoamPointFields_H
30 #define vtkPVFoamPointFields_H
31 
32 #include "vtkPVFoam.H"
33 #include "vtkPVFoamReader.h"
34 #include "vtkOpenFOAMTupleRemap.H"
35 
36 // OpenFOAM includes
37 #include "domainDecomposition.H"
38 #include "pointFields.H"
39 #include "interpolatePointToCell.H"
41 
42 // VTK includes
43 #include "vtkFloatArray.h"
44 #include "vtkUnstructuredGrid.h"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 template<class Type>
49 void Foam::vtkPVFoam::convertPointFields
50 (
51  const IOobjectList& objects,
52  vtkMultiBlockDataSet* output
53 )
54 {
55  const polyBoundaryMesh& patches =
56  procMeshesPtr_->completeMesh().poly().boundary();
57 
58  forAllConstIter(IOobjectList, objects, iter)
59  {
60  // restrict to this GeometricField<Type, ...>
61  if (iter()->headerClassName() != PointField<Type>::typeName)
62  {
63  continue;
64  }
65 
66  // Load the field
67  tmp<PointField<Type>> tptf;
68 
70 
71  try
72  {
73  if (reader_->GetDecomposedCase())
74  {
75  if (!pointReconstructorPtr_.valid())
76  {
77  pointReconstructorPtr_.set
78  (
79  new pointFieldReconstructor
80  (
81  pointMesh::New(procMeshesPtr_->completeMesh()),
82  procMeshesPtr_->procMeshes(),
83  procMeshesPtr_->procPointAddressing()
84  )
85  );
86  }
87 
88  tptf =
89  pointReconstructorPtr_
90  ->reconstructField<Type>(*iter());
91  }
92  else
93  {
94  tptf =
95  new PointField<Type>
96  (
97  *iter(),
98  pointMesh::New(procMeshesPtr_->completeMesh())
99  );
100  }
101  }
102  catch (IOerror& err)
103  {
104  Warning<< err << endl;
105  continue;
106  }
107 
109 
110  const PointField<Type>& ptf = tptf();
111 
112  // Convert activated internalMesh regions
113  convertPointFieldBlock
114  (
115  ptf,
116  output,
117  arrayRangeVolume_,
118  regionPolyDecomp_
119  );
120 
121  // Convert activated cellZones
122  convertPointFieldBlock
123  (
124  ptf,
125  output,
126  arrayRangeCellZones_,
127  zonePolyDecomp_
128  );
129 
130  // Convert activated cellSets
131  convertPointFieldBlock
132  (
133  ptf,
134  output,
135  arrayRangeCellSets_,
136  setPolyDecomp_
137  );
138 
139  // Convert patches - if activated
140  for
141  (
142  int partId = arrayRangePatches_.start();
143  partId < arrayRangePatches_.end();
144  ++partId
145  )
146  {
147  const word patchName = getPartName(partId);
148  const label datasetNo = partDataset_[partId];
149  const label patchId = patches.findIndex(patchName);
150 
151  if (!partStatus_[partId] || datasetNo < 0 || patchId < 0)
152  {
153  continue;
154  }
155 
156  convertPatchPointField
157  (
158  ptf.name(),
159  ptf.boundaryField()[patchId].patchInternalField()(),
160  output,
161  arrayRangePatches_,
162  datasetNo
163  );
164  }
165 
166  // Convert faceZones - if activated
167  for
168  (
169  int partId = arrayRangeFaceZones_.start();
170  partId < arrayRangeFaceZones_.end();
171  ++partId
172  )
173  {
174  const word zoneName = getPartName(partId);
175  const label datasetNo = partDataset_[partId];
176  const label zoneId =
177  ptf.mesh().mesh().faceZones().findIndex(zoneName);
178 
179  if (!partStatus_[partId] || datasetNo < 0 || zoneId < 0)
180  {
181  continue;
182  }
183 
184  // Extract the field on the zone
185  Field<Type> fld
186  (
187  ptf.primitiveField(),
188  ptf.mesh().mesh().faceZones()[zoneId].patch().meshPoints()
189  );
190 
191  convertPatchPointField
192  (
193  ptf.name(),
194  fld,
195  output,
196  arrayRangeFaceZones_,
197  datasetNo
198  );
199  }
200  }
201 }
202 
203 
204 template<class Type>
205 void Foam::vtkPVFoam::convertPointFieldBlock
206 (
207  const PointField<Type>& ptf,
208  vtkMultiBlockDataSet* output,
209  const arrayRange& range,
210  const List<polyDecomp>& decompLst
211 )
212 {
213  for (int partId = range.start(); partId < range.end(); ++partId)
214  {
215  const label datasetNo = partDataset_[partId];
216 
217  if (datasetNo >= 0 && partStatus_[partId])
218  {
219  convertPointField
220  (
221  ptf,
223  output,
224  range,
225  datasetNo,
226  decompLst[datasetNo]
227  );
228  }
229  }
230 }
231 
232 
233 template<class Type>
234 void Foam::vtkPVFoam::convertPointField
235 (
236  const PointField<Type>& ptf,
237  const VolField<Type>& tf,
238  vtkMultiBlockDataSet* output,
239  const arrayRange& range,
240  const label datasetNo,
241  const polyDecomp& decomp
242 )
243 {
244  const label nComp = pTraits<Type>::nComponents;
245  const labelList& addPointCellLabels = decomp.addPointCellLabels();
246  const labelList& pointMap = decomp.pointMap();
247 
248  // use a pointMap or address directly into mesh
249  label nPoints;
250  if (pointMap.size())
251  {
252  nPoints = pointMap.size();
253  }
254  else
255  {
256  nPoints = ptf.size();
257  }
258 
259  vtkFloatArray* pointData = vtkFloatArray::New();
260  pointData->SetNumberOfTuples(nPoints + addPointCellLabels.size());
261  pointData->SetNumberOfComponents(nComp);
262  pointData->Allocate(nComp*(nPoints + addPointCellLabels.size()));
263 
264  // Note: using the name of the original volField
265  // not the name generated by the interpolation "volPointInterpolate(<name>)"
266  if (&tf != &VolField<Type>::null())
267  {
268  pointData->SetName(tf.name().c_str());
269  }
270  else
271  {
272  pointData->SetName(ptf.name().c_str());
273  }
274 
276  << "Converting Point field: " << tf.name()
277  << " size=" << nPoints << " (" << nPoints + addPointCellLabels.size()
278  << "), nComp=" << nComp << endl;
279 
280  float vec[nComp];
281 
282  if (pointMap.size())
283  {
284  forAll(pointMap, i)
285  {
286  const Type& t = ptf[pointMap[i]];
287  for (direction d=0; d<nComp; ++d)
288  {
289  vec[d] = component(t, d);
290  }
291  vtkOpenFOAMTupleRemap<Type>(vec);
292 
293  pointData->InsertTuple(i, vec);
294  }
295  }
296  else
297  {
298  forAll(ptf, i)
299  {
300  const Type& t = ptf[i];
301  for (direction d=0; d<nComp; ++d)
302  {
303  vec[d] = component(t, d);
304  }
305  vtkOpenFOAMTupleRemap<Type>(vec);
306 
307  pointData->InsertTuple(i, vec);
308  }
309  }
310 
311  // continue insertion from here
312  label i = nPoints;
313 
314  if (&tf != &VolField<Type>::null())
315  {
316  forAll(addPointCellLabels, apI)
317  {
318  const Type& t = tf[addPointCellLabels[apI]];
319  for (direction d=0; d<nComp; ++d)
320  {
321  vec[d] = component(t, d);
322  }
323  vtkOpenFOAMTupleRemap<Type>(vec);
324 
325  pointData->InsertTuple(i++, vec);
326  }
327  }
328  else
329  {
330  forAll(addPointCellLabels, apI)
331  {
332  Type t = interpolatePointToCell(ptf, addPointCellLabels[apI]);
333  for (direction d=0; d<nComp; ++d)
334  {
335  vec[d] = component(t, d);
336  }
337  vtkOpenFOAMTupleRemap<Type>(vec);
338 
339  pointData->InsertTuple(i++, vec);
340  }
341  }
342 
343  vtkUnstructuredGrid::SafeDownCast
344  (
345  GetDataSetFromBlock(output, range, datasetNo)
346  ) ->GetPointData()
347  ->AddArray(pointData);
348 
349  pointData->Delete();
350 }
351 
352 
353 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
354 
355 #endif
356 
357 // ************************************************************************* //
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 pointMesh & New(const word &name, const polyMesh &mesh)
Construct and return the named DemandDrivenMeshObject.
static const GeometricField< Type, GeoMesh, PrimitiveField > & null()
Return a null geometric field.
void throwExceptions()
Definition: error.H:115
void dontThrowExceptions()
Definition: error.H:120
Motion of the mesh specified as a list of pointMeshMovers.
const tensorField & tf
label nPoints
gmvFile<< "tracers "<< particles.size()<< nl;{ pointField positions(particles.size());label particlei=0;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter) { positions[particlei++]=iter().position(mesh);} for(i=0;i< pTraits< point >::nComponents;i++) { forAll(positions, particlei) { gmvFile<< component(positions[particlei], i)<< ' ';} gmvFile<< nl;}}forAll(lagrangianScalarNames, i){ const word &name=lagrangianScalarNames[i];IOField< scalar > fld(IOobject(name, runTime.name(), lagrangian::cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Interpolates (averages) the vertex values to the cell center.
label patchId(-1)
const fvPatchList & patches
#define DebugInFunction
Report an information message using Foam::Info.
List< label > labelList
A List of labels.
Definition: labelList.H:56
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)
Type interpolatePointToCell(const PointField< Type > &ptf, const label celli)
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