ensightSetWriter.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-2015 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 "ensightSetWriter.H"
27 #include "coordSet.H"
28 #include "OFstream.H"
30 #include "IOmanip.H"
31 #include "foamVersion.H"
32 #include "ensightPTraits.H"
33 
34 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
35 
36 template<class Type>
38 :
39  writer<Type>()
40 {}
41 
42 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
43 
44 template<class Type>
46 {}
47 
48 
49 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
50 
51 template<class Type>
53 (
54  const coordSet& points,
55  const wordList& valueSetNames
56 ) const
57 {
58  return
59  this->getBaseName(points, valueSetNames)
60  //+ '_'
61  //+ ensightPTraits<Type>::typeName
62  + ".case";
63 }
64 
65 
66 template<class Type>
68 (
69  const coordSet& points,
70  const wordList& valueSetNames,
71  const List<const Field<Type>*>& valueSets,
72  Ostream& os
73 ) const
74 {
75  const fileName base(os.name().lessExt());
76  const fileName meshFile(base + ".mesh");
77 
78  // Write .case file
79  os << "FORMAT" << nl
80  << "type: ensight gold" << nl
81  << nl
82  << "GEOMETRY" << nl
83  << "model: 1 " << meshFile.name().c_str() << nl
84  << nl
85  << "VARIABLE"
86  << nl;
87  forAll(valueSetNames, setI)
88  {
89  fileName dataFile(base + ".***." + valueSetNames[setI]);
90 
91  os.setf(ios_base::left);
92  os << ensightPTraits<Type>::typeName
93  << " per node: 1 "
94  << setw(15) << valueSetNames[setI]
95  << " " << dataFile.name().c_str()
96  << nl;
97  }
98  os << nl
99  << "TIME" << nl
100  << "time set: 1" << nl
101  << "number of steps: 1" << nl
102  << "filename start number: 0" << nl
103  << "filename increment: 1" << nl
104  << "time values:" << nl
105  << "0.00000e+00" << nl;
106 
107  // Write .mesh file
108  {
109  string desc = string("written by OpenFOAM-") + Foam::FOAMversion;
110  OFstream os(meshFile);
111  os.setf(ios_base::scientific, ios_base::floatfield);
112  os.precision(5);
113 
114  os << "EnSight Geometry File" << nl
115  << desc.c_str() << nl
116  << "node id assign" << nl
117  << "element id assign" << nl
118  << "part" << nl
119  << setw(10) << 1 << nl
120  << "internalMesh" << nl
121  << "coordinates" << nl
122  << setw(10) << points.size() << nl;
123 
124  for (direction cmpt = 0; cmpt < vector::nComponents; cmpt++)
125  {
126  forAll(points, pointI)
127  {
128  const scalar comp = points[pointI][cmpt];
129  if (mag(comp) >= scalar(floatScalarVSMALL))
130  {
131  os << setw(12) << comp << nl;
132  }
133  else
134  {
135  os << setw(12) << scalar(0) << nl;
136  }
137  }
138  }
139  os << "point" << nl
140  << setw(10) << points.size() << nl;
141  forAll(points, pointI)
142  {
143  os << setw(10) << pointI+1 << nl;
144  }
145  }
146 
147  // Write data files
148  forAll(valueSetNames, setI)
149  {
150  fileName dataFile(base + ".000." + valueSetNames[setI]);
151  OFstream os(dataFile);
152  os.setf(ios_base::scientific, ios_base::floatfield);
153  os.precision(5);
154  {
155  os << ensightPTraits<Type>::typeName << nl
156  << "part" << nl
157  << setw(10) << 1 << nl
158  << "coordinates" << nl;
159 
160  for (direction i=0; i < pTraits<Type>::nComponents; ++i)
161  {
163 
164  const scalarField fld(valueSets[setI]->component(cmpt));
165  forAll(fld, i)
166  {
167  if (mag(fld[i]) >= scalar(floatScalarVSMALL))
168  {
169  os << setw(12) << fld[i] << nl;
170  }
171  else
172  {
173  os << setw(12) << scalar(0) << nl;
174  }
175  }
176  }
177  }
178  }
179 }
180 
181 
182 template<class Type>
184 (
185  const bool writeTracks,
186  const PtrList<coordSet>& tracks,
187  const wordList& valueSetNames,
188  const List<List<Field<Type> > >& valueSets,
189  Ostream& os
190 ) const
191 {
192  const fileName base(os.name().lessExt());
193  const fileName meshFile(base + ".mesh");
194 
195  // Write .case file
196  os << "FORMAT" << nl
197  << "type: ensight gold" << nl
198  << nl
199  << "GEOMETRY" << nl
200  << "model: 1 " << meshFile.name().c_str() << nl
201  << nl
202  << "VARIABLE"
203  << nl;
204  forAll(valueSetNames, setI)
205  {
206  fileName dataFile(base + ".***." + valueSetNames[setI]);
207 
208  os.setf(ios_base::left);
209  os << ensightPTraits<Type>::typeName
210  << " per node: 1 "
211  << setw(15) << valueSetNames[setI]
212  << " " << dataFile.name().c_str()
213  << nl;
214  }
215  os << nl
216  << "TIME" << nl
217  << "time set: 1" << nl
218  << "number of steps: 1" << nl
219  << "filename start number: 0" << nl
220  << "filename increment: 1" << nl
221  << "time values:" << nl
222  << "0.00000e+00" << nl;
223 
224  // Write .mesh file
225  {
226  string desc = string("written by OpenFOAM-") + Foam::FOAMversion;
227  OFstream os(meshFile);
228  os.setf(ios_base::scientific, ios_base::floatfield);
229  os.precision(5);
230  os << "EnSight Geometry File" << nl
231  << desc.c_str() << nl
232  << "node id assign" << nl
233  << "element id assign" << nl;
234 
235  forAll(tracks, trackI)
236  {
237  const coordSet& points = tracks[trackI];
238 
239  os << "part" << nl
240  << setw(10) << trackI+1 << nl
241  << "internalMesh" << nl
242  << "coordinates" << nl
243  << setw(10) << points.size() << nl;
244 
245  for (direction cmpt = 0; cmpt < vector::nComponents; cmpt++)
246  {
247  forAll(points, pointI)
248  {
249  const scalar comp = points[pointI][cmpt];
250  if (mag(comp) >= scalar(floatScalarVSMALL))
251  {
252  os << setw(12) << comp << nl;
253  }
254  else
255  {
256  os << setw(12) << scalar(0) << nl;
257  }
258  }
259  }
260 
261  if (writeTracks)
262  {
263  os << "bar2" << nl
264  << setw(10) << points.size()-1 << nl;
265  for (label i = 0; i < points.size()-1; i++)
266  {
267  os << setw(10) << i+1
268  << setw(10) << i+2
269  << nl;
270  }
271  }
272  }
273  }
274 
275 
276  // Write data files
277  forAll(valueSetNames, setI)
278  {
279  fileName dataFile(base + ".000." + valueSetNames[setI]);
280  OFstream os(dataFile);
281  os.setf(ios_base::scientific, ios_base::floatfield);
282  os.precision(5);
283  {
284  os << ensightPTraits<Type>::typeName << nl;
285 
286  const List<Field<Type> >& fieldVals = valueSets[setI];
287  forAll(fieldVals, trackI)
288  {
289  os << "part" << nl
290  << setw(10) << trackI+1 << nl
291  << "coordinates" << nl;
292 
293  for (direction i=0; i < pTraits<Type>::nComponents; ++i)
294  {
296 
297  const scalarField fld(fieldVals[trackI].component(cmpt));
298  forAll(fld, i)
299  {
300  if (mag(fld[i]) >= scalar(floatScalarVSMALL))
301  {
302  os << setw(12) << fld[i] << nl;
303  }
304  else
305  {
306  os << setw(12) << scalar(0) << nl;
307  }
308  }
309  }
310  }
311  }
312  }
313 }
314 
315 
316 // ************************************************************************* //
Foam::component
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
Definition: FieldFieldFunctions.C:41
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
coordSet.H
Foam::floatScalarVSMALL
static const floatScalar floatScalarVSMALL
Definition: floatScalar.H:59
Foam::VectorSpace< Vector< scalar >, scalar, 3 >::nComponents
@ nComponents
Number of components in this vector space.
Definition: VectorSpace.H:88
Foam::ensightSetWriter::getFileName
virtual fileName getFileName(const coordSet &, const wordList &) const
Generate file name with correct extension.
Definition: ensightSetWriter.C:53
Foam::fileName::lessExt
fileName lessExt() const
Return file name without extension (part before last .)
Definition: fileName.C:313
Foam::string
A class for handling character strings derived from std::string.
Definition: string.H:74
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
Foam::fileName::name
word name() const
Return file name (part beyond last /)
Definition: fileName.C:212
OFstream.H
Foam::ensightSetWriter::ensightSetWriter
ensightSetWriter()
Construct null.
Definition: ensightSetWriter.C:37
Foam::ensightPTraits
Conversion of OpenFOAM pTraits into the Ensight equivalent.
Definition: ensightPTraits.H:48
Foam::label
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
Foam::Field< Type >
Foam::nl
static const char nl
Definition: Ostream.H:260
ensightPTraits.H
IOmanip.H
Istream and Ostream manipulators taking arguments.
Foam::PtrList
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:61
ensightSetWriter.H
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
fld
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< ' ';}gmvFile<< nl;forAll(lagrangianScalarNames, i){ const word &name=lagrangianScalarNames[i];IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Foam::writer
Base class for graphics format writing. Entry points are.
Definition: writer.H:78
Foam::coordSet
Holds list of sampling positions.
Definition: coordSet.H:49
Foam::setw
Omanip< int > setw(const int i)
Definition: IOmanip.H:199
Foam::scientific
IOstream & scientific(IOstream &io)
Definition: IOstream.H:582
Foam::OFstream
Output to file stream.
Definition: OFstream.H:81
Foam::IOstream::setf
ios_base::fmtflags setf(const ios_base::fmtflags f)
Set flags of stream.
Definition: IOstream.H:496
Foam::OSstream::precision
virtual int precision() const
Get precision of output field.
Definition: OSstream.C:290
Foam::ensightSetWriter::~ensightSetWriter
virtual ~ensightSetWriter()
Destructor.
Definition: ensightSetWriter.C:45
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::direction
unsigned char direction
Definition: direction.H:43
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::ensightSetWriter::write
virtual void write(const coordSet &, const wordList &, const List< const Field< Type > * > &, Ostream &) const
General entry point for writing.
Definition: ensightSetWriter.C:68
Foam::FOAMversion
const char *const FOAMversion
Foam::IOstream::name
virtual const fileName & name() const
Return the name of the stream.
Definition: IOstream.H:297
foamVersion.H