mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
- Default is a width of 8 characters, but this can be extended up to 31
characters via the '-width' command-line option.
- Now use a similar structure as foamToEnsightParts for the masking.
This reduces the clutter within the directory, makes it easier to
selectively delete some time steps (using shell commands).
- Added in a "time" information data in each sub-directory to
make it possible to reconstruct the case file with an external
script.
- Conversion of cloud data should now also work in parallel
(may need more testing).
- Support binary output for cloud data.
- Better avoidance of illegal ensight variable names.
But still partially incomplete (due to patch fields).
==================================================
Example of NEW file structure:
EnSight/verticalChannel.case # case name
EnSight/geometry # for non-moving geometry
EnSight/data/ # time-varying data
EnSight/data/00000000/
EnSight/data/00000001/
...
Fields are stored by name within the data/********/ directories:
EnSight/data/00000001/time # human-readable time info
EnSight/data/00000001/U
EnSight/data/00000001/p
...
EnSight/data/00000001/geometry # for moving geometry
Clouds are stored at the next sub-directory level:
EnSight/data/00000001/lagrangian/<cloudName>/positions
EnSight/data/00000001/lagrangian/<cloudName>/U
...
==================================================
The old structure was significantly more cluttered:
EnSight/verticalChannel.case
EnSight/verticalChannel.0000.mesh
EnSight/verticalChannel.0001.p
EnSight/verticalChannel.0001.<cloudName>
EnSight/verticalChannel.0001.<cloudName>.U
==================================================
181 lines
5.2 KiB
C
181 lines
5.2 KiB
C
/*---------------------------------------------------------------------------*\
|
|
========= |
|
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
|
\\ / O peration |
|
|
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
|
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
|
-------------------------------------------------------------------------------
|
|
License
|
|
This file is part of OpenFOAM.
|
|
|
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
|
under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
\*---------------------------------------------------------------------------*/
|
|
|
|
#include "ensightCloud.H"
|
|
#include "ensightFile.H"
|
|
#include "fvMesh.H"
|
|
#include "passiveParticle.H"
|
|
#include "Cloud.H"
|
|
#include "pointList.H"
|
|
|
|
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
|
|
|
|
void Foam::ensightParticlePositions
|
|
(
|
|
const fvMesh& mesh,
|
|
const fileName& dataDir,
|
|
const label timeIndex,
|
|
const word& cloudName,
|
|
const bool dataExists,
|
|
IOstream::streamFormat format
|
|
)
|
|
{
|
|
if (dataExists)
|
|
{
|
|
Info<< " positions";
|
|
}
|
|
else
|
|
{
|
|
Info<< " positions{0}";
|
|
}
|
|
|
|
// Total number of parcels on all processes
|
|
label nTotParcels = 0;
|
|
autoPtr<Cloud<passiveParticle>> cloudPtr;
|
|
|
|
if (dataExists)
|
|
{
|
|
cloudPtr.reset(new Cloud<passiveParticle>(mesh, cloudName, false));
|
|
nTotParcels = cloudPtr().size();
|
|
}
|
|
reduce(nTotParcels, sumOp<label>());
|
|
|
|
if (Pstream::master())
|
|
{
|
|
const fileName postFileName =
|
|
ensightFile::subDir(timeIndex)/cloud::prefix/cloudName/"positions";
|
|
|
|
// the ITER/lagrangian subdirectory must exist
|
|
mkDir(dataDir/postFileName.path());
|
|
|
|
ensightFile os(dataDir, postFileName, format);
|
|
|
|
// tag binary format (just like geometry files)
|
|
os.writeBinaryHeader();
|
|
os.write(postFileName); // description
|
|
os.newline();
|
|
os.write("particle coordinates");
|
|
os.newline();
|
|
os.write(nTotParcels, 8); // unusual width
|
|
os.newline();
|
|
|
|
if (!nTotParcels)
|
|
{
|
|
return; // DONE
|
|
}
|
|
|
|
if (format == IOstream::BINARY)
|
|
{
|
|
// binary write is Ensight6 - first ids, then positions
|
|
|
|
// 1-index
|
|
for (label parcelId = 0; parcelId < nTotParcels; ++parcelId)
|
|
{
|
|
os.write(parcelId+1);
|
|
}
|
|
|
|
// Master
|
|
forAllConstIter(Cloud<passiveParticle>, cloudPtr(), elmnt)
|
|
{
|
|
const point& p = elmnt().position();
|
|
|
|
os.write(p.x());
|
|
os.write(p.y());
|
|
os.write(p.z());
|
|
}
|
|
|
|
// Slaves
|
|
for (int slave=1; slave<Pstream::nProcs(); ++slave)
|
|
{
|
|
IPstream fromSlave(Pstream::scheduled, slave);
|
|
pointList points(fromSlave);
|
|
|
|
forAll(points, pti)
|
|
{
|
|
const point& p = points[pti];
|
|
|
|
os.write(p.x());
|
|
os.write(p.y());
|
|
os.write(p.z());
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// ASCII id + position together
|
|
|
|
label parcelId = 0;
|
|
forAllConstIter(Cloud<passiveParticle>, cloudPtr(), elmnt)
|
|
{
|
|
const point& p = elmnt().position();
|
|
|
|
os.write(++parcelId, 8); // unusual width
|
|
os.write(p.x());
|
|
os.write(p.y());
|
|
os.write(p.z());
|
|
os.newline();
|
|
}
|
|
|
|
// Slaves
|
|
for (int slave=1; slave<Pstream::nProcs(); ++slave)
|
|
{
|
|
IPstream fromSlave(Pstream::scheduled, slave);
|
|
pointList points(fromSlave);
|
|
|
|
forAll(points, pti)
|
|
{
|
|
const point& p = points[pti];
|
|
|
|
os.write(++parcelId, 8); // unusual width
|
|
os.write(p.x());
|
|
os.write(p.y());
|
|
os.write(p.z());
|
|
os.newline();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else if (nTotParcels)
|
|
{
|
|
// SLAVE, and data exist
|
|
pointList points(cloudPtr().size());
|
|
|
|
label pti = 0;
|
|
forAllConstIter(Cloud<passiveParticle>, cloudPtr(), elmnt)
|
|
{
|
|
const point& p = elmnt().position();
|
|
points[pti++] = p;
|
|
}
|
|
|
|
{
|
|
OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
|
|
toMaster<< points;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
// ************************************************************************* //
|