foamVtkInternalWriterTemplates.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) 2017-2019 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 "foamVtkInternalWriter.H"
29 #include "foamVtkOutput.H"
30 #include "volPointInterpolation.H"
31 #include "interpolatePointToCell.H"
32 
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
35 template<class Type>
37 (
38  const word& fieldName,
39  const Type& val
40 )
41 {
42  if (isState(outputState::CELL_DATA))
43  {
44  ++nCellData_;
45  vtk::fileWriter::writeUniform<Type>(fieldName, val, numberOfCells_);
46  }
47  else if (isState(outputState::POINT_DATA))
48  {
49  ++nPointData_;
50  vtk::fileWriter::writeUniform<Type>(fieldName, val, numberOfPoints_);
51  }
52  else
53  {
55  << "Ignore bad writer state (" << stateNames[state_]
56  << ") for field " << fieldName << nl << endl
57  << exit(FatalError);
58  }
59 }
60 
61 
62 template<class Type, template<class> class PatchField>
64 (
66 )
67 {
68  if (isState(outputState::POINT_DATA))
69  {
70  ++nPointData_;
71  }
72  else
73  {
75  << "Bad writer state (" << stateNames[state_]
76  << ") - should be (" << stateNames[outputState::POINT_DATA]
77  << ") for field " << field.name() << nl << endl
78  << exit(FatalError);
79  }
80 
82 
83  const labelList& addPointCellLabels = vtuCells_.addPointCellLabels();
84 
85  if (format_)
86  {
87  if (legacy())
88  {
89  legacy::floatField<nCmpt>(format(), field.name(), numberOfPoints_);
90  }
91  else
92  {
93  const uint64_t payLoad =
94  vtk::sizeofData<float, nCmpt>(numberOfPoints_);
95 
96  format().beginDataArray<float, nCmpt>(field.name());
97  format().writeSize(payLoad);
98  }
99  }
100 
101  if (parallel_)
102  {
103  List<Type> addedValues(addPointCellLabels.size());
104  label outi = 0;
105 
106  for (const label cellId : addPointCellLabels)
107  {
108  addedValues[outi++] = interpolatePointToCell(field, cellId);
109  }
110 
111  vtk::writeListsParallel(format_.ref(), field, addedValues);
112  }
113  else
114  {
116 
117  for (const label cellId : addPointCellLabels)
118  {
119  const Type val = interpolatePointToCell(field, cellId);
120  vtk::write(format(), val);
121  }
122  }
123 
124  if (format_)
125  {
126  format().flush();
127  format().endDataArray();
128  }
129 }
130 
131 
132 template<class Type>
134 (
136 )
137 {
138  if (isState(outputState::CELL_DATA))
139  {
140  ++nCellData_;
141  }
142  else
143  {
145  << "Bad writer state (" << stateNames[state_]
146  << ") - should be (" << stateNames[outputState::CELL_DATA]
147  << ") for field " << field.name() << nl << endl
148  << exit(FatalError);
149  }
150 
152 
153  const labelList& cellMap = vtuCells_.cellMap();
154 
155  if (format_)
156  {
157  if (legacy())
158  {
159  legacy::floatField<nCmpt>(format(), field.name(), numberOfCells_);
160  }
161  else
162  {
163  const uint64_t payLoad =
164  vtk::sizeofData<float, nCmpt>(numberOfCells_);
165 
166  format().beginDataArray<float, nCmpt>(field.name());
167  format().writeSize(payLoad);
168  }
169  }
170 
171  if (parallel_)
172  {
173  vtk::writeListParallel(format_.ref(), field, cellMap);
174  }
175  else
176  {
177  vtk::writeList(format(), field, cellMap);
178  }
179 
180  if (format_)
181  {
182  format().flush();
183  format().endDataArray();
184  }
185 }
186 
187 
188 template<class Type, template<class> class PatchField>
190 (
192 )
193 {
194  write(field.internalField());
195 }
196 
197 
198 template<class Type>
200 (
201  const DimensionedField<Type, volMesh>& vfield,
203 )
204 {
205  if (isState(outputState::POINT_DATA))
206  {
207  ++nPointData_;
208  }
209  else
210  {
212  << "Bad writer state (" << stateNames[state_]
213  << ") - should be (" << stateNames[outputState::POINT_DATA]
214  << ") for field " << vfield.name() << nl << endl
215  << exit(FatalError);
216  }
217 
219 
220  typedef DimensionedField<Type, pointMesh> PointFieldType;
221 
222  // Use tmp intermediate. Compiler sometimes weird otherwise.
223  tmp<PointFieldType> tfield = pInterp.interpolate(vfield);
224  const PointFieldType& pfield = tfield();
225 
226  const labelList& addPointCellLabels = vtuCells_.addPointCellLabels();
227 
228  if (format_)
229  {
230  if (legacy())
231  {
232  legacy::floatField<nCmpt>(format(), vfield.name(), numberOfPoints_);
233  }
234  else
235  {
236  const uint64_t payLoad =
237  vtk::sizeofData<float, nCmpt>(numberOfPoints_);
238 
239  format().beginDataArray<float, nCmpt>(vfield.name());
240  format().writeSize(payLoad);
241  }
242  }
243 
244  if (parallel_)
245  {
247  (
248  format_.ref(),
249  pfield,
250  vfield,
251  addPointCellLabels
252  );
253  }
254  else
255  {
256  vtk::writeLists(format(), pfield, vfield, addPointCellLabels);
257  }
258 
259  if (format_)
260  {
261  format().flush();
262  format().endDataArray();
263  }
264 }
265 
266 
267 template<class Type>
269 (
272 )
273 {
274  if (isState(outputState::POINT_DATA))
275  {
276  ++nPointData_;
277  }
278  else
279  {
281  << "Bad writer state (" << stateNames[state_]
282  << ") - should be (" << stateNames[outputState::POINT_DATA]
283  << ") for field " << vfield.name() << nl << endl
284  << exit(FatalError);
285  }
286 
288 
290 
291  // Use tmp intermediate. Compiler sometimes weird otherwise.
292  tmp<PointFieldType> tfield = pInterp.interpolate(vfield);
293  const PointFieldType& pfield = tfield();
294 
295  const labelList& addPointCellLabels = vtuCells_.addPointCellLabels();
296 
297  if (format_)
298  {
299  if (legacy())
300  {
301  legacy::floatField<nCmpt>(format(), vfield.name(), numberOfPoints_);
302  }
303  else
304  {
305  const uint64_t payLoad =
306  vtk::sizeofData<float, nCmpt>(numberOfPoints_);
307 
308  format().beginDataArray<float, nCmpt>(vfield.name());
309  format().writeSize(payLoad);
310  }
311  }
312 
313  if (parallel_)
314  {
316  (
317  format_.ref(),
318  pfield,
319  vfield,
320  addPointCellLabels
321  );
322  }
323  else
324  {
325  vtk::writeLists(format(), pfield, vfield, addPointCellLabels);
326  }
327 
328  if (format_)
329  {
330  format().flush();
331  format().endDataArray();
332  }
333 }
334 
335 
336 // ************************************************************************* //
Foam::vtk::writeListParallel
void writeListParallel(vtk::formatter &fmt, const UList< uint8_t > &values)
Write a list of uint8_t values.
Definition: foamVtkOutput.C:126
foamVtkOutput.H
Foam::val
label ListType::const_reference val
Definition: ListOps.H:407
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::expressions::patchExpr::POINT_DATA
Point data.
Definition: patchExprFwd.H:60
Foam::interpolatePointToCell
Type interpolatePointToCell(const GeometricField< Type, pointPatchField, pointMesh > &ptf, const label celli)
Definition: interpolatePointToCell.C:34
interpolatePointToCell.H
Interpolates (averages) the vertex values to the cell center.
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::vtk::writeListsParallel
void writeListsParallel(vtk::formatter &fmt, const UList< Type > &values1, const UList< Type > &values2)
Write a list of values and another list of values.
Definition: foamVtkOutputTemplates.C:255
format
word format(conversionProperties.get< word >("format"))
Foam::label
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:62
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::vtk::writeLists
void writeLists(vtk::formatter &fmt, const UList< Type > &values1, const UList< Type > &values2, const labelUList &addressing)
Write a list of values and a list of values via indirect addressing.
Definition: foamVtkOutputTemplates.C:113
Foam::vtk::internalWriter::write
void write(const GeometricField< Type, PatchField, pointMesh > &field)
Write point field.
Definition: foamVtkInternalWriterTemplates.C:64
Foam::FatalError
error FatalError
cellId
label cellId
Definition: interrogateWallPatches.H:67
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
volPointInterpolation.H
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
Foam::nl
constexpr char nl
Definition: Ostream.H:372
Foam::List< label >
Foam::pTraits
Traits class for primitives.
Definition: pTraits.H:52
Foam::direction
uint8_t direction
Definition: direction.H:47
Foam::vtk::internalWriter::writeUniform
void writeUniform(const word &fieldName, const Type &val)
Write a uniform field of Cell or Point values.
Definition: foamVtkInternalWriterTemplates.C:37
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Definition: foamVtkOutputTemplates.C:35
foamVtkInternalWriter.H
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:53
Foam::volPointInterpolation
Interpolate from cell centres to points (vertices) using inverse distance weighting.
Definition: volPointInterpolation.H:59
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:294
pInterp
autoPtr< volPointInterpolation > pInterp
Definition: convertVolumeFields.H:81
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54