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 (const int slave : Pstream::subProcs())
101  {
102  IPstream fromSlave(Pstream::commsTypes::blocking, slave);
103 
104  for (label i=0; i < nPatches; ++i)
105  {
106  fromSlave >> recv;
107 
108  vtk::writeList(format(), recv);
109  }
110  }
111  }
112  else
113  {
114  // Send each patch field to master
115  OPstream toMaster
116  (
117  Pstream::commsTypes::blocking,
118  Pstream::masterNo()
119  );
120 
121  for (const label patchId : patchIDs_)
122  {
123  const auto& pfld = field.boundaryField()[patchId];
124 
125  toMaster << pfld.patchInternalField()();
126  }
127  }
128  }
129 
130 
131  if (format_)
132  {
133  format().flush();
134  format().endDataArray();
135  }
136 }
137 
138 
139 template<class Type, template<class> class PatchField>
141 (
143 )
144 {
145  if (isState(outputState::CELL_DATA))
146  {
147  ++nCellData_;
148  }
149  else
150  {
152  << "Bad writer state (" << stateNames[state_]
153  << ") - should be (" << stateNames[outputState::CELL_DATA]
154  << ") for field " << field.name() << nl << endl
155  << exit(FatalError);
156  }
157 
159 
160  label nFaces = nLocalFaces_;
161 
162  if (parallel_)
163  {
164  reduce(nFaces, sumOp<label>());
165  }
166 
167 
168  if (format_)
169  {
170  if (legacy())
171  {
172  legacy::floatField<nCmpt>(format(), field.name(), nFaces);
173  }
174  else
175  {
176  const uint64_t payLoad =
177  vtk::sizeofData<float, nCmpt>(nFaces);
178 
179  format().beginDataArray<float, nCmpt>(field.name());
180  format().writeSize(payLoad);
181  }
182  }
183 
184 
185  if (parallel_ ? Pstream::master() : true)
186  {
187  for (const label patchId : patchIDs_)
188  {
189  const auto& pfld = field.boundaryField()[patchId];
190 
191  if (useNearCellValue_)
192  {
193  vtk::writeList(format(), pfld.patchInternalField()());
194  }
195  else
196  {
197  vtk::writeList(format(), pfld);
198  }
199  }
200  }
201 
202  if (parallel_)
203  {
204  // Patch Ids are identical across all processes
205  const label nPatches = patchIDs_.size();
206 
207  if (Pstream::master())
208  {
209  Field<Type> recv;
210 
211  // Receive each patch field and write
212  for (const int slave : Pstream::subProcs())
213  {
214  IPstream fromSlave(Pstream::commsTypes::blocking, slave);
215 
216  for (label i=0; i < nPatches; ++i)
217  {
218  fromSlave >> recv;
219 
220  vtk::writeList(format(), recv);
221  }
222  }
223  }
224  else
225  {
226  // Send each patch field to master
227  OPstream toMaster
228  (
229  Pstream::commsTypes::blocking,
230  Pstream::masterNo()
231  );
232 
233  for (const label patchId : patchIDs_)
234  {
235  const auto& pfld = field.boundaryField()[patchId];
236 
237  if (useNearCellValue_)
238  {
239  toMaster << pfld.patchInternalField()();
240  }
241  else
242  {
243  toMaster << static_cast<const Field<Type>&>(pfld);
244  }
245  }
246  }
247  }
248 
249 
250  if (format_)
251  {
252  format().flush();
253  format().endDataArray();
254  }
255 }
256 
257 
258 template<class Type>
260 (
263 )
264 {
265  if (isState(outputState::POINT_DATA))
266  {
267  ++nPointData_;
268  }
269  else
270  {
272  << "Bad writer state (" << stateNames[state_]
273  << ") - should be (" << stateNames[outputState::POINT_DATA]
274  << ") for field " << field.name() << nl << endl
275  << exit(FatalError);
276  }
277 
279 
280  label nPoints = nLocalPoints_;
281 
282  if (parallel_)
283  {
285  }
286 
287 
288  if (format_)
289  {
290  if (legacy())
291  {
292  legacy::floatField<nCmpt>(format(), field.name(), nPoints);
293  }
294  else
295  {
296  const uint64_t payLoad =
297  vtk::sizeofData<float, nCmpt>(nPoints);
298 
299  format().beginDataArray<float, nCmpt>(field.name());
300  format().writeSize(payLoad);
301  }
302  }
303 
304 
305  if (parallel_ ? Pstream::master() : true)
306  {
307  for (const label patchId : patchIDs_)
308  {
309  const auto& pfld = field.boundaryField()[patchId];
310 
311  if (useNearCellValue_)
312  {
313  auto tfield =
315  (
316  pfld.patchInternalField()()
317  );
318 
319  vtk::writeList(format(), tfield());
320  }
321  else
322  {
323  auto tfield = pInter.faceToPointInterpolate(pfld);
324 
325  vtk::writeList(format(), tfield());
326  }
327  }
328  }
329 
330 
331  if (parallel_)
332  {
333  // Patch Ids are identical across all processes
334  const label nPatches = patchIDs_.size();
335 
336  if (Pstream::master())
337  {
338  Field<Type> recv;
339 
340  // Receive each patch field and write
341  for (const int slave : Pstream::subProcs())
342  {
343  IPstream fromSlave(Pstream::commsTypes::blocking, slave);
344 
345  for (label i=0; i < nPatches; ++i)
346  {
347  fromSlave >> recv;
348 
349  vtk::writeList(format(), recv);
350  }
351  }
352  }
353  else
354  {
355  // Send each patch field to master
356  OPstream toMaster
357  (
358  Pstream::commsTypes::blocking,
359  Pstream::masterNo()
360  );
361 
362  for (const label patchId : patchIDs_)
363  {
364  const auto& pfld = field.boundaryField()[patchId];
365 
366  if (useNearCellValue_)
367  {
368  auto tfield =
370  (
371  pfld.patchInternalField()()
372  );
373 
374  toMaster << tfield();
375  }
376  else
377  {
378  auto tfield = pInter.faceToPointInterpolate(pfld);
379 
380  toMaster << tfield();
381  }
382  }
383  }
384  }
385 
386 
387  if (format_)
388  {
389  format().flush();
390  format().endDataArray();
391  }
392 }
393 
394 
395 // ************************************************************************* //
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:381
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:52
Foam::IPstream
Input inter-processor communications stream.
Definition: IPstream.H:52
patchId
label patchId(-1)
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:53