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-------------------------------------------------------------------------------
10License
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
29#include "foamVtkOutput.H"
32
33// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34
35template<class Type, template<class> class PatchField>
37(
39)
40{
42 {
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
84template<class Type>
86(
88)
89{
90 writeCellData(field.name(), field.field());
91}
92
93
94template<class Type, template<class> class PatchField>
96(
98)
99{
100 writeCellData(field.name(), field.primitiveField());
101}
102
103
104template<class Type>
106(
109)
110{
111 if (isState(outputState::POINT_DATA))
112 {
113 ++nPointData_;
114 }
115 else
116 {
117 reportBadState(FatalErrorInFunction, outputState::POINT_DATA)
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 }
147
148 this->endDataArray();
149}
150
151
152template<class Type>
154(
157)
158{
159 if (isState(outputState::POINT_DATA))
160 {
161 ++nPointData_;
162 }
163 else
164 {
165 reportBadState(FatalErrorInFunction, outputState::POINT_DATA)
166 << " for field " << vfield.name() << nl << endl
167 << exit(FatalError);
168 }
169
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// ************************************************************************* //
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Generic GeometricField class.
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:65
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
virtual bool write()
Write the output fields.
A class for managing temporary objects.
Definition: tmp.H:65
Interpolate from cell centres to points (vertices) using inverse distance weighting.
bool isState(outputState test) const noexcept
True if output state corresponds to the test state.
autoPtr< vtk::formatter > format_
The VTK formatter in use (only valid on master process)
bool parallel_
Parallel writing (via master)
void endDataArray()
Flush formatter and end of DataArray output (non-legacy)
label nPointData_
The number of PointData written for the Piece thus far.
@ POINT_DATA
Inside PointData.
Ostream & reportBadState(Ostream &, outputState expected) const
Generate message reporting bad writer state.
vtk::formatter & format()
The VTK formatter in use. FatalError for off-processor.
label numberOfPoints_
The number of field points for the current Piece.
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:335
rDeltaTY field()
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
autoPtr< volPointInterpolation > pInterp
Interpolates (averages) the vertex values to the cell center.
label cellId
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
void writeListsParallel(vtk::formatter &fmt, const UList< Type > &values1, const UList< Type > &values2)
Write a list of values and another list of values.
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.
void writeList(vtk::formatter &fmt, const UList< uint8_t > &values)
Write a list of uint8_t values.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
Type interpolatePointToCell(const GeometricField< Type, pointPatchField, pointMesh > &ptf, const label celli)
error FatalError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
word format(conversionProperties.get< word >("format"))