writer.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 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::writer
29 
30 Description
31  Base class for graphics format writing. Entry points are
32  - write(..). \n
33  Write to an Ostream a table of points with corresponding values.
34  - write(scalar/vector/sphericalTensor/symmTensor/tensor). \n
35  Write single scalar/vector/sphericalTensor/symmTensor/tensor.
36  Default is to write space separated components.
37 
38  Example:
39  \verbatim
40  // Construct writer of xmgr type
41  autoPtr<writer<scalar>> scalarFormatter(writer<scalar>::New("xmgr"));
42 
43  // Output list of points and corresponding values
44  scalarFormatter().write
45  (
46  coordSet(...)
47  "U.component(0)", // name of values
48  vals // values
49  );
50  \endverbatim
51 
52 SourceFiles
53  writer.C
54 
55 \*---------------------------------------------------------------------------*/
56 
57 #ifndef writer_H
58 #define writer_H
59 
60 #include "fileName.H"
61 #include "wordList.H"
62 #include "vector.H"
63 #include "tensor.H"
64 #include "typeInfo.H"
65 #include "runTimeSelectionTables.H"
66 #include "autoPtr.H"
67 #include "Field.H"
68 
69 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
70 
71 namespace Foam
72 {
73 
74 // Forward Declarations
75 class coordSet;
76 
77 /*---------------------------------------------------------------------------*\
78  Class writer Declaration
79 \*---------------------------------------------------------------------------*/
80 
81 template<class Type>
82 class writer
83 {
84 protected:
85 
86  //- Generates filename from coordSet and sampled fields
87  fileName getBaseName(const coordSet&, const wordList&) const;
88 
89  void writeCoord(const coordSet&, const label sampleI, Ostream&) const;
90 
91  //- Writes single-column ascii write. Column 1 is coordSet coordinate,
92  // columns 2 is the value. Uses write() function
93  // to write coordinate in correct format.
94  void writeTable(const coordSet&, const List<Type>&, Ostream&) const;
95 
96  //- Writes multi-column ascii write. Column 1 is coordSet coordinate,
97  // columns 2..n are the values. Uses write() function
98  // to write coordinate in correct format.
99  void writeTable
100  (
101  const coordSet&,
102  const List<const List<Type>*>&,
103  Ostream& os
104  ) const;
105 
106  //- Writes a separator. Used by write functions.
107  virtual void writeSeparator(Ostream& os) const;
108 
109 
110 public:
111 
112  //- Runtime type information
113  TypeName("writer");
114 
115  // Declare run-time constructor selection table
116 
118  (
119  autoPtr,
120  writer,
121  word,
122  (),
123  ()
124  );
125 
127  (
128  autoPtr,
129  writer,
130  dict,
131  (
133  ),
134  (formatOptions)
135  );
136 
137 
138  // Selectors
139 
140  //- Return a reference to the selected writer
141  static autoPtr<writer> New(const word& writeFormat);
142 
143  //- Return a reference to the selected writer
144  static autoPtr<writer> New
145  (
146  const word& writeFormat,
148  );
149 
150 
151  // Constructors
152 
153  //- Default construct
154  writer();
155 
156  //- Construct with dictionary
157  explicit writer(const dictionary& dict);
158 
159 
160  //- Destructor
161  virtual ~writer() = default;
162 
163 
164  // Member Functions
165 
166  //- Generate file name with correct extension
167  virtual fileName getFileName
168  (
169  const coordSet&,
170  const wordList&
171  ) const = 0;
172 
173  //- General entry point for writing.
174  // The data is organized in a set of point with one or more values
175  // per point
176  virtual void write
177  (
178  const coordSet&,
179  const wordList&,
180  const List<const Field<Type>*>&,
181  Ostream&
182  ) const = 0;
183 
184  //- General entry point for writing.
185  // The data is organized in a set of point with one or more values
186  // per point
187  virtual void write
188  (
189  const coordSet&,
190  const wordList&,
191  const List<Field<Type>>&,
192  Ostream&
193  ) const;
194 
195  //- General entry point for writing of multiple coordSets.
196  // Each coordSet (track) has same data variables.
197  // The data is per variable, per track, per point of track.
198  // If writeTracks adds connecting lines (wherever applicable)
199  virtual void write
200  (
201  const bool writeTracks,
202  const List<scalarField>& times,
203  const PtrList<coordSet>& tracks,
204  const wordList& valueSetNames,
205  const List<List<Field<Type>>>& valueSets,
206  Ostream&
207  ) const = 0;
208 
209  //- Write scalar as ascii
210  virtual Ostream& write(const scalar, Ostream&) const;
211 
212  template<class VSType>
213  Ostream& writeVS(const VSType&, Ostream&) const;
214 
215  //- Write vector. Tab separated ascii
216  virtual Ostream& write(const vector&, Ostream&) const;
217 
218  //- Write sphericalTensor. Tab separated ascii
219  virtual Ostream& write(const sphericalTensor&, Ostream&) const;
220 
221  //- Write symmTensor. Tab separated ascii
222  virtual Ostream& write(const symmTensor&, Ostream&) const;
223 
224  //- Write tensor. Tab separated ascii
225  virtual Ostream& write(const tensor&, Ostream&) const;
226 };
227 
228 
229 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
230 
231 } // End namespace Foam
232 
233 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
234 
235 #ifdef NoRepository
236  #include "writer.C"
237 #endif
238 
239 
240 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
241 
242 #endif
243 
244 // ************************************************************************* //
Foam::Tensor< scalar >
Foam::SymmTensor< scalar >
Foam::writer::declareRunTimeSelectionTable
declareRunTimeSelectionTable(autoPtr, writer, word,(),())
Foam::writer::writeVS
Ostream & writeVS(const VSType &, Ostream &) const
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
typeInfo.H
Foam::writer::TypeName
TypeName("writer")
Runtime type information.
Foam::writer::getBaseName
fileName getBaseName(const coordSet &, const wordList &) const
Generates filename from coordSet and sampled fields.
Definition: writer.C:85
Foam::writer::write
virtual void write(const coordSet &, const wordList &, const List< const Field< Type > * > &, Ostream &) const =0
General entry point for writing.
Foam::writer::~writer
virtual ~writer()=default
Destructor.
tensor.H
formatOptions
const dictionary formatOptions
Definition: createFields.H:26
wordList.H
Foam::writer::getFileName
virtual fileName getFileName(const coordSet &, const wordList &) const =0
Generate file name with correct extension.
Foam::Field
Generic templated field type.
Definition: Field.H:63
Field.H
fileName.H
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:59
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam::writer
Base class for graphics format writing. Entry points are.
Definition: writer.H:81
Foam::coordSet
Holds list of sampling positions.
Definition: coordSet.H:53
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::SphericalTensor< scalar >
Foam::writer::writer
writer()
Default construct.
Definition: writer.C:165
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
runTimeSelectionTables.H
Macros to ease declaration of run-time selection tables.
Foam::writer::writeTable
void writeTable(const coordSet &, const List< Type > &, Ostream &) const
Writes single-column ascii write. Column 1 is coordSet coordinate,.
Definition: writer.C:122
Foam::Vector< scalar >
Foam::List< word >
vector.H
Foam::writer::writeCoord
void writeCoord(const coordSet &, const label sampleI, Ostream &) const
Definition: writer.C:103
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::writer::writeSeparator
virtual void writeSeparator(Ostream &os) const
Writes a separator. Used by write functions.
Definition: writer.C:228
writer.C
autoPtr.H
Foam::writer::New
static autoPtr< writer > New(const word &writeFormat)
Return a reference to the selected writer.
Definition: writer.C:38