Commit 82f9089b authored by Andrew Heather's avatar Andrew Heather
Browse files

Merge branch 'develop' of develop.openfoam.com:Development/OpenFOAM-plus into develop

parents e3420b8a f0107b47
ensightMesh.C
ensightCloud.C
ensightOutputCloud.C
meshSubsetHelper.C
foamToEnsight.C
EXE = $(FOAM_APPBIN)/foamToEnsight
......@@ -3,14 +3,12 @@ EXE_INC = \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/dynamicMesh/lnInclude \
-I$(LIB_SRC)/fileFormats/lnInclude \
-I$(LIB_SRC)/sampling/lnInclude \
-I$(LIB_SRC)/lagrangian/basic/lnInclude \
-I$(LIB_SRC)/conversion/lnInclude
EXE_LIBS = \
-ldynamicMesh \
-lfileFormats \
-lsampling \
-lgenericPatchFields \
-llagrangian \
-lconversion
......@@ -38,8 +38,7 @@ if (timeDirs.size() > 1 && Pstream::master())
if (meshMoving)
{
Info<< "found." << nl
<< " Writing meshes for every timestep." << endl;
Info<< "found. Writing meshes for every timestep." << endl;
}
else
{
......
if (Pstream::master())
{
ensightCaseFile.setf(ios_base::scientific, ios_base::floatfield);
ensightCaseFile.precision(5);
ensightCaseFile << nl << "TIME" << nl
<< "time set: " << 1 << nl
<< "number of steps: " << nTimeSteps << nl
<< "filename start number: " << 0 << nl
<< "filename increment: " << 1 << nl;
ensightCaseFile << "time values:" << nl;
label count = 0;
scalar Tcorr = 0.0;
if (timeDirs[0].value() < 0)
{
Tcorr = -timeDirs[0].value();
Info<< "Correcting time values. Adding " << Tcorr << endl;
}
forAll(timeDirs, n)
{
ensightCaseFile << setw(12) << timeDirs[n].value() + Tcorr << " ";
if (++count % 6 == 0)
{
ensightCaseFile << nl;
}
}
ensightCaseFile << nl;
}
......@@ -23,8 +23,8 @@ License
\*---------------------------------------------------------------------------*/
#include "ensightCloud.H"
#include "ensightFile.H"
#include "ensightOutputCloud.H"
#include "fvMesh.H"
#include "passiveParticle.H"
#include "Cloud.H"
......@@ -32,30 +32,19 @@ License
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
void Foam::ensightParticlePositions
void Foam::ensightCloud::writePositions
(
const fvMesh& mesh,
const fileName& dataDir,
const label timeIndex,
const word& cloudName,
const bool dataExists,
IOstream::streamFormat format
const bool exists,
autoPtr<ensightFile>& output
)
{
if (dataExists)
{
Info<< " positions";
}
else
{
Info<< " positions{0}";
}
// Total number of parcels on all processes
label nTotParcels = 0;
autoPtr<Cloud<passiveParticle>> cloudPtr;
if (dataExists)
if (exists)
{
cloudPtr.reset(new Cloud<passiveParticle>(mesh, cloudName, false));
nTotParcels = cloudPtr().size();
......@@ -64,29 +53,15 @@ void Foam::ensightParticlePositions
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();
ensightFile& os = output();
os.beginParticleCoordinates(nTotParcels);
if (!nTotParcels)
{
return; // DONE
}
if (format == IOstream::BINARY)
if (os.format() == IOstream::BINARY)
{
// binary write is Ensight6 - first ids, then positions
......@@ -131,7 +106,7 @@ void Foam::ensightParticlePositions
{
const point& p = elmnt().position();
os.write(++parcelId, 8); // unusual width
os.write(++parcelId, 8); // unusual width
os.write(p.x());
os.write(p.y());
os.write(p.z());
......@@ -148,7 +123,7 @@ void Foam::ensightParticlePositions
{
const point& p = points[pti];
os.write(++parcelId, 8); // unusual width
os.write(++parcelId, 8); // unusual width
os.write(p.x());
os.write(p.y());
os.write(p.z());
......@@ -171,10 +146,11 @@ void Foam::ensightParticlePositions
{
OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
toMaster<< points;
toMaster
<< points;
}
}
}
// ************************************************************************* //
......@@ -2,8 +2,8 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -21,78 +21,73 @@ License
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Namespace
ensightOutput
Description
Miscellaneous collection of functions and template related to Ensight data
A collection of global functions for writing ensight file content.
SourceFiles
ensightOutputFunctions.C
ensightOutputCloud.C
ensightOutputCloudTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef ensightOutputFunctions_H
#define ensightOutputFunctions_H
#ifndef ensightOutputCloud_H
#define ensightOutputCloud_H
#include "ensightFile.H"
#include "Cloud.H"
#include "polyMesh.H"
#include "IOobject.H"
#include "ensightMesh.H"
namespace Foam
{
#include "autoPtr.H"
#include "IOField.H"
#include "volFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void ensightCaseEntry
(
OFstream& caseFile,
const string& ensightType,
const word& fieldName,
const fileName& dataMask,
const fileName& local=fileName::null,
const label cloudNo=-1,
const label timeSet=1
);
namespace Foam
{
namespace ensightCloud
{
void ensightParticlePositions
//- Write cloud positions
void writePositions
(
const polyMesh& mesh,
const fileName& dataDir,
const fileName& subDir,
const fvMesh& mesh,
const word& cloudName,
IOstream::streamFormat format
const bool exists,
autoPtr<ensightFile>& output
);
//- Write lagrangian parcels
//- Write cloud field, returning true if the field is non-empty.
template<class Type>
void ensightLagrangianField
bool writeCloudField
(
const IOobject& fieldObject,
const fileName& dataDir,
const fileName& subDir,
const word& cloudName,
IOstream::streamFormat format
const IOField<Type>& field,
ensightFile& os
);
//- Write generalized field components
//- Write cloud field from IOobject, always returning true.
template<class Type>
void ensightVolField
bool writeCloudField
(
const ensightParts& partsList,
const IOobject& fieldObject,
const fvMesh& mesh,
const fileName& dataDir,
const fileName& subDir,
IOstream::streamFormat format
const bool exists,
autoPtr<ensightFile>& output
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // namespace ensightCloud
} // namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "ensightOutputFunctions.C"
#include "ensightOutputCloudTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -23,24 +23,26 @@ License
\*---------------------------------------------------------------------------*/
#include "ensightCloud.H"
#include "ensightFile.H"
#include "Time.H"
#include "IOField.H"
#include "OFstream.H"
#include "IOmanip.H"
#include "ensightOutputCloud.H"
#include "ensightPTraits.H"
#include "IOField.H"
#include "Time.H"
#include "globalIndex.H"
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::writeCloudField
bool Foam::ensightCloud::writeCloudField
(
const Foam::IOField<Type>& field,
Foam::ensightFile& os
)
{
if (returnReduce(field.size(), sumOp<label>()) > 0)
const bool exists = (returnReduce(field.size(), sumOp<label>()) > 0);
if (exists)
{
if (Pstream::master())
{
......@@ -106,86 +108,30 @@ void Foam::writeCloudField
else
{
OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
toMaster<< field;
toMaster
<< field;
}
}
return exists;
}
template<class Type>
void Foam::ensightCloudField
bool Foam::ensightCloud::writeCloudField
(
const Foam::IOobject& fieldObject,
const Foam::fileName& dataDir,
const Foam::label timeIndex,
const Foam::word& cloudName,
const Foam::label cloudNo,
Foam::Ostream& ensightCaseFile,
const bool dataExists,
Foam::IOstream::streamFormat format
const bool exists,
Foam::autoPtr<Foam::ensightFile>& output
)
{
const ensight::VarName varName(fieldObject.name());
if (dataExists)
{
Info<< ' ' << fieldObject.name();
}
else
{
Info<< ' ' << fieldObject.name() << "{0}"; // ie, empty field
}
ensightFile* filePtr(nullptr);
if (Pstream::master())
{
const fileName postFileName =
ensightFile::subDir(timeIndex)/cloud::prefix/cloudName/varName;
// the ITER/lagrangian subdirectory must exist
// the ITER/lagrangian subdirectory was already created
// when writing positions
mkDir(dataDir/postFileName.path());
if (timeIndex == 0)
{
const fileName dirName =
dataDir.name()/ensightFile::mask()/cloud::prefix/cloudName;
ensightCaseFile.setf(ios_base::left);
// prefix variables with 'c' (cloud)
ensightCaseFile
<< ensightPTraits<Type>::typeName << " per "
<< setw(20)
<< "measured node:"
<< " 1 "
<< setw(15)
<< ("c" + Foam::name(cloudNo) + varName).c_str() << ' '
<< (dirName/varName).c_str()
<< nl;
}
filePtr = new ensightFile(dataDir, postFileName, format);
// description
filePtr->write
(
string(postFileName + " <" + pTraits<Type>::typeName + ">")
);
filePtr->newline();
}
if (dataExists)
if (exists)
{
IOField<Type> field(fieldObject);
writeCloudField(field, *filePtr);
writeCloudField(field, output.rawRef());
}
if (filePtr) // on master only
{
delete filePtr;
}
return true;
}
......
......@@ -50,7 +50,7 @@ if (timeDirs.size() && !noLagrangian)
forAllConstIter(IOobjectList, cloudObjs, fieldIter)
{
const IOobject obj = *fieldIter();
const IOobject& obj = *fieldIter();
// Add field and field type
cloudIter().insert
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
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 "meshSubsetHelper.H"
#include "cellSet.H"
#include "cellZone.H"
#include "Time.H"
#include "IOstreams.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::meshSubsetHelper::meshSubsetHelper
(
fvMesh& baseMesh,
const word& name,
const bool isCellSet
)
:
baseMesh_(baseMesh),
subsetter_(baseMesh),
name_(name),
type_(name_.empty() ? 0 : isCellSet ? 1 : 2)
{
correct();
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::meshSubsetHelper::correct(bool verbose)
{
if (type_ == 1)
{
if (verbose)
{
Info<< "Subsetting mesh based on cellSet " << name_ << endl;
}
cellSet subset(baseMesh_, name_);
subsetter_.setLargeCellSubset(subset);
}
else if (type_ == 2)
{
if (verbose)
{
Info<< "Subsetting mesh based on cellZone " << name_ << endl;
}
labelHashSet subset(baseMesh_.cellZones()[name_]);
subsetter_.setLargeCellSubset(subset, 0);
}
}
Foam::polyMesh::readUpdateState Foam::meshSubsetHelper::readUpdate()
{
polyMesh::readUpdateState meshState = baseMesh_.readUpdate();
if (meshState != polyMesh::UNCHANGED)
{
correct(true);
}
return meshState;
}
// ************************************************************************* //
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
......@@ -22,46 +22,60 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::ensightBinaryStream
Foam::meshSubsetHelper
Description
Simple helper to hold a mesh or mesh-subset and provide uniform access.
SourceFiles
ensightBinaryStream.C
meshSubsetHelper.C
meshSubsetHelperTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef ensightBinaryStream_H
#define ensightBinaryStream_H
#ifndef meshSubsetHelper_H
#define meshSubsetHelper_H
#include "fvMeshSubset.H"
#include "zeroGradientFvPatchField.H"
#include "ensightStream.H"