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"
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  << " 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  }
147 
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 
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 // ************************************************************************* //
foamVtkOutput.H
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
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:369
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:353
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:114
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:453
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::List< label >
Foam::expressions::POINT_DATA
Point data.
Definition: exprFieldAssociation.H:46
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:36
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