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-2021 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"
31 #include "interpolatePointToCell.H"
32 
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
35 template<class Type, template<class> class PatchField>
37 (
39 )
40 {
42  {
43  ++nPointData_;
44  }
45  else
46  {
48  << " for field " << field.name() << nl << endl
49  << exit(FatalError);
50  }
51 
52  const labelList& addPointCellLabels = vtuCells_.addPointCellLabels();
53 
54 
55  this->beginDataArray<Type>(field.name(), numberOfPoints_);
56 
57  if (parallel_)
58  {
59  List<Type> addedValues(addPointCellLabels.size());
60  label outi = 0;
61 
62  for (const label cellId : addPointCellLabels)
63  {
64  addedValues[outi++] = interpolatePointToCell(field, cellId);
65  }
66 
67  vtk::writeListsParallel(format_.ref(), field, addedValues);
68  }
69  else
70  {
72 
73  for (const label cellId : addPointCellLabels)
74  {
75  const Type val = interpolatePointToCell(field, cellId);
76  vtk::write(format(), val);
77  }
78  }
79 
80  this->endDataArray();
81 }
82 
83 
84 template<class Type>
86 (
88 )
89 {
90  writeCellData(field.name(), field.field());
91 }
92 
93 
94 template<class Type, template<class> class PatchField>
96 (
98 )
99 {
100  writeCellData(field.name(), field.primitiveField());
101 }
102 
103 
104 template<class Type>
106 (
107  const DimensionedField<Type, volMesh>& vfield,
109 )
110 {
111  if (isState(outputState::POINT_DATA))
112  {
113  ++nPointData_;
114  }
115  else
116  {
118  << " for field " << vfield.name() << nl << endl
119  << exit(FatalError);
120  }
121 
122  typedef DimensionedField<Type, pointMesh> PointFieldType;
123 
124  // Use tmp intermediate. Compiler sometimes weird otherwise.
125  tmp<PointFieldType> tfield = pInterp.interpolate(vfield);
126  const auto& pfield = tfield();
127 
128  const labelList& addPointCellLabels = vtuCells_.addPointCellLabels();
129 
130 
131  this->beginDataArray<Type>(vfield.name(), numberOfPoints_);
132 
133  if (parallel_)
134  {
136  (
137  format_.ref(),
138  pfield,
139  vfield,
140  addPointCellLabels
141  );
142  }
143  else
144  {
145  vtk::writeLists(format(), pfield, vfield, addPointCellLabels);
146  }
148  this->endDataArray();
149 }
150 
151 
152 template<class Type>
154 (
157 )
158 {
159  if (isState(outputState::POINT_DATA))
160  {
161  ++nPointData_;
162  }
163  else
164  {
166  << " for field " << vfield.name() << nl << endl
167  << exit(FatalError);
168  }
169 
170  typedef GeometricField<Type, pointPatchField, pointMesh> PointFieldType;
171 
172  // Use tmp intermediate. Compiler sometimes weird otherwise.
173  tmp<PointFieldType> tfield = pInterp.interpolate(vfield);
174  const auto& pfield = tfield();
175 
176  const labelList& addPointCellLabels = vtuCells_.addPointCellLabels();
177 
178 
179  this->beginDataArray<Type>(vfield.name(), numberOfPoints_);
180 
181  if (parallel_)
182  {
184  (
185  format_.ref(),
186  pfield,
187  vfield,
188  addPointCellLabels
189  );
190  }
191  else
192  {
193  vtk::writeLists(format(), pfield, vfield, addPointCellLabels);
194  }
195 
196  this->endDataArray();
197 }
198 
199 
200 // ************************************************************************* //
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
autoPtr< vtk::formatter > format_
The VTK formatter in use (only valid on master process)
rDeltaTY field()
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.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
vtk::formatter & format()
The VTK formatter in use. FatalError for off-processor.
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:195
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
void endDataArray()
Flush formatter and end of DataArray output (non-legacy)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
void writeListsParallel(vtk::formatter &fmt, const UList< Type > &values1, const UList< Type > &values2)
Write a list of values and another list of values.
Generic GeometricField class.
Definition: areaFieldsFwd.H:50
label nPointData_
The number of PointData written for the Piece thus far.
bool isState(outputState test) const noexcept
True if output state corresponds to the test state.
bool parallel_
Parallel writing (via master)
void write(const GeometricField< Type, PatchField, pointMesh > &field)
Write point field.
const vtuCells & vtuCells_
The volume cells (internalMesh)
void addPointCellLabels(const labelUList &cellIds)
Define which additional cell-centres are to be used (ADVANCED!)
Definition: foamVtuCells.C:328
label numberOfPoints_
The number of field points for the current Piece.
Ostream & reportBadState(Ostream &, outputState expected) const
Generate message reporting bad writer state.
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Interpolate from cell centres to points (vertices) using inverse distance weighting.
void writeList(vtk::formatter &fmt, const UList< uint8_t > &values)
Write a list of uint8_t values.
word format(conversionProperties.get< word >("format"))
Type interpolatePointToCell(const GeometricField< Type, pointPatchField, pointMesh > &ptf, const label celli)
label cellId
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: areaFieldsFwd.H:42
List< label > labelList
A List of labels.
Definition: List.H:62
Interpolates (averages) the vertex values to the cell center.
autoPtr< volPointInterpolation > pInterp