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