ensightCloudField.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 "ensightCloudField.H"
27 #include "Time.H"
28 #include "IOField.H"
29 #include "OFstream.H"
30 #include "IOmanip.H"
31 
32 using namespace Foam;
33 
34 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
35 
36 template<class Type>
38 (
39  const IOobject& fieldObject,
40  const fileName& postProcPath,
41  const word& prepend,
42  const label timeIndex,
43  const word& cloudName,
44  Ostream& ensightCaseFile,
45  const bool dataExists
46 )
47 {
48  if (dataExists)
49  {
50  Info<< "Converting cloud " << cloudName
51  << " field " << fieldObject.name() << endl;
52  }
53  else
54  {
55  Info<< "Creating empty cloud " << cloudName
56  << " field " << fieldObject.name() << endl;
57  }
58 
59  word timeFile = prepend + itoa(timeIndex);
60 
61  const Time& runTime = fieldObject.time();
62 
63  if (timeIndex == 0 && Pstream::master())
64  {
65  ensightCaseFile
66  << pTraits<Type>::typeName << " per measured node: 1 ";
67  ensightCaseFile.width(15);
68  ensightCaseFile.setf(ios_base::left);
69  ensightCaseFile
70  << ("c" + fieldObject.name()).c_str()
71  << (' ' + prepend + "****." + cloudName
72  + "." + fieldObject.name()).c_str()
73  << nl;
74  }
75 
76  fileName ensightFileName
77  (
78  timeFile + "." + cloudName +"." + fieldObject.name()
79  );
80 
82  (
83  postProcPath/ensightFileName,
84  runTime.writeFormat(),
85  runTime.writeVersion(),
86  runTime.writeCompression()
87  );
88 
90 
91  if (dataExists)
92  {
93  IOField<Type> vf(fieldObject);
94 
95  ensightFile.setf(ios_base::scientific, ios_base::floatfield);
97 
98  label count = 0;
99  forAll(vf, i)
100  {
101  Type v = vf[i];
102 
103  if (mag(v) < 1.0e-90)
104  {
105  v = Zero;
106  }
107 
108  for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
109  {
110  ensightFile << setw(12) << component(v, cmpt);
111  if (++count % 6 == 0)
112  {
113  ensightFile << nl;
114  }
115  }
116  }
117 
118  if ((count % 6 != 0) || (count==0))
119  {
120  ensightFile << nl;
121  }
122  }
123 }
124 
125 
126 // ************************************************************************* //
Ensight output with specialized write() for strings, integers and floats. Correctly handles binary wr...
Definition: ensightFile.H:47
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
const word & name() const
Return name.
Definition: IOobject.H:295
A class for handling file names.
Definition: fileName.H:79
virtual int precision() const
Get precision of output field.
Definition: OSstream.C:293
ios_base::fmtflags setf(const ios_base::fmtflags f)
Set flags of stream.
Definition: IOstream.H:496
word itoa(const label n)
Output to file stream.
Definition: OFstream.H:82
uint8_t direction
Definition: direction.H:45
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:423
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
IOstream::versionNumber writeVersion() const
Default write version number.
Definition: Time.H:294
A class for handling words, derived from string.
Definition: word.H:59
IOstream::compressionType writeCompression() const
Default write compression.
Definition: Time.H:300
static const zero Zero
Definition: zero.H:97
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
virtual int width() const =0
Get width of output field.
Istream and Ostream manipulators taking arguments.
static const char nl
Definition: Ostream.H:265
IOstream::streamFormat writeFormat() const
Default write format.
Definition: Time.H:288
const Time & time() const
Return time.
Definition: IOobject.C:360
messageStream Info
dimensioned< scalar > mag(const dimensioned< Type > &)
const doubleScalar e
Elementary charge.
Definition: doubleScalar.H:98
Omanip< int > setw(const int i)
Definition: IOmanip.H:199
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
A primitive field of type <T> with automated input and output.
Definition: IOField.H:50
void ensightCloudField(const IOobject &fieldObject, const fileName &postProcPath, const word &prepend, const label timeIndex, const word &timeFile, const word &cloudName, Ostream &ensightCaseFile, const bool dataExists)
IOstream & scientific(IOstream &io)
Definition: IOstream.H:582
Namespace for OpenFOAM.