All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
setWriter.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-2021 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::setWriter
26 
27 Description
28  Base class for graphics format writing. Entry points are
29  - write(..). \n
30  Write to an Ostream a table of points with corresponding values.
31  - write(scalar/vector/sphericalTensor/symmTensor/tensor). \n
32  Write single scalar/vector/sphericalTensor/symmTensor/tensor.
33  Default is to write space separated components.
34 
35  Example:
36  \verbatim
37  // Construct setWriter of xmgr type
38  autoPtr<setWriter<scalar>> scalarFormatter =
39  setWriter<scalar>::New("xmgr");
40 
41  // Output list of points and corresponding values
42  scalarFormatter().write
43  (
44  coordSet(...)
45  "U.component(0)", // name of values
46  vals // values
47  );
48  \endverbatim
49 
50 SourceFiles
51  setWriter.C
52 
53 \*---------------------------------------------------------------------------*/
54 
55 #ifndef setWriter_H
56 #define setWriter_H
57 
58 #include "fileName.H"
59 #include "wordList.H"
60 #include "vector.H"
61 #include "tensor.H"
62 #include "typeInfo.H"
63 #include "runTimeSelectionTables.H"
64 #include "autoPtr.H"
65 #include "Field.H"
66 
67 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
68 
69 namespace Foam
70 {
71 
72 // Forward declaration of classes
73 class coordSet;
74 
75 /*---------------------------------------------------------------------------*\
76  Class setWriter Declaration
77 \*---------------------------------------------------------------------------*/
78 
79 template<class Type>
80 class setWriter
81 {
82 
83 protected:
84 
85  //- Generates filename from coordSet and sampled fields
86  fileName getBaseName(const coordSet&, const wordList&) const;
87 
88  void writeCoord(const coordSet&, const label sampleI, Ostream&) const;
89 
90  //- Writes single-column ascii write. Column 1 is coordSet coordinate,
91  // columns 2 is the value. Uses write() function
92  // to write coordinate in correct format.
93  void writeTable(const coordSet&, const List<Type>&, Ostream&) const;
94 
95  //- Writes multi-column ascii write. Column 1 is coordSet coordinate,
96  // columns 2..n are the values. Uses write() function
97  // to write coordinate in correct format.
98  void writeTable
99  (
100  const coordSet&,
101  const List<const List<Type>*>&,
102  Ostream& os
103  ) const;
104 
105  //- Writes a separator. Used by write functions.
106  virtual void writeSeparator(Ostream& os) const;
107 
108 
109 public:
110 
111  //- Runtime type information
112  TypeName("setWriter");
113 
114  // Declare run-time constructor selection table
115 
117  (
118  autoPtr,
119  setWriter,
120  word,
121  (),
122  ()
123  );
124 
125 
126  // Selectors
127 
128  //- Return a reference to the selected setWriter
129  static autoPtr<setWriter> New(const word& writeFormat);
130 
131 
132  // Constructors
133 
134  //- Construct null
135  setWriter();
136 
137 
138  //- Destructor
139  virtual ~setWriter() = 0;
140 
141 
142  // Member Functions
143 
144  //- Generate file name with correct extension
145  virtual fileName getFileName
146  (
147  const coordSet&,
148  const wordList&
149  ) const = 0;
150 
151  //- General entry point for writing.
152  // The data is organised in a set of point with one or more values
153  // per point
154  virtual void write
155  (
156  const coordSet&,
157  const wordList&,
158  const List<const Field<Type>*>&,
159  Ostream&
160  ) const = 0;
161 
162  //- General entry point for writing.
163  // The data is organised in a set of point with one or more values
164  // per point
165  virtual void write
166  (
167  const coordSet&,
168  const wordList&,
169  const List<Field<Type>>&,
170  Ostream&
171  ) const;
172 
173  //- General entry point for writing of multiple coordSets.
174  // Each coordSet (track) has same data variables.
175  // The data is per variable, per track, per point of track.
176  // If writeTracks adds connecting lines (wherever applicable)
177  virtual void write
178  (
179  const bool writeTracks,
180  const PtrList<coordSet>&,
181  const wordList& valueSetNames,
182  const List<List<Field<Type>>>&,
183  Ostream&
184  ) const = 0;
185 
186  //- Write scalar as ascii
187  virtual Ostream& write(const scalar, Ostream&) const;
188 
189  template<class VSType>
190  Ostream& writeVS(const VSType&, Ostream&) const;
191 
192  //- Write vector. Tab separated ascii
193  virtual Ostream& write(const vector&, Ostream&) const;
194 
195  //- Write sphericalTensor. Tab separated ascii
196  virtual Ostream& write(const sphericalTensor&, Ostream&) const;
197 
198  //- Write symmTensor. Tab separated ascii
199  virtual Ostream& write(const symmTensor&, Ostream&) const;
200 
201  //- Write tensor. Tab separated ascii
202  virtual Ostream& write(const tensor&, Ostream&) const;
203 };
204 
205 
206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
207 
208 } // End namespace Foam
209 
210 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
211 
212 #ifdef NoRepository
213  #include "setWriter.C"
214 #endif
215 
216 
217 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
218 
219 #endif
220 
221 // ************************************************************************* //
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A class for handling file names.
Definition: fileName.H:79
virtual void write(const coordSet &, const wordList &, const List< const Field< Type > *> &, Ostream &) const =0
General entry point for writing.
setWriter()
Construct null.
Definition: setWriter.C:140
Base class for graphics format writing. Entry points are.
Definition: setWriter.H:79
virtual fileName getFileName(const coordSet &, const wordList &) const =0
Generate file name with correct extension.
virtual ~setWriter()=0
Destructor.
Definition: setWriter.C:147
void writeCoord(const coordSet &, const label sampleI, Ostream &) const
Definition: setWriter.C:78
virtual void writeSeparator(Ostream &os) const
Writes a separator. Used by write functions.
Definition: setWriter.C:205
Templated 3D SphericalTensor derived from VectorSpace adding construction from 1 component, element access using th ii() member function and the inner-product (dot-product) and outer-product operators.
Holds list of sampling positions.
Definition: coordSet.H:49
Pre-declare SubField and related Field type.
Definition: Field.H:56
A class for handling words, derived from string.
Definition: word.H:59
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
Ostream & writeVS(const VSType &, Ostream &) const
TypeName("setWriter")
Runtime type information.
static autoPtr< setWriter > New(const word &writeFormat)
Return a reference to the selected setWriter.
Definition: setWriter.C:35
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
fileName getBaseName(const coordSet &, const wordList &) const
Generates filename from coordSet and sampled fields.
Definition: setWriter.C:60
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.
void writeTable(const coordSet &, const List< Type > &, Ostream &) const
Writes single-column ascii write. Column 1 is coordSet coordinate,.
Definition: setWriter.C:97
declareRunTimeSelectionTable(autoPtr, setWriter, word,(),())
Namespace for OpenFOAM.