writer.C
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) 2019 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 \*---------------------------------------------------------------------------*/
28 
29 #include "writer.H"
30 #include "coordSet.H"
31 #include "OFstream.H"
32 #include "OSspecific.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 template<class Type>
38 (
39  const word& writeType
40 )
41 {
42  auto cstrIter = wordConstructorTablePtr_->cfind(writeType);
43 
44  if (!cstrIter.found())
45  {
47  (
48  "writer",
49  writeType,
50  *wordConstructorTablePtr_
51  ) << exit(FatalError);
52  }
53 
54  return autoPtr<writer<Type>>(cstrIter()());
55 }
56 
57 
58 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
59 
60 template<class Type>
62 (
63  const coordSet& points,
64  const wordList& valueSets
65 ) const
66 {
67  fileName fName(points.name());
68 
69  forAll(valueSets, i)
70  {
71  fName += '_' + valueSets[i];
72  }
73 
74  return fName;
75 }
76 
77 
78 template<class Type>
80 (
81  const coordSet& points,
82  const label pointi,
83  Ostream& os
84 ) const
85 {
86  if (points.hasVectorAxis())
87  {
88  write(points.vectorCoord(pointi), os);
89  }
90  else
91  {
92  write(points.scalarCoord(pointi), os);
93  }
94 }
95 
96 
97 template<class Type>
99 (
100  const coordSet& points,
101  const List<Type>& values,
102  Ostream& os
103 ) const
104 {
105  forAll(points, pointi)
106  {
107  writeCoord(points, pointi, os);
108  writeSeparator(os);
109  write(values[pointi], os);
110  os << nl;
111  }
112 }
113 
114 
115 template<class Type>
117 (
118  const coordSet& points,
119  const List<const List<Type>*>& valuesPtrList,
120  Ostream& os
121 ) const
122 {
123  forAll(points, pointi)
124  {
125  writeCoord(points, pointi, os);
126 
127  forAll(valuesPtrList, i)
128  {
129  writeSeparator(os);
130 
131  const List<Type>& values = *valuesPtrList[i];
132  write(values[pointi], os);
133  }
134  os << nl;
135  }
136 }
137 
138 
139 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
140 
141 template<class Type>
143 {}
144 
145 
146 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
147 
148 template<class Type>
150 {}
151 
152 
153 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
154 
155 template<class Type>
157 (
158  const coordSet& points,
159  const wordList& valueSetNames,
160  const List<Field<Type>>& valueSets,
161  Ostream& os
162 ) const
163 {
164  List<const Field<Type>*> valueSetPtrs(valueSets.size());
165  forAll(valueSetPtrs, i)
166  {
167  valueSetPtrs[i] = &valueSets[i];
168  }
169  write(points, valueSetNames, valueSetPtrs, os);
170 }
171 
172 
173 template<class Type>
175 (
176  const scalar value,
177  Ostream& os
178 ) const
179 {
180  return os << value;
181 }
182 
183 
184 template<class Type>
185 template<class VSType>
187 (
188  const VSType& value,
189  Ostream& os
190 ) const
191 {
192  for (direction d=0; d<VSType::nComponents; d++)
193  {
194  if (d > 0)
195  {
196  writeSeparator(os);
197  }
198 
199  os << value.component(d);
200  }
201  return os;
202 }
203 
204 
205 template<class Type>
207 (
208  Ostream& os
209 ) const
210 {
211  os << token::SPACE << token::TAB;
212 }
213 
214 
215 template<class Type>
217 (
218  const vector& value,
219  Ostream& os
220 ) const
221 {
222  return writeVS(value, os);
223 }
224 
225 
226 template<class Type>
228 (
229  const sphericalTensor& value,
230  Ostream& os
231 ) const
232 {
233  return writeVS(value, os);
234 }
235 
236 
237 template<class Type>
239 (
240  const symmTensor& value,
241  Ostream& os
242 ) const
243 {
244  return writeVS(value, os);
245 }
246 
247 
248 template<class Type>
250 (
251  const tensor& value,
252  Ostream& os
253 ) const
254 {
255  return writeVS(value, os);
256 }
257 
258 
259 // ************************************************************************* //
Foam::Tensor< scalar >
Foam::SymmTensor< scalar >
OSspecific.H
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
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
Foam::HashTableOps::values
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:149
coordSet.H
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
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
OFstream.H
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::FatalError
error FatalError
FatalErrorInLookup
#define FatalErrorInLookup(lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalError.
Definition: error.H:385
Foam::coordSet
Holds list of sampling positions.
Definition: coordSet.H:53
Foam::SphericalTensor< scalar >
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
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
Foam::nl
constexpr char nl
Definition: Ostream.H:385
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 >
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::direction
uint8_t direction
Definition: direction.H:52
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Definition: foamVtkOutputTemplates.C:35
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
writer.H
Foam::writer::writeSeparator
virtual void writeSeparator(Ostream &os) const
Writes a separator. Used by write functions.
Definition: writer.C:207
Foam::writer::New
static autoPtr< writer > New(const word &writeFormat)
Return a reference to the selected writer.
Definition: writer.C:38