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