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  WRITE_POINTS = 1,
92  WRITE_LINES = 2
93  };
94 
95 
96  // Private Data
97 
98  //- Ensight case options
99  ensightCase::options caseOpts_;
101  //- Collate times (default: true)
102  bool collateTimes_;
103 
104  //- Cached information for times, geometry, fields (collated)
106 
107 
108  // Private Member Functions
109 
110  //- Write geometry
111  void writeGeometry
112  (
114  elemOutputType elemOutput
115  ) const;
116 
117  //- Write geometry
118  fileName writeCollated(const bool writeTracks);
119 
120  //- Write geometry
121  fileName writeUncollated(const bool writeTracks);
122 
123  //- Templated write operation - one file per timestep
124  template<class Type>
125  fileName writeCollated
126  (
127  const word& fieldName,
128  const UPtrList<const Field<Type>>& fieldPtrs,
129  elemOutputType elemOutput
130  );
131 
132  //- Templated write operation - all time steps in single file
133  template<class Type>
134  fileName writeUncollated
135  (
136  const word& fieldName,
137  const UPtrList<const Field<Type>>& fieldPtrs,
138  elemOutputType elemOutput
139  );
140 
141  //- Templated write operation
142  template<class Type>
143  fileName writeTemplate
144  (
145  const word& fieldName,
146  const Field<Type>& values
147  );
148 
149  //- Templated write operation
150  template<class Type>
151  fileName writeTemplate
152  (
153  const word& fieldName,
154  const List<Field<Type>>& fieldValues
155  );
156 
157 
158 public:
159 
160  //- Runtime type information (no debug)
161  TypeNameNoDebug("ensight");
162 
163 
164  // Constructors
165 
166  //- Default construct
167  ensightWriter();
168 
169  //- Default construct with specified options
170  explicit ensightWriter(const dictionary& options);
171 
172  //- Construct from components
174  (
175  const coordSet& coords,
176  const fileName& outputPath,
177  const dictionary& options = dictionary()
178  );
179 
180  //- Construct from components
182  (
183  const UPtrList<coordSet>& tracks,
184  const fileName& outputPath,
185  const dictionary& options = dictionary()
186  );
187 
188 
189  //- Destructor. Calls close()
190  virtual ~ensightWriter();
191 
192 
193  // Member Functions
194 
195  //- Finish output, clears output times.
196  // Later reuse will rebuild times from fieldsDict file cache.
197  virtual void close(bool force = false); // override
198 
199 
200  // Write
201 
202  //- Expected (characteristic) output file name - information only
203  // \warning incorrect for uncollated output!
204  virtual fileName path() const; // override
205 
212 };
213 
214 
215 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
216 
217 } // End namespace coordSetWriters
218 } // End namespace Foam
219 
220 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
221 
222 #endif
223 
224 // ************************************************************************* //
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:129
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.
Specialized Ensight output with extra geometry file header.
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:164
Holds list of sampling positions.
Definition: coordSet.H:49
Generic templated field type.
Definition: Field.H:62
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...
OBJstream os(runTime.globalPath()/outputName)
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.