ensightCoordSetWriter.H
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) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2021-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::coordSetWriters::ensightCoordSetWriter
29 
30 Description
31  A coordSetWriter for Ensight format.
32 
33  \verbatim
34  formatOptions
35  {
36  ensight
37  {
38  format ascii;
39  collateTimes true;
40  }
41  }
42  \endverbatim
43 
44  Format options:
45  \table
46  Property | Description | Required | Default
47  format | ascii/binary | no | binary
48  collateTimes | use common geometry for times | no | true
49  timeFormat | Time format (ensight case) | no | scientific
50  timePrecision | Time precision (ensight case) | no | 5
51  \endtable
52  \endtable
53 
54 SourceFiles
55  ensightCoordSetWriter.C
56 
57 \*---------------------------------------------------------------------------*/
58 
59 #ifndef Foam_coordSetWriters_ensightWriter_H
60 #define Foam_coordSetWriters_ensightWriter_H
61 
62 #include "coordSetWriter.H"
63 #include "ensightCase.H"
64 #include "ensightWriterCaching.H"
65 
66 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
67 
68 namespace Foam
69 {
70 
71 // Forward Declarations
72 class ensightGeoFile;
73 
74 namespace coordSetWriters
75 {
76 
77 /*---------------------------------------------------------------------------*\
78  Class ensightWriter Declaration
79 \*---------------------------------------------------------------------------*/
80 
81 class ensightWriter
82 :
83  public coordSetWriter
84 {
85  // Data Types
86 
87  //- Types of element output
88  enum elemOutputType
89  {
90  NO_ELEMENTS = 0,
91  VERTEX_ELEMENTS = 2,
92  LINE_ELEMENTS = 3,
93 
94  // Compatibility (older names)
95  WRITE_POINTS = VERTEX_ELEMENTS,
96  WRITE_LINES = LINE_ELEMENTS
97  };
98 
99 
100  // Private Data
101 
102  //- Ensight case options
103  ensightCase::options caseOpts_;
104 
105  //- Collate times (default: true)
106  bool collateTimes_;
107 
108  //- Cached information for times, geometry, fields (collated)
110 
111 
112  // Private Member Functions
113 
114  //- Write geometry
115  void writeGeometry
116  (
117  ensightGeoFile& os,
118  elemOutputType elemOutput
119  ) const;
120 
121  //- Write geometry
122  fileName writeCollated(const bool writeTracks);
123 
124  //- Write geometry
125  fileName writeUncollated(const bool writeTracks);
126 
127  //- Templated write operation - one file per timestep
128  template<class Type>
129  fileName writeCollated
130  (
131  const word& fieldName,
132  const UPtrList<const Field<Type>>& fieldPtrs,
133  elemOutputType elemOutput
134  );
135 
136  //- Templated write operation - all time steps in single file
137  template<class Type>
138  fileName writeUncollated
139  (
140  const word& fieldName,
141  const UPtrList<const Field<Type>>& fieldPtrs,
142  elemOutputType elemOutput
143  );
144 
145  //- Templated write operation
146  template<class Type>
147  fileName writeTemplate
148  (
149  const word& fieldName,
150  const Field<Type>& values
151  );
152 
153  //- Templated write operation
154  template<class Type>
155  fileName writeTemplate
156  (
157  const word& fieldName,
158  const List<Field<Type>>& fieldValues
159  );
160 
161 
162 public:
163 
164  //- Runtime type information (no debug)
165  TypeNameNoDebug("ensight");
166 
167 
168  // Constructors
169 
170  //- Default construct
171  ensightWriter();
172 
173  //- Default construct with specified options
174  explicit ensightWriter(const dictionary& options);
175 
176  //- Construct from components
178  (
179  const coordSet& coords,
180  const fileName& outputPath,
181  const dictionary& options = dictionary()
182  );
183 
184  //- Construct from components
186  (
187  const UPtrList<coordSet>& tracks,
188  const fileName& outputPath,
189  const dictionary& options = dictionary()
190  );
191 
192 
193  //- Destructor. Calls close()
194  virtual ~ensightWriter();
195 
196 
197  // Member Functions
198 
199  //- Finish output, clears output times.
200  // Later reuse will rebuild times from fieldsDict file cache.
201  virtual void close(bool force = false); // override
202 
203 
204  // Write
205 
206  //- Expected (characteristic) output file name - information only
207  // \warning incorrect for uncollated output!
208  virtual fileName path() const; // override
209 
216 };
217 
218 
219 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
220 
221 } // End namespace coordSetWriters
222 } // End namespace Foam
223 
224 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
225 
226 #endif
227 
228 // ************************************************************************* //
A class for handling file names.
Definition: fileName.H:72
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:130
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
State information for writers with collated times.
A variant of ensightFile (Ensight writing) that includes the extra geometry file header information...
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:164
Configuration options for the ensightCase.
Definition: ensightCase.H:546
Holds list of sampling positions.
Definition: coordSet.H:49
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition: Field.H:69
A class for handling words, derived from Foam::string.
Definition: word.H:63
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition: HashTable.H:106
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
TypeNameNoDebug("ensight")
Runtime type information (no debug)
virtual void close(bool force=false)
Finish output, clears output times.
virtual fileName path() const
Expected (characteristic) output file name - information only.
Tensor of scalars, i.e. Tensor<scalar>.
virtual ~ensightWriter()
Destructor. Calls close()
Namespace for OpenFOAM.