foamVtkFileWriterTemplates.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) 2019-2025 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 <type_traits>
29 #include "foamVtkOutput.H"
30 
31 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
32 
33 template<class Type>
35 (
36  const word& fieldName,
37  const label nValues
38 )
39 {
40  typedef typename pTraits<Type>::cmptType cmptType;
41 
42  static_assert
43  (
44  (
45  std::is_same_v<label, cmptType>
46  || std::is_floating_point_v<cmptType>
47  ),
48  "Label and Floating-point vector space only"
49  );
50 
52 
53  if (format_)
54  {
55  if constexpr (std::is_same_v<label, cmptType>)
56  {
57  if (legacy())
58  {
59  legacy::intField<nCmpt>(format(), fieldName, nValues);
60  }
61  else
62  {
63  const uint64_t payLoad =
64  vtk::sizeofData<label, nCmpt>(nValues);
65 
66  format().beginDataArray<label, nCmpt>(fieldName);
67  format().writeSize(payLoad);
68  }
69  }
70  else
71  {
72  if (legacy())
73  {
74  legacy::floatField<nCmpt>(format(), fieldName, nValues);
75  }
76  else
77  {
78  const uint64_t payLoad =
79  vtk::sizeofData<float, nCmpt>(nValues);
80 
81  format().beginDataArray<float, nCmpt>(fieldName);
82  format().writeSize(payLoad);
83  }
84  }
85  }
86 }
87 
88 
89 template<class Type>
91 (
92  const word& fieldName,
93  const Type& val,
94  const label nLocalValues
95 )
96 {
97  label nTotal = nLocalValues;
98 
99  if (parallel_)
100  {
101  reduce(nTotal, sumOp<label>());
102  }
103 
104  this->beginDataArray<Type>(fieldName, nTotal);
105 
106  if (parallel_)
107  {
108  vtk::writeValueParallel(format_.ref(), val, nLocalValues);
109  }
110  else
111  {
112  vtk::write(format(), val, nLocalValues);
113  }
115  this->endDataArray();
116 }
117 
118 
119 template<class Type>
121 (
122  const word& fieldName,
123  const UList<Type>& field
124 )
125 {
126  label nValues = field.size();
127 
128  if (parallel_)
129  {
130  reduce(nValues, sumOp<label>());
131  }
132 
133  this->beginDataArray<Type>(fieldName, nValues);
134 
135  if (parallel_)
136  {
137  vtk::writeListParallel(format_.ref(), field);
138  }
139  else
140  {
142  }
143 
144  this->endDataArray();
145 }
146 
147 
148 // ************************************************************************* //
autoPtr< vtk::formatter > format_
The VTK formatter in use (only valid on master process)
rDeltaTY field()
uint8_t direction
Definition: direction.H:46
vtk::formatter & format()
The VTK formatter in use. FatalError for off-processor.
void writeBasicField(const word &fieldName, const UList< Type > &field)
Write basic (primitive) field content.
A traits class, which is primarily used for primitives and vector-space.
Definition: pTraits.H:61
formatter & beginDataArray(const word &dataName, uint64_t payLoad=npos, bool leaveOpen=false)
Begin "DataArray" XML section.
virtual bool writeSize(const uint64_t numbytes)=0
Write leading size for binary output.
bool legacy() const noexcept
Commonly used query.
void reduce(T &value, [[maybe_unused]] BinaryOp bop, [[maybe_unused]] const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce)
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
A class for handling words, derived from Foam::string.
Definition: word.H:63
void writeList(vtk::formatter &fmt, const UList< uint8_t > &values)
Write a list of uint8_t values.
word format(conversionProperties.get< word >("format"))
void writeUniform(const word &fieldName, const Type &val, const label nValues)
Write uniform field content.
void writeListParallel(vtk::formatter &fmt, const UList< Type > &values)
Write a list of values.
void writeValueParallel(vtk::formatter &fmt, const Type &val, const label count=1)
Component-wise write of a value (N times) in parallel.
void beginDataArray(const word &fieldName, const label nValues)
Start of a field or DataArray output (legacy or non-legacy).