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 -------------------------------------------------------------------------------
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::writer
28 
29 Description
30  Base class for graphics format writing. Entry points are
31  - write(..). \n
32  Write to an Ostream a table of points with corresponding values.
33  - write(scalar/vector/sphericalTensor/symmTensor/tensor). \n
34  Write single scalar/vector/sphericalTensor/symmTensor/tensor.
35  Default is to write space separated components.
36 
37  Example:
38  \verbatim
39  // Construct writer of xmgr type
40  autoPtr<writer<scalar>> scalarFormatter(writer<scalar>::New("xmgr"));
41 
42  // Output list of points and corresponding values
43  scalarFormatter().write
44  (
45  coordSet(...)
46  "U.component(0)", // name of values
47  vals // values
48  );
49  \endverbatim
50 
51 SourceFiles
52  writer.C
53 
54 \*---------------------------------------------------------------------------*/
55 
56 #ifndef writer_H
57 #define writer_H
58 
59 #include "fileName.H"
60 #include "wordList.H"
61 #include "vector.H"
62 #include "tensor.H"
63 #include "typeInfo.H"
64 #include "runTimeSelectionTables.H"
65 #include "autoPtr.H"
66 #include "Field.H"
67 
68 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
69 
70 namespace Foam
71 {
72 
73 // Forward declaration of classes
74 class coordSet;
75 
76 /*---------------------------------------------------------------------------*\
77  Class writer Declaration
78 \*---------------------------------------------------------------------------*/
79 
80 template<class Type>
81 class writer
82 {
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 
126 
127  // Selectors
128 
129  //- Return a reference to the selected writer
130  static autoPtr<writer> New(const word& writeFormat);
131 
132 
133  // Constructors
134 
135  //- Construct null
136  writer();
137 
138 
139  //- Destructor
140  virtual ~writer() = 0;
141 
142 
143  // Member Functions
144 
145  //- Generate file name with correct extension
146  virtual fileName getFileName
147  (
148  const coordSet&,
149  const wordList&
150  ) const = 0;
151 
152  //- General entry point for writing.
153  // The data is organized in a set of point with one or more values
154  // per point
155  virtual void write
156  (
157  const coordSet&,
158  const wordList&,
159  const List<const Field<Type>*>&,
160  Ostream&
161  ) const = 0;
162 
163  //- General entry point for writing.
164  // The data is organized in a set of point with one or more values
165  // per point
166  virtual void write
167  (
168  const coordSet&,
169  const wordList&,
170  const List<Field<Type>>&,
171  Ostream&
172  ) const;
173 
174  //- General entry point for writing of multiple coordSets.
175  // Each coordSet (track) has same data variables.
176  // The data is per variable, per track, per point of track.
177  // If writeTracks adds connecting lines (wherever applicable)
178  virtual void write
179  (
180  const bool writeTracks,
181  const PtrList<coordSet>&,
182  const wordList& valueSetNames,
183  const List<List<Field<Type>>>&,
184  Ostream&
185  ) const = 0;
186 
187  //- Write scalar as ascii
188  virtual Ostream& write(const scalar, Ostream&) const;
189 
190  template<class VSType>
191  Ostream& writeVS(const VSType&, Ostream&) const;
192 
193  //- Write vector. Tab separated ascii
194  virtual Ostream& write(const vector&, Ostream&) const;
195 
196  //- Write sphericalTensor. Tab separated ascii
197  virtual Ostream& write(const sphericalTensor&, Ostream&) const;
198 
199  //- Write symmTensor. Tab separated ascii
200  virtual Ostream& write(const symmTensor&, Ostream&) const;
201 
202  //- Write tensor. Tab separated ascii
203  virtual Ostream& write(const tensor&, Ostream&) const;
204 };
205 
206 
207 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
208 
209 } // End namespace Foam
210 
211 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
212 
213 #ifdef NoRepository
214  #include "writer.C"
215 #endif
216 
217 
218 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
219 
220 #endif
221 
222 // ************************************************************************* //
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:62
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
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:62
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()=0
Destructor.
Definition: writer.C:149
tensor.H
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:62
Foam::writer
Base class for graphics format writing. Entry points are.
Definition: writer.H:80
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()
Construct null.
Definition: writer.C:142
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:99
Foam::Vector< scalar >
Foam::List< word >
vector.H
Foam::writer::writeCoord
void writeCoord(const coordSet &, const label sampleI, Ostream &) const
Definition: writer.C:80
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:207
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