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-------------------------------------------------------------------------------
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
28#include <type_traits>
29#include "foamVtkOutput.H"
30
31// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
32
33template<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
87template<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
117template<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// ************************************************************************* //
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:66
A traits class, which is primarily used for primitives.
Definition: pTraits.H:59
void writeUniform(const word &fieldName, const Type &val, const label nValues)
Write uniform field content.
bool legacy() const noexcept
Commonly used query.
autoPtr< vtk::formatter > format_
The VTK formatter in use (only valid on master process)
void beginDataArray(const word &fieldName, const label nValues)
Start of a field or DataArray output (legacy or non-legacy).
void writeBasicField(const word &fieldName, const UList< Type > &field)
Write basic (primitive) field content.
vtk::formatter & format()
The VTK formatter in use. FatalError for off-processor.
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.
A class for handling words, derived from Foam::string.
Definition: word.H:68
rDeltaTY field()
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
void writeList(vtk::formatter &fmt, const UList< uint8_t > &values)
Write a list of uint8_t values.
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 reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
uint8_t direction
Definition: direction.H:56
word format(conversionProperties.get< word >("format"))