ensightParticlePositions.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 
27 #include "fvMesh.H"
28 #include "passiveParticle.H"
29 #include "Cloud.H"
30 #include "OFstream.H"
31 #include "IOmanip.H"
32 #include "itoa.H"
33 
34 using namespace Foam;
35 
36 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
37 
39 (
40  const fvMesh& mesh,
41  const fileName& postProcPath,
42  const word& timeFile,
43  const word& cloudName,
44  const bool dataExists
45 )
46 {
47  if (dataExists)
48  {
49  Info<< "Converting cloud " << cloudName << " positions" << endl;
50  }
51  else
52  {
53  Info<< "Creating empty cloud " << cloudName << " positions" << endl;
54  }
55 
56  const Time& runTime = mesh.time();
57 
58  fileName ensightFileName(timeFile + "." + cloudName);
60  (
61  postProcPath/ensightFileName,
62  runTime.writeFormat(),
63  runTime.writeVersion(),
64  runTime.writeCompression()
65  );
66 
67  // Output header
69  << cloudName.c_str() << nl
70  << "particle coordinates" << nl;
71 
72  if (dataExists)
73  {
74  Cloud<passiveParticle> parcels(mesh, cloudName, false);
75 
76  // Set Format
77  ensightFile.setf(ios_base::scientific, ios_base::floatfield);
79 
80  ensightFile<< setw(8) << parcels.size() << nl;
81 
82  label nParcels = 0;
83 
84  // Output positions
86  {
87  const vector& p = elmnt().position();
88 
90  << setw(8) << ++nParcels
91  << setw(12) << p.x() << setw(12) << p.y() << setw(12) << p.z()
92  << nl;
93  }
94  }
95  else
96  {
97  label nParcels = 0;
98  ensightFile<< setw(8) << nParcels << nl;
99  }
100 }
101 
102 
103 // ************************************************************************* //
Ensight output with specialized write() for strings, integers and floats. Correctly handles binary wr...
Definition: ensightFile.H:47
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
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
Output to file stream.
Definition: OFstream.H:82
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
void ensightParticlePositions(const polyMesh &mesh, const fileName &dataDir, const fileName &subDir, const word &cloudName, IOstream::streamFormat format)
const Cmpt & z() const
Definition: VectorI.H:87
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:239
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
const Cmpt & y() const
Definition: VectorI.H:81
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
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
const Cmpt & x() const
Definition: VectorI.H:75
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
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
messageStream Info
Omanip< int > setw(const int i)
Definition: IOmanip.H:199
IOstream & scientific(IOstream &io)
Definition: IOstream.H:582
Namespace for OpenFOAM.