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-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 "foamVtkInternalWriter.H"
29 #include "foamVtkOutput.H"
30 #include "volPointInterpolation.H"
31 #include "interpolatePointToCell.H"
32 
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
35 template<class Type, template<class> class PatchField>
37 (
39 )
40 {
41  if (isState(outputState::POINT_DATA))
42  {
43  ++nPointData_;
44  }
45  else
46  {
48  << "Bad writer state (" << stateNames[state_]
49  << ") - should be (" << stateNames[outputState::POINT_DATA]
50  << ") for field " << field.name() << nl << endl
51  << exit(FatalError);
52  }
53 
55 
56  const labelList& addPointCellLabels = vtuCells_.addPointCellLabels();
57 
58  if (format_)
59  {
60  if (legacy())
61  {
62  legacy::floatField<nCmpt>(format(), field.name(), numberOfPoints_);
63  }
64  else
65  {
66  const uint64_t payLoad =
67  vtk::sizeofData<float, nCmpt>(numberOfPoints_);
68 
69  format().beginDataArray<float, nCmpt>(field.name());
70  format().writeSize(payLoad);
71  }
72  }
73 
74  if (parallel_)
75  {
76  List<Type> addedValues(addPointCellLabels.size());
77  label outi = 0;
78 
79  for (const label cellId : addPointCellLabels)
80  {
81  addedValues[outi++] = interpolatePointToCell(field, cellId);
82  }
83 
84  vtk::writeListsParallel(format_.ref(), field, addedValues);
85  }
86  else
87  {
89 
90  for (const label cellId : addPointCellLabels)
91  {
92  const Type val = interpolatePointToCell(field, cellId);
93  vtk::write(format(), val);
94  }
95  }
96 
97  if (format_)
98  {
99  format().flush();
100  format().endDataArray();
101  }
102 }
103 
104 
105 template<class Type>
107 (
109 )
110 {
111  writeCellData(field.name(), field.field());
112 }
113 
114 
115 template<class Type, template<class> class PatchField>
117 (
119 )
120 {
121  writeCellData(field.name(), field.primitiveField());
122 }
123 
124 
125 template<class Type>
127 (
128  const DimensionedField<Type, volMesh>& vfield,
130 )
131 {
132  if (isState(outputState::POINT_DATA))
133  {
134  ++nPointData_;
135  }
136  else
137  {
139  << "Bad writer state (" << stateNames[state_]
140  << ") - should be (" << stateNames[outputState::POINT_DATA]
141  << ") for field " << vfield.name() << nl << endl
142  << exit(FatalError);
143  }
144 
146 
147  typedef DimensionedField<Type, pointMesh> PointFieldType;
148 
149  // Use tmp intermediate. Compiler sometimes weird otherwise.
150  tmp<PointFieldType> tfield = pInterp.interpolate(vfield);
151  const auto& pfield = tfield();
152 
153  const labelList& addPointCellLabels = vtuCells_.addPointCellLabels();
154 
155  if (format_)
156  {
157  if (legacy())
158  {
159  legacy::floatField<nCmpt>(format(), vfield.name(), numberOfPoints_);
160  }
161  else
162  {
163  const uint64_t payLoad =
164  vtk::sizeofData<float, nCmpt>(numberOfPoints_);
165 
166  format().beginDataArray<float, nCmpt>(vfield.name());
167  format().writeSize(payLoad);
168  }
169  }
170 
171  if (parallel_)
172  {
174  (
175  format_.ref(),
176  pfield,
177  vfield,
178  addPointCellLabels
179  );
180  }
181  else
182  {
183  vtk::writeLists(format(), pfield, vfield, addPointCellLabels);
184  }
185 
186  if (format_)
187  {
188  format().flush();
189  format().endDataArray();
190  }
191 }
192 
193 
194 template<class Type>
196 (
199 )
200 {
201  if (isState(outputState::POINT_DATA))
202  {
203  ++nPointData_;
204  }
205  else
206  {
208  << "Bad writer state (" << stateNames[state_]
209  << ") - should be (" << stateNames[outputState::POINT_DATA]
210  << ") for field " << vfield.name() << nl << endl
211  << exit(FatalError);
212  }
213 
215 
217 
218  // Use tmp intermediate. Compiler sometimes weird otherwise.
219  tmp<PointFieldType> tfield = pInterp.interpolate(vfield);
220  const auto& pfield = tfield();
221 
222  const labelList& addPointCellLabels = vtuCells_.addPointCellLabels();
223 
224  if (format_)
225  {
226  if (legacy())
227  {
228  legacy::floatField<nCmpt>(format(), vfield.name(), numberOfPoints_);
229  }
230  else
231  {
232  const uint64_t payLoad =
233  vtk::sizeofData<float, nCmpt>(numberOfPoints_);
234 
235  format().beginDataArray<float, nCmpt>(vfield.name());
236  format().writeSize(payLoad);
237  }
238  }
239 
240  if (parallel_)
241  {
243  (
244  format_.ref(),
245  pfield,
246  vfield,
247  addPointCellLabels
248  );
249  }
250  else
251  {
252  vtk::writeLists(format(), pfield, vfield, addPointCellLabels);
253  }
254 
255  if (format_)
256  {
257  format().flush();
258  format().endDataArray();
259  }
260 }
261 
262 
263 // ************************************************************************* //
foamVtkOutput.H
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
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:350
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:240
format
word format(conversionProperties.get< word >("format"))
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:37
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:381
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::List< label >
Foam::pTraits
Traits class for primitives.
Definition: pTraits.H:54
Foam::direction
uint8_t direction
Definition: direction.H:52
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
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