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