foamVtkPatchWriterTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2016-2020 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "foamVtkPatchWriter.H"
29 #include "foamVtkOutput.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 template<class Type, template<class> class PatchField>
35 (
37 )
38 {
39  if (isState(outputState::POINT_DATA))
40  {
41  ++nPointData_;
42  }
43  else
44  {
46  << "Bad writer state (" << stateNames[state_]
47  << ") - should be (" << stateNames[outputState::POINT_DATA]
48  << ") for field " << field.name() << nl << endl
49  << exit(FatalError);
50  }
51 
53 
54  label nPoints = nLocalPoints_;
55 
56  if (parallel_)
57  {
59  }
60 
61 
62  if (format_)
63  {
64  if (legacy())
65  {
66  legacy::floatField<nCmpt>(format(), field.name(), nPoints);
67  }
68  else
69  {
70  const uint64_t payLoad =
71  vtk::sizeofData<float, nCmpt>(nPoints);
72 
73  format().beginDataArray<float, nCmpt>(field.name());
74  format().writeSize(payLoad);
75  }
76  }
77 
78 
79  if (parallel_ ? Pstream::master() : true)
80  {
81  for (const label patchId : patchIDs_)
82  {
83  const auto& pfld = field.boundaryField()[patchId];
84 
85  vtk::writeList(format(), pfld.patchInternalField()());
86  }
87  }
88 
89 
90  if (parallel_)
91  {
92  // Patch Ids are identical across all processes
93  const label nPatches = patchIDs_.size();
94 
95  if (Pstream::master())
96  {
97  Field<Type> recv;
98 
99  // Receive each patch field and write
100  for
101  (
102  int slave=Pstream::firstSlave();
103  slave<=Pstream::lastSlave();
104  ++slave
105  )
106  {
107  IPstream fromSlave(Pstream::commsTypes::blocking, slave);
108 
109  for (label i=0; i < nPatches; ++i)
110  {
111  fromSlave >> recv;
112 
113  vtk::writeList(format(), recv);
114  }
115  }
116  }
117  else
118  {
119  // Send each patch field to master
120  OPstream toMaster
121  (
122  Pstream::commsTypes::blocking,
123  Pstream::masterNo()
124  );
125 
126  for (const label patchId : patchIDs_)
127  {
128  const auto& pfld = field.boundaryField()[patchId];
129 
130  toMaster << pfld.patchInternalField()();
131  }
132  }
133  }
134 
135 
136  if (format_)
137  {
138  format().flush();
139  format().endDataArray();
140  }
141 }
142 
143 
144 template<class Type, template<class> class PatchField>
146 (
148 )
149 {
150  if (isState(outputState::CELL_DATA))
151  {
152  ++nCellData_;
153  }
154  else
155  {
157  << "Bad writer state (" << stateNames[state_]
158  << ") - should be (" << stateNames[outputState::CELL_DATA]
159  << ") for field " << field.name() << nl << endl
160  << exit(FatalError);
161  }
162 
164 
165  label nFaces = nLocalFaces_;
166 
167  if (parallel_)
168  {
169  reduce(nFaces, sumOp<label>());
170  }
171 
172 
173  if (format_)
174  {
175  if (legacy())
176  {
177  legacy::floatField<nCmpt>(format(), field.name(), nFaces);
178  }
179  else
180  {
181  const uint64_t payLoad =
182  vtk::sizeofData<float, nCmpt>(nFaces);
183 
184  format().beginDataArray<float, nCmpt>(field.name());
185  format().writeSize(payLoad);
186  }
187  }
188 
189 
190  if (parallel_ ? Pstream::master() : true)
191  {
192  for (const label patchId : patchIDs_)
193  {
194  const auto& pfld = field.boundaryField()[patchId];
195 
196  if (useNearCellValue_)
197  {
198  vtk::writeList(format(), pfld.patchInternalField()());
199  }
200  else
201  {
202  vtk::writeList(format(), pfld);
203  }
204  }
205  }
206 
207  if (parallel_)
208  {
209  // Patch Ids are identical across all processes
210  const label nPatches = patchIDs_.size();
211 
212  if (Pstream::master())
213  {
214  Field<Type> recv;
215 
216  // Receive each patch field and write
217  for
218  (
219  int slave=Pstream::firstSlave();
220  slave<=Pstream::lastSlave();
221  ++slave
222  )
223  {
224  IPstream fromSlave(Pstream::commsTypes::blocking, slave);
225 
226  for (label i=0; i < nPatches; ++i)
227  {
228  fromSlave >> recv;
229 
230  vtk::writeList(format(), recv);
231  }
232  }
233  }
234  else
235  {
236  // Send each patch field to master
237  OPstream toMaster
238  (
239  Pstream::commsTypes::blocking,
240  Pstream::masterNo()
241  );
242 
243  for (const label patchId : patchIDs_)
244  {
245  const auto& pfld = field.boundaryField()[patchId];
246 
247  if (useNearCellValue_)
248  {
249  toMaster << pfld.patchInternalField()();
250  }
251  else
252  {
253  toMaster << static_cast<const Field<Type>&>(pfld);
254  }
255  }
256  }
257  }
258 
259 
260  if (format_)
261  {
262  format().flush();
263  format().endDataArray();
264  }
265 }
266 
267 
268 template<class Type>
270 (
273 )
274 {
275  if (isState(outputState::POINT_DATA))
276  {
277  ++nPointData_;
278  }
279  else
280  {
282  << "Bad writer state (" << stateNames[state_]
283  << ") - should be (" << stateNames[outputState::POINT_DATA]
284  << ") for field " << field.name() << nl << endl
285  << exit(FatalError);
286  }
287 
289 
290  label nPoints = nLocalPoints_;
291 
292  if (parallel_)
293  {
295  }
296 
297 
298  if (format_)
299  {
300  if (legacy())
301  {
302  legacy::floatField<nCmpt>(format(), field.name(), nPoints);
303  }
304  else
305  {
306  const uint64_t payLoad =
307  vtk::sizeofData<float, nCmpt>(nPoints);
308 
309  format().beginDataArray<float, nCmpt>(field.name());
310  format().writeSize(payLoad);
311  }
312  }
313 
314 
315  if (parallel_ ? Pstream::master() : true)
316  {
317  for (const label patchId : patchIDs_)
318  {
319  const auto& pfld = field.boundaryField()[patchId];
320 
321  if (useNearCellValue_)
322  {
323  auto tfield =
325  (
326  pfld.patchInternalField()()
327  );
328 
329  vtk::writeList(format(), tfield());
330  }
331  else
332  {
333  auto tfield = pInter.faceToPointInterpolate(pfld);
334 
335  vtk::writeList(format(), tfield());
336  }
337  }
338  }
339 
340 
341  if (parallel_)
342  {
343  // Patch Ids are identical across all processes
344  const label nPatches = patchIDs_.size();
345 
346  if (Pstream::master())
347  {
348  Field<Type> recv;
349 
350  // Receive each patch field and write
351  for
352  (
353  int slave=Pstream::firstSlave();
354  slave<=Pstream::lastSlave();
355  ++slave
356  )
357  {
358  IPstream fromSlave(Pstream::commsTypes::blocking, slave);
359 
360  for (label i=0; i < nPatches; ++i)
361  {
362  fromSlave >> recv;
363 
364  vtk::writeList(format(), recv);
365  }
366  }
367  }
368  else
369  {
370  // Send each patch field to master
371  OPstream toMaster
372  (
373  Pstream::commsTypes::blocking,
374  Pstream::masterNo()
375  );
376 
377  for (const label patchId : patchIDs_)
378  {
379  const auto& pfld = field.boundaryField()[patchId];
380 
381  if (useNearCellValue_)
382  {
383  auto tfield =
385  (
386  pfld.patchInternalField()()
387  );
388 
389  toMaster << tfield();
390  }
391  else
392  {
393  auto tfield = pInter.faceToPointInterpolate(pfld);
394 
395  toMaster << tfield();
396  }
397  }
398  }
399  }
400 
401 
402  if (format_)
403  {
404  format().flush();
405  format().endDataArray();
406  }
407 }
408 
409 
410 // ************************************************************************* //
foamVtkOutput.H
nPatches
label nPatches
Definition: readKivaGrid.H:396
Foam::OPstream
Output inter-processor communications stream.
Definition: OPstream.H:52
Foam::expressions::patchExpr::POINT_DATA
Point data.
Definition: patchExprFwd.H:60
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::sumOp
Definition: ops.H:213
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
format
word format(conversionProperties.get< word >("format"))
Foam::Field
Generic templated field type.
Definition: Field.H:63
field
rDeltaTY field()
Foam::vtk::writeList
void writeList(vtk::formatter &fmt, const UList< uint8_t > &values)
Write a list of uint8_t values.
Definition: foamVtkOutput.C:112
Foam::FatalError
error FatalError
reduce
reduce(hasMovingMesh, orOp< bool >())
Foam::PrimitivePatchInterpolation::faceToPointInterpolate
tmp< Field< Type > > faceToPointInterpolate(const Field< Type > &ff) const
Interpolate from faces to points.
Definition: PrimitivePatchInterpolation.C:177
foamVtkPatchWriter.H
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:372
Foam::PrimitivePatchInterpolation
Interpolation class within a primitive patch. Allows interpolation from points to faces and vice vers...
Definition: PrimitivePatchInterpolation.H:53
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::pTraits
Traits class for primitives.
Definition: pTraits.H:54
Foam::vtk::patchWriter::write
void write(const GeometricField< Type, PatchField, pointMesh > &field)
Write point field.
Definition: foamVtkPatchWriterTemplates.C:35
Foam::direction
uint8_t direction
Definition: direction.H:47
Foam::IPstream
Input inter-processor communications stream.
Definition: IPstream.H:52
patchId
label patchId(-1)
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:53