xmgraceCoordSetWriter.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) 2022 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
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 Class
27  Foam::coordSetWriters::xmgraceWriter
28 
29 Description
30  Write coordSet(s) in xmgrace format
31 
32  The formatOptions for xmgrace:
33  \table
34  Property | Description | Required | Default
35  buffer | Use buffered output | no | true
36  compression | Use file compression | no | false
37  precision | Write precision in ascii | no | same as IOstream
38  \endtable
39 
40  When called with a single coordSet, will combine all output fields
41  into a single file. Although it is nominally 'buffered', it actually
42  just keeps track of the number of fields written into the file.
43 
44  When called as a track writer (eg, with multiple coordSets),
45  will emit one file per field.
46 
47  \section Output file locations
48 
49  The \c rootdir normally corresponds to something like
50  \c postProcessing/<name>
51 
52  \subsection Geometry and Fields
53  \verbatim
54  rootdir
55  `-- timeName
56  `-- setName.{agr}
57  \endverbatim
58 
59 SourceFiles
60  xmgraceCoordSetWriter.C
61 
62 \*---------------------------------------------------------------------------*/
63 
64 #ifndef Foam_coordSetWriters_xmgraceWriter_H
65 #define Foam_coordSetWriters_xmgraceWriter_H
66 
67 #include "coordSetWriter.H"
68 
69 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
70 
71 namespace Foam
72 {
73 
74 // Forward Declarations
75 class OFstream;
76 
77 namespace coordSetWriters
78 {
79 
80 /*---------------------------------------------------------------------------*\
81  Class xmgraceWriter Declaration
82 \*---------------------------------------------------------------------------*/
83 
84 class xmgraceWriter
85 :
86  public coordSetWriter
87 {
88  // Private Data
89 
90  //- Output stream option
91  IOstreamOption streamOpt_;
92 
93  //- ASCII write precision
94  unsigned precision_;
95 
96  //- Backend output file (when buffering)
97  autoPtr<Foam::OFstream> ofile_;
98 
99  //- The number of fields written (when buffering)
100  label nWritten_;
101 
102 
103  // Private Member Functions
104 
105  //- Templated write operation
106  template<class Type>
107  fileName writeTemplate
108  (
109  const word& fieldName,
110  const UPtrList<const Field<Type>>& fieldPtrs
111  );
112 
113  //- Templated write operation
114  template<class Type>
115  fileName writeTemplate
116  (
117  const word& fieldName,
118  const Field<Type>& vals
119  );
120 
121  //- Templated write operation
122  template<class Type>
123  fileName writeTemplate
124  (
125  const word& fieldName,
126  const List<Field<Type>>& fieldValues
127  );
128 
129 
130 public:
131 
132  //- Runtime type information (no debug)
133  TypeNameNoDebug("xmgr");
134 
135 
136  // Constructors
137 
138  //- Default construct
139  xmgraceWriter();
140 
141  //- Default construct with specified options
142  explicit xmgraceWriter(const dictionary& options);
143 
144  //- Construct from components
146  (
147  const coordSet& coords,
148  const fileName& outputPath,
149  const dictionary& options = dictionary()
150  );
151 
152  //- Construct from components
154  (
155  const UPtrList<coordSet>& tracks,
156  const fileName& outputPath,
157  const dictionary& options = dictionary()
158  );
159 
160 
161  //- Destructor. Calls close()
162  virtual ~xmgraceWriter();
163 
164 
165  // Member Functions
166 
167  //- Enable/disable internal buffering
168  virtual bool buffering(const bool on); // override
169 
170  //- Characteristic output file name - information only
171  virtual fileName path() const; // override
172 
173  //- Close and reset, clears backend.
174  virtual void close(bool force = false); // override
175 
176  //- Begin time step. Clears existing backend.
177  virtual void beginTime(const Time& t); // override
178 
179  //- Begin time step. Clears existing backend.
180  virtual void beginTime(const instant& inst); // override
181 
182  //- End time step. Clears existing backend.
183  virtual void endTime(); // override
184 
185 
192 };
193 
194 
195 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
196 
197 } // End namespace coordSetWriters
198 } // End namespace Foam
199 
200 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
201 
202 #endif
203 
204 // ************************************************************************* //
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
virtual bool buffering() const
True if the format uses internal buffering (eg, column output)
virtual ~xmgraceWriter()
Destructor. Calls close()
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
virtual fileName path() const
Characteristic output file name - information only.
Holds list of sampling positions.
Definition: coordSet.H:49
Generic templated field type.
Definition: Field.H:62
TypeNameNoDebug("xmgr")
Runtime type information (no debug)
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual void close(bool force=false)
Close and reset, clears backend.
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...
virtual void endTime()
End time step. Clears existing backend.
An instant of time. Contains the time value and name. Uses Foam::Time when formatting the name...
Definition: instant.H:53
virtual void beginTime(const Time &t)
Begin time step. Clears existing backend.
Tensor of scalars, i.e. Tensor<scalar>.
Namespace for OpenFOAM.