foamVtkIndPatchWriterTemplates.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) 2018-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 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
29 
30 
31 template<class Type>
33 (
34  const word& fieldName,
35  const Type& val
36 )
37 {
38  if (isState(outputState::CELL_DATA))
39  {
40  ++nCellData_;
41  vtk::fileWriter::writeUniform<Type>(fieldName, val, numberOfCells_);
42  }
43  else if (isState(outputState::POINT_DATA))
44  {
45  ++nPointData_;
46  vtk::fileWriter::writeUniform<Type>(fieldName, val, numberOfPoints_);
47  }
48  else
49  {
51  << "Bad writer state (" << stateNames[state_]
52  << ") for field " << fieldName << nl << endl
53  << exit(FatalError);
54  }
55 }
56 
57 
58 template<class Type>
60 (
61  const word& fieldName,
62  const UList<Type>& field
63 )
64 {
65  if (isState(outputState::CELL_DATA))
66  {
67  ++nCellData_;
68  }
69  else if (isState(outputState::POINT_DATA))
70  {
71  ++nPointData_;
72  }
73  else
74  {
76  << "Bad writer state (" << stateNames[state_]
77  << ") - should be (" << stateNames[outputState::CELL_DATA]
78  << ") or (" << stateNames[outputState::POINT_DATA]
79  << ") for field " << fieldName << nl << endl
80  << exit(FatalError);
81  }
82 
83  static_assert
84  (
85  (
86  std::is_same<label, typename pTraits<Type>::cmptType>::value
87  || std::is_floating_point<typename pTraits<Type>::cmptType>::value
88  ),
89  "Label and Floating-point vector space only"
90  );
91 
93 
94  label nValues = field.size();
95 
96  // Could check sizes:
97  // nValues == nLocalFaces (CELL_DATA)
98  // nValues == nLocalPoints (POINT_DATA)
99 
100  if (parallel_)
101  {
102  reduce(nValues, sumOp<label>());
103  }
104 
105  if (format_)
106  {
107  if (std::is_same<label, typename pTraits<Type>::cmptType>::value)
108  {
109  if (legacy())
110  {
111  legacy::intField<nCmpt>(format(), fieldName, nValues);
112  }
113  else
114  {
115  const uint64_t payLoad = vtk::sizeofData<label, nCmpt>(nValues);
116 
117  format().beginDataArray<label, nCmpt>(fieldName);
118  format().writeSize(payLoad);
119  }
120  }
121  else
122  {
123  if (legacy())
124  {
125  legacy::floatField<nCmpt>(format(), fieldName, nValues);
126  }
127  else
128  {
129  const uint64_t payLoad = vtk::sizeofData<float, nCmpt>(nValues);
130 
131  format().beginDataArray<float, nCmpt>(fieldName);
132  format().writeSize(payLoad);
133  }
134  }
135  }
136 
137 
138  if (parallel_)
139  {
140  vtk::writeListParallel(format_.ref(), field);
141  }
142  else
143  {
145  }
146 
147 
148  if (format_)
149  {
150  format().flush();
151  format().endDataArray();
152  }
153 }
154 
155 
156 // ************************************************************************* //
Foam::vtk::writeListParallel
void writeListParallel(vtk::formatter &fmt, const UList< uint8_t > &values)
Write a list of uint8_t values.
Definition: foamVtkOutput.C:126
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::expressions::patchExpr::POINT_DATA
Point data.
Definition: patchExprFwd.H:60
Foam::vtk::indirectPatchWriter::writeUniform
void writeUniform(const word &fieldName, const Type &val)
Write a uniform field of Cell (Face) or Point values.
Definition: foamVtkIndPatchWriterTemplates.C:33
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::sumOp
Definition: ops.H:213
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::FatalError
error FatalError
reduce
reduce(hasMovingMesh, orOp< bool >())
Foam::vtk::indirectPatchWriter::write
void write(const word &fieldName, const UList< Type > &field)
Write a list of Cell (Face) or Point values.
Definition: foamVtkIndPatchWriterTemplates.C:60
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::pTraits
Traits class for primitives.
Definition: pTraits.H:54
Foam::UList< Type >
Foam::direction
uint8_t direction
Definition: direction.H:52
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:303