surfaceWriter.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) 2011-2022 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::surfaceWriter
26 
27 Description
28  Base class for surface writers
29 
30 SourceFiles
31  surfaceWriter.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef surfaceWriter_H
36 #define surfaceWriter_H
37 
38 #include "typeInfo.H"
39 #include "autoPtr.H"
40 #include "pointField.H"
41 #include "faceList.H"
42 #include "fileName.H"
43 #include "setWriter.H"
44 #include "runTimeSelectionTables.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 /*---------------------------------------------------------------------------*\
52  Class surfaceWriter Declaration
53 \*---------------------------------------------------------------------------*/
54 
55 class surfaceWriter
56 {
57 protected:
58 
59  // Protected Data
60 
61  //- Write format
63 
64  //- Write compression
66 
67 
68 public:
69 
70  //- Runtime type information
71  TypeName("surfaceWriter");
72 
73  // Declare run-time constructor selection table
74 
76  (
77  autoPtr,
79  word,
80  (
81  const IOstream::streamFormat writeFormat,
82  const IOstream::compressionType writeCompression
83  ),
84  (writeFormat, writeCompression)
85  );
86 
88  (
89  autoPtr,
91  dict,
92  (
93  const dictionary& dict
94  ),
95  (dict)
96  );
97 
98 
99  // Selectors
100 
101  //- Select given write options
103  (
104  const word& writeType,
105  const IOstream::streamFormat writeFormat,
106  const IOstream::compressionType writeCompression
107  );
108 
109  //- Select given a dictionary
111  (
112  const word& writeType,
113  const dictionary& dict
114  );
115 
116 
117  // Constructors
118 
119  //- Construct given write options
121  (
122  const IOstream::streamFormat writeFormat,
123  const IOstream::compressionType writeCompression
124  );
125 
126  //- Construct from dictionary
127  surfaceWriter(const dictionary& dict);
128 
129 
130  //- Destructor
131  virtual ~surfaceWriter();
132 
133 
134  // Member Functions
135 
136  //- Write fields for a single surface to file.
137  virtual void write
138  (
139  const fileName& outputDir, // <case>/surface/TIME
140  const fileName& surfaceName, // name of surface
141  const pointField& points,
142  const faceList& faces,
143  const wordList& fieldNames, // names of fields
144  const bool writePointValues
145  #define FieldTypeValuesConstArg(Type, nullArg) \
146  , const UPtrList<const Field<Type>>& field##Type##Values
147  FOR_ALL_FIELD_TYPES(FieldTypeValuesConstArg)
148  #undef FieldTypeValuesConstArg
149  ) const = 0;
150 
151  //- Write fields for a single surface to file.
152  virtual void write
153  (
154  const fileName& outputDir, // <case>/surface/TIME
155  const fileName& surfaceName, // name of surface
156  const pointField& points,
157  const faceList& faces,
158  const wordList& fieldNames, // names of fields
159  const bool writePointValues
160  #define FieldTypeValuesConstArg(Type, nullArg) \
161  , const PtrList<Field<Type>>& field##Type##Values
162  FOR_ALL_FIELD_TYPES(FieldTypeValuesConstArg)
163  #undef FieldTypeValuesConstArg
164  ) const
165  {
166  write
167  (
168  outputDir,
169  surfaceName,
170  points,
171  faces,
172  fieldNames,
173  writePointValues
174  #define FieldTypeValuesParameter(Type, nullArg) \
175  , reinterpret_cast<const UPtrList<const Field<Type>>&> \
176  (field##Type##Values)
179  );
180  }
181 
182  //- Write the surface geometry only.
183  void inline write
184  (
185  const fileName& outputDir, // <case>/surface/TIME
186  const fileName& surfaceName, // name of surface
187  const pointField& points,
188  const faceList& faces
189  ) const
190  {
191  write
192  (
193  outputDir,
194  surfaceName,
195  points,
196  faces,
197  wordList(),
198  false
199  #define FieldTypeValuesParameter(Type, nullArg) \
200  , UPtrList<const Field<Type>>()
203  );
204  }
205 
206  //- Write fields for a single surface to file. For use in code where
207  // the fields that are to be written are known. Takes any number of
208  // name, values arguments at the end. E.g.:
209  //
210  // write
211  // (
212  // // Output options
213  // "myDirectory", "mySurface",
214  //
215  // // Geometry
216  // pp.localPoints(), pp.localFaces(),
217  //
218  // // Fields
219  // "p", Field<scalar>(pp.size(), ...),
220  // "U", Field<vector>(pp.size(), ...)
221  // );
222  //
223  template<class ... Args>
224  void inline write
225  (
226  const fileName& outputDir, // <case>/surface/TIME
227  const fileName& surfaceName, // name of surface
228  const pointField& points,
229  const faceList& faces,
230  const bool writePointValues,
231  const Args& ... args
232  ) const
233  {
235  #define DeclareFieldTypeValues(Type, nullArg) \
236  UPtrList<const Field<Type>> field##Type##Values;
238  #undef DeclareFieldTypeValues
239 
241  (
242  fieldNames
243  #define FieldTypeValuesParameter(Type, nullArg) \
244  , field##Type##Values
247  args ...
248  );
249 
250  write
251  (
252  outputDir,
253  surfaceName,
254  points,
255  faces,
256  fieldNames,
257  writePointValues
258  #define FieldTypeValuesParameter(Type, nullArg) \
259  , field##Type##Values
262  );
263  }
264 };
265 
266 
267 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
268 
269 } // End namespace Foam
270 
271 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
272 
273 #endif
274 
275 // ************************************************************************* //
A class for handling file names.
Definition: fileName.H:79
#define FieldTypeValuesParameter(Type, nullArg)
IOstream::compressionType writeCompression_
Write compression.
Definition: surfaceWriter.H:64
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
#define FieldTypeValuesConstArg(Type, nullArg)
static void unpackTypeValueSets(wordList &valueSetNames #define TypeValueSetsNonConstArg(Type, nullArg))
Helper for variadic write.
Definition: setWriter.H:95
virtual ~surfaceWriter()
Destructor.
static List< word > fieldNames
Definition: globalFoam.H:46
IOstream::streamFormat writeFormat_
Write format.
Definition: surfaceWriter.H:61
surfaceWriter(const IOstream::streamFormat writeFormat, const IOstream::compressionType writeCompression)
Construct given write options.
Definition: surfaceWriter.C:44
A class for handling words, derived from string.
Definition: word.H:59
virtual void write(const fileName &outputDir, const fileName &surfaceName, const pointField &points, const faceList &faces, const wordList &fieldNames, const bool writePointValues #define FieldTypeValuesConstArg(Type, nullArg)) const =0
Write fields for a single surface to file.
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
static autoPtr< surfaceWriter > New(const word &writeType, const IOstream::streamFormat writeFormat, const IOstream::compressionType writeCompression)
Select given write options.
Definition: surfaceWriter.C:75
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
#define DeclareFieldTypeValues(Type, nullArg)
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:193
TypeName("surfaceWriter")
Runtime type information.
List< word > wordList
A List of words.
Definition: fileName.H:54
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:70
FOR_ALL_FIELD_TYPES(DefineFvWallInfoType)
Base class for surface writers.
Definition: surfaceWriter.H:54
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
Macros to ease declaration of run-time selection tables.
rDeltaTY field()
Foam::argList args(argc, argv)
declareRunTimeSelectionTable(autoPtr, surfaceWriter, word,(const IOstream::streamFormat writeFormat, const IOstream::compressionType writeCompression),(writeFormat, writeCompression))
Namespace for OpenFOAM.