All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
writer.C
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 \*---------------------------------------------------------------------------*/
25 
26 #include "writer.H"
27 #include "coordSet.H"
28 #include "OFstream.H"
29 #include "OSspecific.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 template<class Type>
35 (
36  const word& writeType
37 )
38 {
39  typename wordConstructorTable::iterator cstrIter =
40  wordConstructorTablePtr_->find(writeType);
41 
42  if (cstrIter == wordConstructorTablePtr_->end())
43  {
45  << "Unknown write type "
46  << writeType << nl << nl
47  << "Valid write types : " << endl
48  << wordConstructorTablePtr_->sortedToc()
49  << exit(FatalError);
50  }
51 
52  return autoPtr<writer<Type>>(cstrIter()());
53 }
54 
55 
56 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
57 
58 template<class Type>
60 (
61  const coordSet& points,
62  const wordList& valueSets
63 ) const
64 {
65  fileName fName(points.name());
66 
67  forAll(valueSets, i)
68  {
69  fName += '_' + valueSets[i];
70  }
71 
72  return fName;
73 }
74 
75 
76 template<class Type>
78 (
79  const coordSet& points,
80  const label pointi,
81  Ostream& os
82 ) const
83 {
84  if (points.hasVectorAxis())
85  {
86  write(points.vectorCoord(pointi), os);
87  }
88  else
89  {
90  write(points.scalarCoord(pointi), os);
91  }
92 }
93 
94 
95 template<class Type>
97 (
98  const coordSet& points,
99  const List<Type>& values,
100  Ostream& os
101 ) const
102 {
103  forAll(points, pointi)
104  {
105  writeCoord(points, pointi, os);
106  writeSeparator(os);
107  write(values[pointi], os);
108  os << nl;
109  }
110 }
111 
112 
113 template<class Type>
115 (
116  const coordSet& points,
117  const List<const List<Type>*>& valuesPtrList,
118  Ostream& os
119 ) const
120 {
121  forAll(points, pointi)
122  {
123  writeCoord(points, pointi, os);
124 
125  forAll(valuesPtrList, i)
126  {
127  writeSeparator(os);
128 
129  const List<Type>& values = *valuesPtrList[i];
130  write(values[pointi], os);
131  }
132  os << nl;
133  }
134 }
135 
136 
137 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
138 
139 template<class Type>
141 {}
142 
143 
144 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
145 
146 template<class Type>
148 {}
149 
150 
151 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
152 
153 template<class Type>
155 (
156  const coordSet& points,
157  const wordList& valueSetNames,
158  const List<Field<Type>>& valueSets,
159  Ostream& os
160 ) const
161 {
162  List<const Field<Type>*> valueSetPtrs(valueSets.size());
163  forAll(valueSetPtrs, i)
164  {
165  valueSetPtrs[i] = &valueSets[i];
166  }
167  write(points, valueSetNames, valueSetPtrs, os);
168 }
169 
170 
171 template<class Type>
173 (
174  const scalar value,
175  Ostream& os
176 ) const
177 {
178  return os << value;
179 }
180 
181 
182 template<class Type>
183 template<class VSType>
185 (
186  const VSType& value,
187  Ostream& os
188 ) const
189 {
190  for (direction d=0; d<VSType::nComponents; d++)
191  {
192  if (d > 0)
193  {
194  writeSeparator(os);
195  }
196 
197  os << value.component(d);
198  }
199  return os;
200 }
201 
202 
203 template<class Type>
205 (
206  Ostream& os
207 ) const
208 {
209  os << token::SPACE << token::TAB;
210 }
211 
212 
213 template<class Type>
215 (
216  const vector& value,
217  Ostream& os
218 ) const
219 {
220  return writeVS(value, os);
221 }
222 
223 
224 template<class Type>
226 (
227  const sphericalTensor& value,
228  Ostream& os
229 ) const
230 {
231  return writeVS(value, os);
232 }
233 
234 
235 template<class Type>
237 (
238  const symmTensor& value,
239  Ostream& os
240 ) const
241 {
242  return writeVS(value, os);
243 }
244 
245 
246 template<class Type>
248 (
249  const tensor& value,
250  Ostream& os
251 ) const
252 {
253  return writeVS(value, os);
254 }
255 
256 
257 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
uint8_t direction
Definition: direction.H:45
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
bool hasVectorAxis() const
Is axis specification a vector.
Definition: coordSet.C:84
virtual void write(const coordSet &, const wordList &, const List< const Field< Type > *> &, Ostream &) const =0
General entry point for writing.
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.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
writer()
Construct null.
Definition: writer.C:140
virtual ~writer()=0
Destructor.
Definition: writer.C:147
Holds list of sampling positions.
Definition: coordSet.H:49
vector vectorCoord(const label index) const
Get point according to axis="xyz" specification.
Definition: coordSet.C:126
Pre-declare SubField and related Field type.
Definition: Field.H:56
A class for handling words, derived from string.
Definition: word.H:59
void write(std::ostream &os, const bool binary, List< floatScalar > &fField)
Write floats ascii or binary.
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
static const char nl
Definition: Ostream.H:260
const word & name() const
Definition: coordSet.H:111
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
scalar scalarCoord(const label index) const
Get coordinate of point according to axis specification.
Definition: coordSet.C:91
void writeCoord(const coordSet &, const label sampleI, Ostream &) const
Definition: writer.C:78