vtkWritePolyData.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2021 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::vtkWritePolyData
26 
27 Description
28  General write functions for vtk polygonal data files
29 
30 SourceFiles
31  vtkWritePolyData.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef vtkWritePolyData_H
36 #define vtkWritePolyData_H
37 
38 #include "vtkWriteOps.H"
39 #include "boolList.H"
40 #include "fileName.H"
41 #include "Field.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 /*---------------------------------------------------------------------------*\
49  Namespace vtkWritePolyData Declaration
50 \*---------------------------------------------------------------------------*/
51 
52 namespace vtkWritePolyData
53 {
54 
55 //- Helper for templated write
56 template<class Types, class Type>
57 inline void setFieldTypeValue
58 (
59  UPtrList<const Field<Types>>& fieldTypeValues,
60  const label fieldi,
61  const Field<Type>& fieldTypeValue
62 )
63 {}
64 
65 
66 //- Helper for templated write
67 template<class Type>
68 inline void setFieldTypeValue
69 (
70  UPtrList<const Field<Type>>& fieldTypeValues,
71  const label fieldi,
72  const Field<Type>& fieldTypeValue
73 )
74 {
75  fieldTypeValues.set(fieldi, &fieldTypeValue);
76 }
77 
78 
79 //- Helper for templated write
81 (
82  wordList& fieldNames,
83  boolList& fieldIsPointValues,
84  UPtrList<const Field<label>>& fieldLabelValues
85  #define FieldTypeValuesNonConstArg(Type, nullArg) \
86  , UPtrList<const Field<Type>>& field##Type##Values
87  FOR_ALL_FIELD_TYPES(FieldTypeValuesNonConstArg)
88  #undef FieldTypeValuesNonConstArg
89 )
90 {}
91 
92 
93 //- Helper for templated write
94 template<class Type, class ... Args>
96 (
97  wordList& fieldNames,
98  boolList& fieldIsPointValues,
99  UPtrList<const Field<label>>& fieldLabelValues
100  #define FieldTypeValuesNonConstArg(Type, nullArg) \
101  , UPtrList<const Field<Type>>& field##Type##Values
102  FOR_ALL_FIELD_TYPES(FieldTypeValuesNonConstArg),
103  #undef FieldTypeValuesNonConstArg
104  const word& fieldName,
105  const bool fieldIsPointValue,
106  const Field<Type>& fieldTypeValue,
107  Args& ... args
108 )
109 {
110  const label fieldi = fieldNames.size() - 1 - sizeof...(Args)/3;
111 
112  fieldNames[fieldi] = fieldName;
113  fieldIsPointValues[fieldi] = fieldIsPointValue;
114  setFieldTypeValue(fieldLabelValues, fieldi, fieldTypeValue);
115  #define SetFieldTypeValue(Type, nullArg) \
116  setFieldTypeValue(field##Type##Values, fieldi, fieldTypeValue);
118  #undef SetFieldTypeValue
119 
121  (
122  fieldNames,
123  fieldIsPointValues,
124  fieldLabelValues
125  #define FieldTypeValuesParameter(Type, nullArg) , field##Type##Values
128  args ...
129  );
130 }
131 
132 
133 //- Write the field values out for a type
134 template<class Type, class DataType>
136 (
137  std::ostream& os,
138  const bool binary,
139  const wordList& fieldNames,
140  const boolList& fieldIsPointValues,
141  const UPtrList<const Field<Type>>& fieldTypeValues,
142  const bool writePointValues
143 );
144 
145 
146 //- Write VTK polygonal data to a file. Takes a PtrList of fields of labels and
147 // of every primitive type. Each PtrList should be the length of the total
148 // number of fields and only one PtrList should be non-null for each field
149 // index.
150 template<class PointField, class VertexList, class LineList, class FaceList>
151 void write
152 (
153  const fileName& file,
154  const word& title,
155  const bool binary,
156  const PointField& points,
157  const VertexList& vertices,
158  const LineList& lines,
159  const FaceList& faces,
160  const wordList& fieldNames,
161  const boolList& fieldIsPointValues,
162  const UPtrList<const Field<label>>& fieldLabelValues
163  #define FieldTypeValuesConstArg(Type, nullArg) \
164  , const UPtrList<const Field<Type>>& field##Type##Values
167 );
168 
169 
170 //- Write VTK polygonal data to a file. Takes any number of name,
171 // isPointValues, values arguments at the end. E.g.;
172 //
173 // write
174 // (
175 // // Output options
176 // "myPolyData.vtk", "myPolyData", false,
177 //
178 // // Geometry
179 // pp.localPoints(), labelList(), labelListList(), pp.localFaces(),
180 //
181 // // Fields
182 // "faceIDs", true, pp.addressing(),
183 // "facePressures", false, Field<scalar>(pp.size(), ...),
184 // "pointVelocities", true, Field<vector>(pp.nPoints(), ...)
185 // );
186 //
187 template
188 <
189  class PointField,
190  class VertexList,
191  class LineList,
192  class FaceList,
193  class ... Args
194 >
195 inline void write
196 (
197  const fileName& file,
198  const word& title,
199  const bool binary,
200  const PointField& points,
201  const VertexList& vertices,
202  const LineList& lines,
203  const FaceList& faces,
204  const Args& ... args
205 );
206 
207 };
208 
209 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
210 
211 } // End namespace Foam
212 
213 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
214 
215 #ifdef NoRepository
216  #include "vtkWritePolyDataTemplates.C"
217 #endif
218 
219 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
220 
221 #endif
222 
223 // ************************************************************************* //
#define FieldTypeValuesParameter(Type, nullArg)
A class for handling file names.
Definition: fileName.H:79
void unpackFieldTypeValues(wordList &fieldNames, boolList &fieldIsPointValues, UPtrList< const Field< label >> &fieldLabelValues #define FieldTypeValuesNonConstArg(Type, nullArg))
Helper for templated write.
void writeFieldTypeValues(std::ostream &os, const bool binary, const wordList &fieldNames, const boolList &fieldIsPointValues, const UPtrList< const Field< Type >> &fieldTypeValues, const bool writePointValues)
Write the field values out for a type.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
General write functions for vtk polygonal data files.
#define FieldTypeValuesConstArg(Type, nullArg)
pointField vertices(const blockVertexList &bvl)
const pointField & points
#define FieldTypeValuesNonConstArg(Type, nullArg)
Pre-declare SubField and related Field type.
Definition: Field.H:56
A class for handling words, derived from string.
Definition: word.H:59
GeometricField< Type, pointPatchField, pointMesh > PointField
#define SetFieldTypeValue(Type, nullArg)
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: UPtrList.H:54
void write(const fileName &file, const word &title, const bool binary, const PointField &points, const VertexList &vertices, const LineList &lines, const FaceList &faces, const wordList &fieldNames, const boolList &fieldIsPointValues, const UPtrList< const Field< label >> &fieldLabelValues #define FieldTypeValuesConstArg(Type, nullArg))
Write VTK polygonal data to a file. Takes a PtrList of fields of labels and.
void setFieldTypeValue(UPtrList< const Field< Types >> &fieldTypeValues, const label fieldi, const Field< Type > &fieldTypeValue)
Helper for templated write.
FOR_ALL_FIELD_TYPES(DefineFvWallInfoType)
rDeltaTY field()
Foam::argList args(argc, argv)
Namespace for OpenFOAM.