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-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 <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  static_assert
41  (
42  (
43  std::is_same<label, typename pTraits<Type>::cmptType>::value
44  || std::is_floating_point<typename pTraits<Type>::cmptType>::value
45  ),
46  "Label and Floating-point vector space only"
47  );
48 
50 
51  if (format_)
52  {
53  if (std::is_same<label, typename pTraits<Type>::cmptType>::value)
54  {
55  if (legacy())
56  {
57  legacy::intField<nCmpt>(format(), fieldName, nValues);
58  }
59  else
60  {
61  const uint64_t payLoad =
62  vtk::sizeofData<label, nCmpt>(nValues);
63 
64  format().beginDataArray<label, nCmpt>(fieldName);
65  format().writeSize(payLoad);
66  }
67  }
68  else
69  {
70  if (legacy())
71  {
72  legacy::floatField<nCmpt>(format(), fieldName, nValues);
73  }
74  else
75  {
76  const uint64_t payLoad =
77  vtk::sizeofData<float, nCmpt>(nValues);
78 
79  format().beginDataArray<float, nCmpt>(fieldName);
80  format().writeSize(payLoad);
81  }
82  }
83  }
84 }
85 
86 
87 template<class Type>
89 (
90  const word& fieldName,
91  const Type& val,
92  const label nLocalValues
93 )
94 {
95  label nTotal = nLocalValues;
96 
97  if (parallel_)
98  {
99  reduce(nTotal, sumOp<label>());
100  }
101 
102  this->beginDataArray<Type>(fieldName, nTotal);
103 
104  if (parallel_)
105  {
106  vtk::writeValueParallel(format_.ref(), val, nLocalValues);
107  }
108  else
109  {
110  vtk::write(format(), val, nLocalValues);
111  }
112 
113  this->endDataArray();
114 }
115 
116 
117 template<class Type>
119 (
120  const word& fieldName,
121  const UList<Type>& field
122 )
123 {
124  label nValues = field.size();
125 
126  if (parallel_)
127  {
128  reduce(nValues, sumOp<label>());
129  }
130 
131  this->beginDataArray<Type>(fieldName, nValues);
132 
133  if (parallel_)
134  {
135  vtk::writeListParallel(format_.ref(), field);
136  }
137  else
138  {
140  }
141 
142  this->endDataArray();
143 }
144 
145 
146 // ************************************************************************* //
foamVtkOutput.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::vtk::fileWriter::beginDataArray
void beginDataArray(const word &fieldName, const label nValues)
Start of a field or DataArray output (legacy or non-legacy).
Definition: foamVtkFileWriterTemplates.C:35
Foam::vtk::fileWriter::writeUniform
void writeUniform(const word &fieldName, const Type &val, const label nValues)
Write uniform field content.
Definition: foamVtkFileWriterTemplates.C:89
Foam::sumOp
Definition: ops.H:213
format
word format(conversionProperties.get< word >("format"))
Foam::vtk::writeValueParallel
void writeValueParallel(vtk::formatter &fmt, const Type &val, const label count=1)
Component-wise write of a value (N times) in parallel.
Definition: foamVtkOutputTemplates.C:128
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::fileWriter::writeBasicField
void writeBasicField(const word &fieldName, const UList< Type > &field)
Write basic (primitive) field content.
Definition: foamVtkFileWriterTemplates.C:119
reduce
reduce(hasMovingMesh, orOp< bool >())
Foam::pTraits
A traits class, which is primarily used for primitives.
Definition: pTraits.H:56
Foam::UList< Type >
Foam::direction
uint8_t direction
Definition: direction.H:52
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
Foam::vtk::writeListParallel
void writeListParallel(vtk::formatter &fmt, const UList< Type > &values)
Write a list of values.
Definition: foamVtkOutputTemplates.C:164