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 | Copyright (C) 2011-2012 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  (
46  "writer::New(const word&)"
47  ) << "Unknown write type "
48  << writeType << nl << nl
49  << "Valid write types : " << endl
50  << wordConstructorTablePtr_->sortedToc()
51  << exit(FatalError);
52  }
53 
54  return autoPtr<writer<Type> >(cstrIter()());
55 }
56 
57 
58 // * * * * * * * * * * * * * Private 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 // ************************************************************************* //
static autoPtr< writer > New(const word &writeFormat)
Return a reference to the selected writer.
Definition: writer.C:35
virtual ~writer()=0
Destructor.
Definition: writer.C:149
unsigned char direction
Definition: direction.H:43
virtual void write(const coordSet &, const wordList &, const List< const Field< Type > * > &, Ostream &) const =0
General entry point for writing.
Holds list of sampling positions.
Definition: coordSet.H:49
const word & name() const
Definition: coordSet.H:111
Templated 3D symmetric tensor derived from VectorSpace adding construction from 6 components...
Definition: SymmTensor.H:53
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
A class for handling words, derived from string.
Definition: word.H:59
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
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
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.
void writeCoord(const coordSet &, const label sampleI, Ostream &) const
Definition: writer.C:80
runTime write()
vector vectorCoord(const label index) const
Get point according to axis="xyz" specification.
Definition: coordSet.C:130
fileName getBaseName(const coordSet &, const wordList &) const
Generates filename from coordSet and sampled fields.
Definition: writer.C:62
static const char nl
Definition: Ostream.H:260
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
#define forAll(list, i)
Definition: UList.H:421
Pre-declare SubField and related Field type.
Definition: Field.H:57
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
Ostream & writeVS(const VSType &, Ostream &) const
writer()
Construct null.
Definition: writer.C:142
error FatalError
A class for handling file names.
Definition: fileName.H:69
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
bool hasVectorAxis() const
Is axis specification a vector.
Definition: coordSet.C:86
scalar scalarCoord(const label index) const
Get coordinate of point according to axis specification.
Definition: coordSet.C:93
void writeTable(const coordSet &, const List< Type > &, Ostream &) const
Writes single-column ascii write. Column 1 is coordSet coordinate,.
Definition: writer.C:99
virtual void writeSeparator(Ostream &os) const
Writes a separator. Used by write functions.
Definition: writer.C:207
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117