ENH: cleanup ensightParts to use updated infrastructure (issue #241).

- Use ensightCase for case writing.
  Rebase ensightPartCells/ensightPartFaces on
  ensightCells/ensightFaces routines.

- Greatly reduces code duplication potential source of errors.
This commit is contained in:
Mark Olesen
2016-10-07 11:24:47 +02:00
parent 54da8848ba
commit 3915942195
23 changed files with 1181 additions and 2049 deletions

View File

@ -1,3 +1,4 @@
ensightOutputSerialCloud.C
foamToEnsightParts.C foamToEnsightParts.C
EXE = $(FOAM_APPBIN)/foamToEnsightParts EXE = $(FOAM_APPBIN)/foamToEnsightParts

View File

@ -1,7 +1,7 @@
// check for "points" in all of the result directories // check for "points" in all of the result directories
// - could restrict to the selected times // - could restrict to the selected times
bool hasMovingMesh = false; bool meshMoving = false;
if (timeDirs.size() > 1 && Pstream::master()) if (timeDirs.size() > 1 && Pstream::master())
{ {
@ -13,7 +13,7 @@ if (timeDirs.size() > 1 && Pstream::master())
Info<< "Search for moving mesh ... " << flush; Info<< "Search for moving mesh ... " << flush;
forAll(timeDirs, timeI) forAll(timeDirs, timeI)
{ {
hasMovingMesh = meshMoving =
( (
isDir(baseDir/timeDirs[timeI].name()/polyMesh::meshSubDir) isDir(baseDir/timeDirs[timeI].name()/polyMesh::meshSubDir)
&& IOobject && IOobject
@ -28,13 +28,13 @@ if (timeDirs.size() > 1 && Pstream::master())
).typeHeaderOk<pointIOField>(true) ).typeHeaderOk<pointIOField>(true)
); );
if (hasMovingMesh) if (meshMoving)
{ {
break; break;
} }
} }
if (hasMovingMesh) if (meshMoving)
{ {
Info<< "found." << nl Info<< "found." << nl
<< " Writing meshes for every timestep." << endl; << " Writing meshes for every timestep." << endl;
@ -45,4 +45,4 @@ if (timeDirs.size() > 1 && Pstream::master())
} }
} }
reduce(hasMovingMesh, orOp<bool>()); reduce(meshMoving, orOp<bool>());

View File

@ -1,270 +0,0 @@
// write time values to case file
scalar timeCorrection = 0;
if (timeDirs[0].value() < 0)
{
timeCorrection = - timeDirs[0].value();
Info<< "Correcting time values. Adding " << timeCorrection << endl;
}
// the case file is always ASCII
Info<< "write case: " << caseFileName.c_str() << endl;
OFstream caseFile(ensightDir/caseFileName, IOstream::ASCII);
caseFile.setf(ios_base::left);
caseFile.setf(ios_base::scientific, ios_base::floatfield);
caseFile.precision(5);
caseFile
<< "FORMAT" << nl
<< setw(16) << "type:" << "ensight gold" << nl << nl;
// time-set for geometries
// TODO: split off into separate time-set, but need to verify ensight spec
if (geometryTimesUsed.size())
{
caseFile
<< "GEOMETRY" << nl
<< setw(16) << "model: 1" << (dataMask/geometryName).c_str() << nl;
}
else
{
caseFile
<< "GEOMETRY" << nl
<< setw(16) << "model:" << geometryName << nl;
}
// add information for clouds
// multiple clouds currently require the same time index
forAllConstIter(HashTable<HashTable<word>>, cloudFields, cloudIter)
{
const word& cloudName = cloudIter.key();
caseFile
<< setw(16) << "measured: 2"
<< fileName(dataMask/cloud::prefix/cloudName/"positions").c_str()
<< nl;
}
caseFile
<< nl << "VARIABLE" << nl;
forAllConstIter(HashTable<word>, volumeFields, fieldIter)
{
const word& fieldName = fieldIter.key();
const word& fieldType = fieldIter();
string ensightType;
if (fieldType == volScalarField::typeName)
{
ensightType = ensightPTraits<scalar>::typeName;
}
else if (fieldType == volVectorField::typeName)
{
ensightType = ensightPTraits<vector>::typeName;
}
else if (fieldType == volSphericalTensorField::typeName)
{
ensightType = ensightPTraits<sphericalTensor>::typeName;
}
else if (fieldType == volSymmTensorField::typeName)
{
ensightType = ensightPTraits<symmTensor>::typeName;
}
else if (fieldType == volTensorField::typeName)
{
ensightType = ensightPTraits<tensor>::typeName;
}
else
{
continue;
}
ensightCaseEntry
(
caseFile,
ensightType,
fieldName,
dataMask
);
}
// TODO: allow similar/different time-steps for each cloud
label cloudNo = 0;
forAllConstIter(HashTable<HashTable<word>>, cloudFields, cloudIter)
{
const word& cloudName = cloudIter.key();
forAllConstIter(HashTable<word>, cloudIter(), fieldIter)
{
const word& fieldName = fieldIter.key();
const word& fieldType = fieldIter();
string ensightType;
if (fieldType == scalarIOField::typeName)
{
ensightType = ensightPTraits<scalar>::typeName;
}
else if (fieldType == vectorIOField::typeName)
{
ensightType = ensightPTraits<vector>::typeName;
}
else if (fieldType == tensorIOField::typeName)
{
ensightType = ensightPTraits<tensor>::typeName;
}
else
{
continue;
}
ensightCaseEntry
(
caseFile,
ensightType,
fieldName,
dataMask,
cloud::prefix/cloudName,
cloudNo,
2
);
}
cloudNo++;
}
// add time values
caseFile << nl << "TIME" << nl;
// time set 1 - volume fields
if (fieldTimesUsed.size())
{
caseFile
<< "time set: " << 1 << nl
<< "number of steps: " << fieldTimesUsed.size() << nl
<< "filename numbers:" << nl;
label count = 0;
forAll(fieldTimesUsed, i)
{
caseFile
<< " " << setw(12) << fieldTimesUsed[i];
if (++count % 6 == 0)
{
caseFile << nl;
}
}
caseFile
<< nl << "time values:" << nl;
count = 0;
forAll(fieldTimesUsed, i)
{
const label index = fieldTimesUsed[i];
caseFile
<< " " << setw(12) << timeIndices[index] + timeCorrection;
if (++count % 6 == 0)
{
caseFile << nl;
}
}
caseFile << nl << nl;
}
// time set 2 - geometry
// THIS NEEDS MORE CHECKING
#if 0
if (geometryTimesUsed.size())
{
caseFile
<< "time set: " << 2 << nl
<< "number of steps: " << geometryTimesUsed.size() << nl
<< "filename numbers:" << nl;
label count = 0;
forAll(geometryTimesUsed, i)
{
caseFile
<< " " << setw(12) << geometryTimesUsed[i];
if (++count % 6 == 0)
{
caseFile << nl;
}
}
caseFile
<< nl << "time values:" << nl;
count = 0;
forAll(geometryTimesUsed, i)
{
const label index = geometryTimesUsed[i];
caseFile
<< " " << setw(12) << timeIndices[index] + timeCorrection;
if (++count % 6 == 0)
{
caseFile << nl;
}
}
caseFile << nl << nl;
}
#endif
// time set - clouds
// TODO: allow similar/different time-steps for each cloud
cloudNo = 0;
forAllConstIter(HashTable<DynamicList<label>>, cloudTimesUsed, cloudIter)
{
// const word& cloudName = cloudIter.key();
const DynamicList<label>& timesUsed = cloudIter();
if (timesUsed.size() && cloudNo == 0)
{
caseFile
<< "time set: " << 2 << nl
<< "number of steps: " << timesUsed.size() << nl
<< "filename numbers:" << nl;
label count = 0;
forAll(timesUsed, i)
{
caseFile
<< " " << setw(12) << timesUsed[i];
if (++count % 6 == 0)
{
caseFile << nl;
}
}
caseFile
<< nl << "time values:" << nl;
count = 0;
forAll(timesUsed, i)
{
const label index = timesUsed[i];
caseFile
<< " " << setw(12) << timeIndices[index] + timeCorrection;
if (++count % 6 == 0)
{
caseFile << nl;
}
}
caseFile << nl << nl;
cloudNo++;
}
}
caseFile << "# end" << nl;

View File

@ -1,245 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 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 "ensightOutputFunctions.H"
#include "ensightPTraits.H"
#include "passiveParticle.H"
#include "IOField.H"
#include "volFields.H"
#include "surfaceFields.H"
#include "OFstream.H"
#include "IOmanip.H"
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
void Foam::ensightCaseEntry
(
OFstream& caseFile,
const string& ensightType,
const word& fieldName,
const fileName& dataMask,
const fileName& local,
const label cloudNo,
const label timeSet
)
{
const ensight::VarName varName(fieldName);
caseFile.setf(ios_base::left);
fileName dirName(dataMask);
if (local.size())
{
dirName = dirName/local;
}
if (cloudNo >= 0)
{
label ts = 1;
if (timeSet > ts)
{
ts = timeSet;
}
// prefix variables with 'c' (cloud)
caseFile
<< ensightType.c_str()
<< " per measured node: " << ts << " "
<< setw(15)
<< ("c" + Foam::name(cloudNo) + varName).c_str()
<< " "
<< (dirName/varName).c_str()
<< nl;
}
else
{
caseFile
<< ensightType.c_str()
<< " per element: "
<< setw(15) << varName
<< " "
<< (dirName/varName).c_str()
<< nl;
}
}
void Foam::ensightParticlePositions
(
const polyMesh& mesh,
const fileName& dataDir,
const fileName& subDir,
const word& cloudName,
IOstream::streamFormat format
)
{
Cloud<passiveParticle> parcels(mesh, cloudName, false);
const fileName postFileName =
subDir/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(parcels.size(), 8); // unusual width
os.newline();
// binary write is Ensight6 - first ids, then positions
if (format == IOstream::BINARY)
{
forAll(parcels, i)
{
os.write(i+1);
}
forAllConstIter(Cloud<passiveParticle>, parcels, elmnt)
{
const vector& p = elmnt().position();
os.write(p.x());
os.write(p.y());
os.write(p.z());
}
}
else
{
label nParcels = 0;
forAllConstIter(Cloud<passiveParticle>, parcels, elmnt)
{
const vector& p = elmnt().position();
os.write(++nParcels, 8); // unusual width
os.write(p.x());
os.write(p.y());
os.write(p.z());
os.newline();
}
}
}
template<class Type>
void Foam::ensightLagrangianField
(
const IOobject& fieldObject,
const fileName& dataDir,
const fileName& subDir,
const word& cloudName,
IOstream::streamFormat format
)
{
Info<< " " << fieldObject.name() << flush;
const fileName postFileName =
subDir/cloud::prefix/cloudName
/ensight::VarName(fieldObject.name());
// the ITER/lagrangian subdirectory was already created
// when writing positions
ensightFile os(dataDir, postFileName, format);
// description
os.write(string(postFileName + " <" + pTraits<Type>::typeName + ">"));
os.newline();
IOField<Type> field(fieldObject);
// 6 values per line
label count = 0;
forAll(field, i)
{
Type val = field[i];
if (mag(val) < 1e-90)
{
val = Zero;
}
for (direction d=0; d < pTraits<Type>::nComponents; ++d)
{
label cmpt = ensightPTraits<Type>::componentOrder[d];
os.write(component(val, cmpt));
if (++count % 6 == 0)
{
os.newline();
}
}
}
// add final newline if required
if (count % 6)
{
os.newline();
}
}
template<class Type>
void Foam::ensightVolField
(
const ensightParts& partsList,
const IOobject& fieldObject,
const fvMesh& mesh,
const fileName& dataDir,
const fileName& subDir,
IOstream::streamFormat format
)
{
Info<< " " << fieldObject.name() << flush;
const fileName postFileName = subDir/ensight::VarName(fieldObject.name());
ensightFile os(dataDir, postFileName, format);
os.write(postFileName); // description
os.newline();
// ie, volField<Type>
partsList.writeField
(
os,
GeometricField<Type, fvPatchField, volMesh>
(
fieldObject,
mesh
)
);
}
// ************************************************************************* //

View File

@ -0,0 +1,95 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 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 "ensightOutputSerialCloud.H"
#include "ensightPTraits.H"
#include "passiveParticle.H"
#include "IOField.H"
#include "volFields.H"
#include "surfaceFields.H"
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
void Foam::ensightSerialCloud::writePositions
(
const polyMesh& mesh,
const word& cloudName,
autoPtr<ensightFile> output
)
{
label nTotParcels = 0;
autoPtr<Cloud<passiveParticle>> cloudPtr;
cloudPtr.reset(new Cloud<passiveParticle>(mesh, cloudName, false));
nTotParcels = cloudPtr().size();
Cloud<passiveParticle> parcels(mesh, cloudName, false);
if (Pstream::master())
{
ensightFile& os = output();
os.beginParticleCoordinates(nTotParcels);
// binary write is Ensight6 - first ids, then positions
if (os.format() == IOstream::BINARY)
{
// 1-index
for (label parcelId = 0; parcelId < nTotParcels; ++parcelId)
{
os.write(parcelId+1);
}
forAllConstIter(Cloud<passiveParticle>, cloudPtr(), elmnt)
{
const vector& p = elmnt().position();
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 vector& p = elmnt().position();
os.write(++parcelId, 8); // unusual width
os.write(p.x());
os.write(p.y());
os.write(p.z());
os.newline();
}
}
}
}
// ************************************************************************* //

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -29,70 +29,57 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef ensightOutputFunctions_H #ifndef ensightOutputSerialCloud_H
#define ensightOutputFunctions_H #define ensightOutputSerialCloud_H
#include "ensightFile.H" #include "ensightFile.H"
#include "Cloud.H" #include "Cloud.H"
#include "polyMesh.H" #include "polyMesh.H"
#include "IOobject.H" #include "IOobject.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
namespace ensightSerialCloud
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // //- Write cloud positions
void writePositions
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
);
void ensightParticlePositions
( (
const polyMesh& mesh, const polyMesh& mesh,
const fileName& dataDir,
const fileName& subDir,
const word& cloudName, const word& cloudName,
IOstream::streamFormat format autoPtr<ensightFile> output
); );
//- Write lagrangian parcels //- Write cloud field
template<class Type> template<class Type>
void ensightLagrangianField bool writeCloudField
(
const IOField<Type>& field,
ensightFile& os
);
//- Write cloud field
template<class Type>
bool writeCloudField
( (
const IOobject& fieldObject, const IOobject& fieldObject,
const fileName& dataDir, autoPtr<ensightFile> output
const fileName& subDir,
const word& cloudName,
IOstream::streamFormat format
); );
//- Write generalized field components
template<class Type> } // namespace ensightSerialCloud
void ensightVolField } // namespace Foam
(
const ensightParts& partsList,
const IOobject& fieldObject,
const fvMesh& mesh,
const fileName& dataDir,
const fileName& subDir,
IOstream::streamFormat format
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // namespace Foam
#ifdef NoRepository #ifdef NoRepository
#include "ensightOutputFunctions.C" #include "ensightOutputSerialCloudTemplates.C"
#endif #endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -21,58 +21,69 @@ License
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description
Template to write generalized field components
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "ensightPart.H" #include "ensightOutputSerialCloud.H"
#include "ensightSerialOutput.H"
#include "ensightPTraits.H" #include "ensightPTraits.H"
#include "passiveParticle.H"
#include "IOField.H"
#include "volFields.H"
#include "surfaceFields.H"
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
template<class Type> template<class Type>
void Foam::ensightPart::writeField bool Foam::ensightSerialCloud::writeCloudField
( (
ensightFile& os, const IOField<Type>& field,
const Field<Type>& field, ensightFile& os
const bool perNode )
) const
{ {
if (this->size() && field.size()) // 6 values per line
{ label count = 0;
os.beginPart(number());
if (perNode) forAll(field, i)
{ {
os.writeKeyword("coordinates"); Type val = field[i];
for (direction d=0; d < pTraits<Type>::nComponents; ++d)
{
label cmpt = ensightPTraits<Type>::componentOrder[d];
os.writeList(field.component(cmpt)); if (mag(val) < 1e-90)
{
val = Zero;
} }
}
else
{
forAll(elementTypes(), elemI)
{
const labelUList& idList = elemLists_[elemI];
if (idList.size())
{
os.writeKeyword(elementTypes()[elemI]);
for (direction d=0; d < pTraits<Type>::nComponents; ++d) for (direction d=0; d < pTraits<Type>::nComponents; ++d)
{ {
label cmpt = ensightPTraits<Type>::componentOrder[d]; label cmpt = ensightPTraits<Type>::componentOrder[d];
os.write(component(val, cmpt));
os.writeList(field.component(cmpt), idList); if (++count % 6 == 0)
{
os.newline();
} }
} }
} }
// add final newline if required
if (count % 6)
{
os.newline();
} }
return true;
} }
template<class Type>
bool Foam::ensightSerialCloud::writeCloudField
(
const IOobject& fieldObject,
autoPtr<ensightFile> output
)
{
IOField<Type> field(fieldObject);
return writeCloudField(field, output.rawRef());
} }

View File

@ -78,8 +78,14 @@ Note
#include "scalarIOField.H" #include "scalarIOField.H"
#include "tensorIOField.H" #include "tensorIOField.H"
// file-format/conversion
#include "ensightCase.H"
#include "ensightGeoFile.H"
#include "ensightParts.H" #include "ensightParts.H"
#include "ensightOutputFunctions.H" #include "ensightSerialOutput.H"
// local files
#include "ensightOutputSerialCloud.H"
#include "memInfo.H" #include "memInfo.H"
@ -146,20 +152,8 @@ int main(int argc, char *argv[])
cloudFieldTypes.insert(vectorIOField::typeName); cloudFieldTypes.insert(vectorIOField::typeName);
cloudFieldTypes.insert(tensorIOField::typeName); cloudFieldTypes.insert(tensorIOField::typeName);
const char* geometryName = "geometry";
#include "setRootCase.H" #include "setRootCase.H"
cpuTime timer;
memInfo mem;
Info<< "Initial memory "
<< mem.update().size() << " kB" << endl;
#include "createTime.H"
// Get times list
instantList timeDirs = timeSelector::select0(runTime, args);
// Default to binary output, unless otherwise specified // Default to binary output, unless otherwise specified
const IOstream::streamFormat format = const IOstream::streamFormat format =
( (
@ -168,6 +162,57 @@ int main(int argc, char *argv[])
: IOstream::BINARY : IOstream::BINARY
); );
cpuTime timer;
memInfo mem;
Info<< "Initial memory " << mem.update().size() << " kB" << endl;
#include "createTime.H"
instantList timeDirs = timeSelector::select0(runTime, args);
#include "createNamedMesh.H"
fileName regionPrefix; // Mesh instance (region0 gets filtered out)
if (regionName != polyMesh::defaultRegion)
{
regionPrefix = regionName;
}
//
// general (case) output options
//
ensightCase::options caseOpts(format);
caseOpts.width(args.optionLookupOrDefault<label>("width", 8));
caseOpts.overwrite(false); // leave existing output directory
// Can also have separate directory for lagrangian
// caseOpts.separateCloud(true);
// Define sub-directory name to use for EnSight data.
// The path to the ensight directory is at case level only
// - For parallel cases, data only written from master
fileName ensightDir = args.optionLookupOrDefault<word>("name", "Ensight");
if (!ensightDir.isAbsolute())
{
ensightDir = args.rootPath()/args.globalCaseName()/ensightDir;
}
//
// Open new ensight case file, initialize header etc.
//
ensightCase ensCase
(
ensightDir,
"Ensight", // args.globalCaseName(),
caseOpts
);
//
// Miscellaneous output configuration
//
// Control for renumbering iterations // Control for renumbering iterations
label indexingNumber = 0; label indexingNumber = 0;
const bool optIndex = args.optionReadIfPresent("index", indexingNumber); const bool optIndex = args.optionReadIfPresent("index", indexingNumber);
@ -176,93 +221,32 @@ int main(int argc, char *argv[])
// Always write the geometry, unless the -noMesh option is specified // Always write the geometry, unless the -noMesh option is specified
bool optNoMesh = args.optionFound("noMesh"); bool optNoMesh = args.optionFound("noMesh");
// Adjust output width
if (args.optionFound("width"))
{
ensightFile::subDirWidth(args.optionRead<label>("width"));
}
// Define sub-directory name to use for Ensight data
fileName ensightDir = "Ensight";
args.optionReadIfPresent("name", ensightDir);
if (!ensightDir.isAbsolute())
{
ensightDir = args.rootPath()/args.globalCaseName()/ensightDir;
}
const fileName caseFileName = "Ensight.case";
const fileName dataDir = ensightDir/"data";
const fileName dataMask = dataDir.name()/ensightFile::mask();
// Ensight and Ensight/data directories must exist
// do not remove old data - we might wish to convert new results
// or a particular time interval
if (isDir(ensightDir))
{
Info<<"Warning: re-using existing directory" << nl
<< " " << ensightDir << endl;
}
// As per mkdir -p "Ensight/data"
mkDir(ensightDir);
mkDir(dataDir);
#include "createNamedMesh.H"
// Mesh instance (region0 gets filtered out)
fileName regionPrefix;
if (regionName != polyMesh::defaultRegion)
{
regionPrefix = regionName;
}
if (Pstream::master())
{
Info<< "Converting " << timeDirs.size() << " time steps" << endl;
}
// Construct the list of ensight parts for the entire mesh // Construct the list of ensight parts for the entire mesh
ensightParts partsList(mesh); ensightParts partsList(mesh);
// Write summary information // Write summary information
if (Pstream::master())
{ {
OFstream partsInfoFile(ensightDir/"partsInfo"); Info<< "Converting " << timeDirs.size() << " time steps" << endl;
partsInfoFile OFstream info(ensCase.path()/"partsInfo");
info
<< "// summary of ensight parts" << nl << nl; << "// summary of ensight parts" << nl << nl;
partsList.writeSummary(partsInfoFile); partsList.writeSummary(info);
} }
#include "checkHasMovingMesh.H" #include "checkMeshMoving.H"
#include "findFields.H" #include "findFields.H"
if (hasMovingMesh && optNoMesh) if (meshMoving && optNoMesh)
{ {
Info<< "mesh is moving: ignoring '-noMesh' option" << endl; Info<< "mesh is moving: ignoring '-noMesh' option" << endl;
optNoMesh = false; optNoMesh = false;
} }
// Map times used
Map<scalar> timeIndices;
// TODO: Track the time indices used by the geometry
DynamicList<label> geometryTimesUsed;
// Track the time indices used by the volume fields
DynamicList<label> fieldTimesUsed;
// Track the time indices used by each cloud
HashTable<DynamicList<label>> cloudTimesUsed;
// Create a new DynamicList for each cloud
forAllConstIter(HashTable<HashTable<word>>, cloudFields, cloudIter)
{
cloudTimesUsed.insert(cloudIter.key(), DynamicList<label>());
}
Info<< "Startup in " Info<< "Startup in "
<< timer.cpuTimeIncrement() << " s, " << timer.cpuTimeIncrement() << " s, "
<< mem.update().size() << " kB" << nl << endl; << mem.update().size() << " kB" << nl << endl;
@ -272,25 +256,10 @@ int main(int argc, char *argv[])
runTime.setTime(timeDirs[timeI], timeI); runTime.setTime(timeDirs[timeI], timeI);
#include "getTimeIndex.H" #include "getTimeIndex.H"
// Remember the time index for the volume fields
fieldTimesUsed.append(timeIndex);
// The data/ITER subdirectory must exist
// Note that data/ITER is indeed a valid ensight::FileName
const fileName subDir = ensightFile::subDir(timeIndex);
mkDir(dataDir/subDir);
// Place a timestamp in the directory for future reference
{
OFstream timeStamp(dataDir/subDir/"time");
timeStamp
<< "# timestep time" << nl
<< subDir.c_str() << " " << runTime.timeName() << nl;
}
#include "moveMesh.H" #include "moveMesh.H"
ensCase.setTime(timeDirs[timeI], timeIndex);
if (timeI == 0 || mesh.moving()) if (timeI == 0 || mesh.moving())
{ {
if (mesh.moving()) if (mesh.moving())
@ -300,19 +269,8 @@ int main(int argc, char *argv[])
if (!optNoMesh) if (!optNoMesh)
{ {
if (hasMovingMesh) autoPtr<ensightGeoFile> os = ensCase.newGeometry(meshMoving);
{ partsList.write(os.rawRef());
// Remember the time index for the geometry
geometryTimesUsed.append(timeIndex);
}
ensightGeoFile geoFile
(
(hasMovingMesh ? dataDir/subDir : ensightDir),
geometryName,
format
);
partsList.writeGeometry(geoFile);
} }
} }
@ -332,68 +290,76 @@ int main(int argc, char *argv[])
IOobject::NO_WRITE IOobject::NO_WRITE
); );
bool wrote = false;
if (fieldType == volScalarField::typeName) if (fieldType == volScalarField::typeName)
{ {
ensightVolField<scalar> autoPtr<ensightFile> os = ensCase.newData<scalar>
( (
partsList, fieldName
fieldObject,
mesh,
dataDir,
subDir,
format
); );
volScalarField vf(fieldObject, mesh);
wrote = ensightSerialOutput::writeField<scalar>
(
vf, partsList, os
);
} }
else if (fieldType == volVectorField::typeName) else if (fieldType == volVectorField::typeName)
{ {
ensightVolField<vector> autoPtr<ensightFile> os = ensCase.newData<vector>
( (
partsList, fieldName
fieldObject,
mesh,
dataDir,
subDir,
format
); );
volVectorField vf(fieldObject, mesh);
wrote = ensightSerialOutput::writeField<vector>
(
vf, partsList, os
);
} }
else if (fieldType == volSphericalTensorField::typeName) else if (fieldType == volSphericalTensorField::typeName)
{ {
ensightVolField<sphericalTensor> autoPtr<ensightFile> os = ensCase.newData<sphericalTensor>
( (
partsList, fieldName
fieldObject,
mesh,
dataDir,
subDir,
format
); );
volSphericalTensorField vf(fieldObject, mesh);
wrote = ensightSerialOutput::writeField<sphericalTensor>
(
vf, partsList, os
);
} }
else if (fieldType == volSymmTensorField::typeName) else if (fieldType == volSymmTensorField::typeName)
{ {
ensightVolField<symmTensor> autoPtr<ensightFile> os = ensCase.newData<symmTensor>
( (
partsList, fieldName
fieldObject, );
mesh,
dataDir, volSymmTensorField vf(fieldObject, mesh);
subDir, wrote = ensightSerialOutput::writeField<symmTensor>
format (
vf, partsList, os
); );
} }
else if (fieldType == volTensorField::typeName) else if (fieldType == volTensorField::typeName)
{ {
ensightVolField<tensor> autoPtr<ensightFile> os = ensCase.newData<tensor>
( (
partsList, fieldName
fieldObject,
mesh,
dataDir,
subDir,
format
); );
volTensorField vf(fieldObject, mesh);
wrote = ensightSerialOutput::writeField<tensor>
(
vf, partsList, os
);
}
if (wrote)
{
Info<< " " << fieldObject.name() << flush;
} }
} }
Info<< " )" << endl; Info<< " )" << endl;
@ -422,16 +388,16 @@ int main(int argc, char *argv[])
continue; continue;
} }
Info<< "Write " << cloudName << " ( positions" << flush; Info<< "Write " << cloudName << " (" << flush;
ensightParticlePositions ensightSerialCloud::writePositions
( (
mesh, mesh,
dataDir,
subDir,
cloudName, cloudName,
format ensCase.newCloud(cloudName)
); );
Info<< " positions";
forAllConstIter(HashTable<word>, cloudIter(), fieldIter) forAllConstIter(HashTable<word>, cloudIter(), fieldIter)
{ {
@ -449,48 +415,39 @@ int main(int argc, char *argv[])
continue; continue;
} }
bool wrote = false;
if (fieldType == scalarIOField::typeName) if (fieldType == scalarIOField::typeName)
{ {
ensightLagrangianField<scalar> wrote = ensightSerialCloud::writeCloudField<scalar>
( (
*fieldObject, *fieldObject,
dataDir, ensCase.newCloudData<scalar>(cloudName, fieldName)
subDir,
cloudName,
format
); );
} }
else if (fieldType == vectorIOField::typeName) else if (fieldType == vectorIOField::typeName)
{ {
ensightLagrangianField<vector> wrote = ensightSerialCloud::writeCloudField<vector>
( (
*fieldObject, *fieldObject,
dataDir, ensCase.newCloudData<vector>(cloudName, fieldName)
subDir,
cloudName,
format
); );
} }
else if (fieldType == tensorIOField::typeName) else if (fieldType == tensorIOField::typeName)
{ {
ensightLagrangianField<tensor> wrote = ensightSerialCloud::writeCloudField<tensor>
( (
*fieldObject, *fieldObject,
dataDir, ensCase.newCloudData<tensor>(cloudName, fieldName)
subDir,
cloudName,
format
); );
}
if (wrote)
{
Info<< " " << fieldObject->name();
} }
} }
Info<< " )" << endl; Info<< " )" << endl;
// Remember the time index
cloudTimesUsed[cloudName].append(timeIndex);
} }
Info<< "Wrote in " Info<< "Wrote in "
@ -498,7 +455,7 @@ int main(int argc, char *argv[])
<< mem.update().size() << " kB" << endl; << mem.update().size() << " kB" << endl;
} }
#include "ensightOutputCase.H" ensCase.write();
Info<< "\nEnd: " Info<< "\nEnd: "
<< timer.elapsedCpuTime() << " s, " << timer.elapsedCpuTime() << " s, "

View File

@ -38,6 +38,6 @@
} }
} }
timeIndices.insert(timeIndex, timeDirs[timeI].value());
Info<< nl << "Time [" << timeIndex << "] = " << runTime.timeName() << nl; Info<< nl << "Time [" << timeIndex << "] = " << runTime.timeName() << nl;
// end-of-file

View File

@ -11,7 +11,6 @@ ensight/mesh/ensightMesh.C
ensight/mesh/ensightMeshIO.C ensight/mesh/ensightMeshIO.C
ensight/mesh/ensightMeshOptions.C ensight/mesh/ensightMeshOptions.C
ensight/part/ensightPart.C ensight/part/ensightPart.C
ensight/part/ensightPartIO.C
ensight/part/ensightPartCells.C ensight/part/ensightPartCells.C
ensight/part/ensightPartFaces.C ensight/part/ensightPartFaces.C
ensight/part/ensightParts.C ensight/part/ensightParts.C

View File

@ -0,0 +1,146 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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/>.
Class
Foam::ensightSerialOutput
Description
A collection of functions for writing ensight file content in serial.
Can be considered transitional and may eventually merge with ensightOutput.
SourceFiles
ensightSerialOutputTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef ensightSerialOutput_H
#define ensightSerialOutput_H
#include "ensightPart.H"
#include "ensightPartFaces.H"
#include "ensightPartCells.H"
#include "ensightParts.H"
#include "volFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class ensightSerialOutput Declaration
\*---------------------------------------------------------------------------*/
class ensightSerialOutput
{
// Private Methods
//- Write field component-wise
template<class Type>
static void writeField
(
const word& key,
const Field<Type>& field,
ensightFile& os
);
//- Disallow null constructor
ensightSerialOutput() = delete;
public:
// Public Methods
//- Write field component-wise
template<class Type>
static bool writeField
(
const Field<Type>&,
const ensightPartFaces& part,
ensightFile& os,
const bool nodeValues
);
//- Write volume field component-wise
template<class Type>
static bool writeField
(
const GeometricField<Type, fvPatchField, volMesh>&,
const ensightPartCells& part,
ensightFile& os
);
//- Write volume field component-wise
template<class Type>
static bool writeField
(
const GeometricField<Type, fvPatchField, volMesh>&,
const ensightParts& list,
ensightFile& os
);
//- Write volume field component-wise
template<class Type>
static inline bool writeField
(
const GeometricField<Type, fvPatchField, volMesh>& vf,
const ensightPartCells& part,
autoPtr<ensightFile>& output
)
{
return writeField(vf, part, output.rawRef());
}
//- Write volume field component-wise
template<class Type>
static inline bool writeField
(
const GeometricField<Type, fvPatchField, volMesh>& vf,
const ensightParts& list,
autoPtr<ensightFile>& output
)
{
return writeField(vf, list, output.rawRef());
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "ensightSerialOutputTemplates.C"
#endif
#endif
// ************************************************************************* //

View File

@ -0,0 +1,178 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "ensightPart.H"
#include "ensightParts.H"
#include "ensightPTraits.H"
#include "direction.H"
#include "typeInfo.H"
// * * * * * * * * * * Static Private Member Functions * * * * * * * * * * * //
template<class Type>
void Foam::ensightSerialOutput::writeField
(
const word& key,
const Field<Type>& fld,
ensightFile& os
)
{
if (fld.size())
{
os.writeKeyword(key);
for (direction d=0; d < pTraits<Type>::nComponents; ++d)
{
const label cmpt = ensightPTraits<Type>::componentOrder[d];
os.writeList(fld.component(cmpt));
}
}
}
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
template<class Type>
bool Foam::ensightSerialOutput::writeField
(
const Field<Type>& fld,
const ensightPartFaces& part,
ensightFile& os,
const bool nodeValues
)
{
if (part.size() && fld.size())
{
if (nodeValues)
{
os.beginPart(part.index());
os.writeKeyword("coordinates");
for (direction d=0; d < pTraits<Type>::nComponents; ++d)
{
const label cmpt = ensightPTraits<Type>::componentOrder[d];
os.writeList(fld.component(cmpt));
}
}
else
{
os.beginPart(part.index());
const List<ensightFaces::elemType> enums =
ensightFaces::elemEnum.enums();
forAllConstIter(List<ensightFaces::elemType>, enums, iter)
{
const ensightFaces::elemType what = *iter;
writeField
(
ensightFaces::key(what),
Field<Type>(fld, part.faceIds(what)),
os
);
}
}
}
return true;
}
template<class Type>
bool Foam::ensightSerialOutput::writeField
(
const GeometricField<Type, fvPatchField, volMesh>& fld,
const ensightPartCells& part,
ensightFile& os
)
{
if (part.size() && fld.size())
{
os.beginPart(part.index());
const List<ensightCells::elemType> enums =
ensightCells::elemEnum.enums();
forAllConstIter(List<ensightCells::elemType>, enums, iter)
{
const ensightCells::elemType what = *iter;
writeField
(
ensightCells::key(what),
Field<Type>(fld, part.cellIds(what)),
os
);
}
}
return true;
}
template<class Type>
bool Foam::ensightSerialOutput::writeField
(
const GeometricField<Type, fvPatchField, volMesh>& vf,
const ensightParts& list,
ensightFile& os
)
{
forAllConstIter(ensightParts::StorageType, list, iter)
{
if (isA<ensightPartFaces>(*iter))
{
const ensightPartFaces& part =
dynamicCast<const ensightPartFaces&>(*iter);
const label patchi = part.patchIndex();
if (patchi >= 0 && patchi < vf.boundaryField().size())
{
writeField
(
vf.boundaryField()[patchi],
part,
os,
false
);
}
}
else
{
const ensightPartCells& part =
dynamicCast<const ensightPartCells&>(*iter);
writeField(vf, part, os);
}
}
return true;
}
// ************************************************************************* //

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -24,164 +24,63 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "ensightPart.H" #include "ensightPart.H"
#include "dictionary.H"
#include "ListOps.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
defineTypeNameAndDebug(ensightPart, 0); defineTypeNameAndDebug(ensightPart, 0);
defineTemplateTypeNameAndDebug(IOPtrList<ensightPart>, 0);
defineRunTimeSelectionTable(ensightPart, istream);
} }
const Foam::List<Foam::word> Foam::ensightPart::elemTypes_(0);
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
bool Foam::ensightPart::isFieldDefined(const List<scalar>& field) const // TODO - move elsewhere
#if 0
bool Foam::ensightPart::isFieldDefined
(
const List<scalar>& field
// const labelUList& addr = cellIds() or faceIds()
) const
{ {
forAll(elemLists_, elemI) forAll(addr, elemI)
{ {
const labelUList& idList = elemLists_[elemI]; const label id = addr[i];
forAll(idList, i)
{
const label id = idList[i];
if (id >= field.size() || std::isnan(field[id])) if (id >= field.size() || std::isnan(field[id]))
{ {
return false; return false;
} }
} }
}
return true; return true;
} }
#endif
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::ensightPart::ensightPart Foam::ensightPart::ensightPart(const string& description)
()
: :
number_(0), name_(description)
name_(""),
elemLists_(0),
offset_(0),
size_(0),
isCellData_(true),
matId_(0),
points_(pointField::null())
{} {}
Foam::ensightPart::ensightPart
(
label partNumber,
const string& partDescription
)
:
number_(partNumber),
name_(partDescription),
elemLists_(0),
offset_(0),
size_(0),
isCellData_(true),
matId_(0),
points_(pointField::null())
{}
Foam::ensightPart::ensightPart
(
label partNumber,
const string& partDescription,
const pointField& points
)
:
number_(partNumber),
name_(partDescription),
elemLists_(0),
offset_(0),
size_(0),
isCellData_(true),
matId_(0),
points_(points)
{}
Foam::ensightPart::ensightPart(const ensightPart& part)
:
number_(part.number_),
name_(part.name_),
elemLists_(part.elemLists_),
offset_(part.offset_),
size_(part.size_),
isCellData_(part.isCellData_),
matId_(part.matId_),
points_(part.points_)
{}
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
Foam::autoPtr<Foam::ensightPart> Foam::ensightPart::New(Istream& is)
{
const word partType(is);
istreamConstructorTable::iterator cstrIter =
istreamConstructorTablePtr_->find(partType);
if (cstrIter == istreamConstructorTablePtr_->end())
{
FatalIOErrorInFunction
(
is
) << "unknown ensightPart type "
<< partType << nl << nl
<< "Valid ensightPart types are :" << endl
<< istreamConstructorTablePtr_->sortedToc()
<< exit(FatalIOError);
}
return autoPtr<ensightPart>(cstrIter()(is));
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::ensightPart::~ensightPart() Foam::ensightPart::~ensightPart()
{} {}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
void Foam::ensightPart::renumber(const labelUList& origId) Foam::ensightGeoFile& Foam::operator<<
(
ensightGeoFile& os,
const ensightPart& part
)
{ {
// transform to global values first part.write(os);
if (offset_) return os;
{
forAll(elemLists_, elemI)
{
labelList& idList = elemLists_[elemI];
forAll(idList, i)
{
idList[i] += offset_;
}
}
offset_ = 0;
}
if (origId.size())
{
forAll(elemLists_, elemI)
{
inplaceRenumber(origId, elemLists_[elemI]);
}
}
} }

View File

@ -29,21 +29,17 @@ Description
SourceFiles SourceFiles
ensightPart.C ensightPart.C
ensightPartIO.C
ensightPartTemplates.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef ensightPart_H #ifndef ensightPart_H
#define ensightPart_H #define ensightPart_H
#include "ensightFile.H"
#include "ensightGeoFile.H" #include "ensightGeoFile.H"
#include "typeInfo.H" #include "typeInfo.H"
#include "labelList.H" #include "labelList.H"
#include "polyMesh.H" #include "polyMesh.H"
#include "Field.H" #include "Field.H"
#include "IOPtrList.H"
#include "IOstream.H" #include "IOstream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -54,8 +50,6 @@ namespace Foam
// Forward declaration of friend functions and operators // Forward declaration of friend functions and operators
class ensightPart; class ensightPart;
Ostream& operator<<(Ostream&, const ensightPart&);
ensightGeoFile& operator<<(ensightGeoFile&, const ensightPart&); ensightGeoFile& operator<<(ensightGeoFile&, const ensightPart&);
@ -65,40 +59,22 @@ ensightGeoFile& operator<<(ensightGeoFile&, const ensightPart&);
class ensightPart class ensightPart
{ {
// Private data // Private Data
// Static data members
static const List<word> elemTypes_;
protected:
// Protected data
//- Part number
label number_;
//- Part name (or description) //- Part name (or description)
string name_; string name_;
//- Simple labelList with a name
labelListList elemLists_;
//- Start offset for elemLists_ // Private Member Functions
label offset_;
//- Number of elements in this part //- Disallow default bitwise copy construct
label size_; ensightPart(const ensightPart&) = delete;
//- Cell or face data //- Disallow default bitwise assignment
bool isCellData_; void operator=(const ensightPart&) = delete;
//- Material id (numeric)
label matId_;
//- pointField referenced
const pointField& points_;
protected:
// Protected Classes // Protected Classes
@ -127,34 +103,6 @@ protected:
{} {}
}; };
// Protected Member Functions
//- Reconstruct part characteristics (eg, element types) from Istream
// A part reconstructed in this manner can be used when writing fields,
// but cannot be used to write a new geometry
void reconstruct(Istream&);
//- Check for fully defined fields
bool isFieldDefined(const List<scalar>&) const;
//- Track points used
virtual localPoints calcLocalPoints() const
{
return localPoints();
}
//- Write connectivities
virtual void writeConnectivity
(
ensightGeoFile&,
const word& key,
const labelUList& idList,
const labelUList& pointMap
) const
{}
public: public:
//- Runtime type information //- Runtime type information
@ -163,85 +111,23 @@ public:
// Constructors // Constructors
//- Construct null //- Construct with description
ensightPart(); ensightPart(const string& description);
//- Construct empty part with number and description
ensightPart(label partNumber, const string& partDescription);
//- Construct part with number, description and points reference
ensightPart
(
label partNumber,
const string& partDescription,
const pointField& points
);
//- Construct as copy
ensightPart(const ensightPart&);
// Selectors
// Declare run-time constructor selection table
declareRunTimeSelectionTable
(
autoPtr,
ensightPart,
istream,
(
Istream& is
),
(is)
);
//- Construct and return clone
autoPtr<ensightPart> clone() const
{
return autoPtr<ensightPart>(new ensightPart(*this));
};
//- Reconstruct part characteristics on freestore from Istream
// \sa reconstruct
static autoPtr<ensightPart> New(Istream&);
//- Destructor //- Destructor
virtual ~ensightPart(); virtual ~ensightPart();
// Static members
virtual const List<word>& elementTypes() const
{
return elemTypes_;
}
// Access // Access
//- Part index (0-based)
virtual label index() const = 0;
//- Number of elements in this part //- Number of elements in this part
label size() const virtual label size() const
{ {
return size_; return 0;
}
//- Represents cell data
bool isCellData() const
{
return isCellData_;
}
//- Represents face data
bool isFaceData() const
{
return !isCellData_;
}
//- Part number
label number() const
{
return number_;
} }
//- Part name or description //- Part name or description
@ -250,80 +136,35 @@ public:
return name_; return name_;
} }
//- Material id
label materialId() const
{
return matId_;
}
//- non-const access to part name or description //- non-const access to part name or description
void name(const string& value) void name(const string& value)
{ {
name_ = value; name_ = value;
} }
//- non-const access to material id
void materialId(const label value)
{
matId_ = value;
}
//- Simple labelList with a name // Output
const labelListList& elemLists() const
{
return elemLists_;
}
//- Offset for element ids
label offset() const
{
return offset_;
}
// Edit
//- Renumber elements
void renumber(const labelUList&);
//- Write summary information about the object
bool writeSummary(Ostream&) const;
//- Write reconstruction information for the object
bool writeData(Ostream&) const;
//- Write geometry //- Write geometry
virtual void writeGeometry(ensightGeoFile&) const virtual void write(ensightGeoFile&) const = 0;
{}
//- Helper: write geometry given the pointField //- Helper: write geometry with given pointField
void writeGeometry(ensightGeoFile&, const pointField&) const; virtual void write
//- Write generalized field components
// optionally write data per node
template<class Type>
void writeField
( (
ensightFile&, ensightGeoFile&,
const Field<Type>&, const pointField&
const bool perNode = false ) const = 0;
) const;
// Member Operators //- Write summary information about the object
virtual void writeSummary(Ostream&) const = 0;
//- Disallow default bitwise assignment //- Print various types of debugging information
void operator=(const ensightPart&) virtual void dumpInfo(Ostream&) const = 0;
{
NotImplemented;
}
// IOstream Operators // IOstream Operators
//- Write data (reconstruction information)
friend Ostream& operator<<(Ostream&, const ensightPart&);
//- Write geometry //- Write geometry
friend ensightGeoFile& operator<<(ensightGeoFile&, const ensightPart&); friend ensightGeoFile& operator<<(ensightGeoFile&, const ensightPart&);
@ -336,12 +177,6 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "ensightPartTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif #endif
// ************************************************************************* // // ************************************************************************* //

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -24,247 +24,29 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "ensightPartCells.H" #include "ensightPartCells.H"
#include "IOstream.H"
#include "IStringStream.H"
#include "dictionary.H"
#include "cellModeller.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
defineTypeNameAndDebug(ensightPartCells, 0); defineTypeNameAndDebug(ensightPartCells, 0);
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream);
} }
const Foam::List<Foam::word> Foam::ensightPartCells::elemTypes_
(
IStringStream
(
"(tetra4 pyramid5 penta6 hexa8 nfaced)"
)()
);
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::ensightPartCells::classify
(
const polyMesh& mesh,
const labelUList& idList
)
{
// References to cell shape models
const cellModel& tet = *(cellModeller::lookup("tet"));
const cellModel& pyr = *(cellModeller::lookup("pyr"));
const cellModel& prism = *(cellModeller::lookup("prism"));
const cellModel& hex = *(cellModeller::lookup("hex"));
const cellShapeList& cellShapes = mesh.cellShapes();
offset_ = 0;
size_ = mesh.nCells();
bool limited = false;
if (notNull(idList))
{
limited = true;
size_ = idList.size();
}
// count the shapes
label nTet = 0;
label nPyr = 0;
label nPrism = 0;
label nHex = 0;
label nPoly = 0;
for (label listI = 0; listI < size_; ++listI)
{
label cellId = listI;
if (limited)
{
cellId = idList[listI];
}
const cellShape& cellShape = cellShapes[cellId];
const cellModel& cellModel = cellShape.model();
if (cellModel == tet)
{
nTet++;
}
else if (cellModel == pyr)
{
nPyr++;
}
else if (cellModel == prism)
{
nPrism++;
}
else if (cellModel == hex)
{
nHex++;
}
else
{
nPoly++;
}
}
// we can avoid double looping, but at the cost of allocation
labelList tetCells(nTet);
labelList pyramidCells(nPyr);
labelList prismCells(nPrism);
labelList hexCells(nHex);
labelList polyCells(nPoly);
nTet = 0,
nPyr = 0;
nPrism = 0;
nHex = 0;
nPoly = 0;
// classify the shapes
for (label listI = 0; listI < size_; ++listI)
{
label cellId = listI;
if (limited)
{
cellId = idList[listI];
}
const cellShape& cellShape = cellShapes[cellId];
const cellModel& cellModel = cellShape.model();
if (cellModel == tet)
{
tetCells[nTet++] = cellId;
}
else if (cellModel == pyr)
{
pyramidCells[nPyr++] = cellId;
}
else if (cellModel == prism)
{
prismCells[nPrism++] = cellId;
}
else if (cellModel == hex)
{
hexCells[nHex++] = cellId;
}
else
{
polyCells[nPoly++] = cellId;
}
}
// MUST match with elementTypes
elemLists_.setSize(elementTypes().size());
elemLists_[tetra4Elements].transfer(tetCells);
elemLists_[pyramid5Elements].transfer(pyramidCells);
elemLists_[penta6Elements].transfer(prismCells);
elemLists_[hexa8Elements].transfer(hexCells);
elemLists_[nfacedElements].transfer(polyCells);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::ensightPartCells::ensightPartCells
(
label partNumber,
const string& partDescription
)
:
ensightPart(partNumber, partDescription),
mesh_(*reinterpret_cast<polyMesh*>(0))
{}
Foam::ensightPartCells::ensightPartCells
(
label partNumber,
const polyMesh& mesh
)
:
ensightPart(partNumber, "cells", mesh.points()),
mesh_(mesh)
{
classify(mesh);
}
Foam::ensightPartCells::ensightPartCells
(
label partNumber,
const polyMesh& mesh,
const labelUList& idList
)
:
ensightPart(partNumber, "cells", mesh.points()),
mesh_(mesh)
{
classify(mesh, idList);
}
Foam::ensightPartCells::ensightPartCells
(
label partNumber,
const polyMesh& mesh,
const cellZone& cZone
)
:
ensightPart(partNumber, cZone.name(), mesh.points()),
mesh_(mesh)
{
classify(mesh, cZone);
}
Foam::ensightPartCells::ensightPartCells(const ensightPartCells& part)
:
ensightPart(part),
mesh_(part.mesh_)
{}
Foam::ensightPartCells::ensightPartCells(Istream& is)
:
ensightPart(),
mesh_(*reinterpret_cast<polyMesh*>(0))
{
reconstruct(is);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::ensightPartCells::~ensightPartCells()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::ensightPart::localPoints Foam::ensightPartCells::calcLocalPoints() const Foam::ensightPart::localPoints Foam::ensightPartCells::calcLocalPoints() const
{ {
localPoints ptList(points_); localPoints ptList(mesh_.points());
labelList& usedPoints = ptList.list; labelList& usedPoints = ptList.list;
label nPoints = 0; label nPoints = 0;
forAll(elemLists_, typeI)
{
const labelUList& idList = elemLists_[typeI];
// add all points from cells // add all points from cells
const labelUList& idList = this->cellIds();
forAll(idList, i) forAll(idList, i)
{ {
const label id = idList[i] + offset_; const label id = idList[i];
const labelUList& cFaces = mesh_.cells()[id]; const labelUList& cFaces = mesh_.cells()[id];
forAll(cFaces, cFacei) forAll(cFaces, cFacei)
@ -280,7 +62,6 @@ Foam::ensightPart::localPoints Foam::ensightPartCells::calcLocalPoints() const
} }
} }
} }
}
// this is not absolutely necessary, but renumber anyhow // this is not absolutely necessary, but renumber anyhow
nPoints = 0; nPoints = 0;
@ -297,6 +78,60 @@ Foam::ensightPart::localPoints Foam::ensightPartCells::calcLocalPoints() const
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::ensightPartCells::ensightPartCells
(
label partIndex,
const polyMesh& mesh
)
:
ensightCells(partIndex),
ensightPart("cells"),
mesh_(mesh)
{
classify(mesh);
}
Foam::ensightPartCells::ensightPartCells
(
label partIndex,
const polyMesh& mesh,
const labelUList& idList
)
:
ensightCells(partIndex),
ensightPart("cells"),
mesh_(mesh)
{
classify(mesh, idList);
}
Foam::ensightPartCells::ensightPartCells
(
label partIndex,
const polyMesh& mesh,
const cellZone& cZone
)
:
ensightCells(partIndex),
ensightPart(cZone.name()),
mesh_(mesh)
{
classify(mesh, cZone);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::ensightPartCells::~ensightPartCells()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::ensightPartCells::writeConnectivity void Foam::ensightPartCells::writeConnectivity
( (
ensightGeoFile& os, ensightGeoFile& os,
@ -305,6 +140,8 @@ void Foam::ensightPartCells::writeConnectivity
const labelUList& pointMap const labelUList& pointMap
) const ) const
{ {
if (idList.empty()) return;
os.writeKeyword(key); os.writeKeyword(key);
os.write(idList.size()); os.write(idList.size());
os.newline(); os.newline();
@ -318,7 +155,7 @@ void Foam::ensightPartCells::writeConnectivity
// write the number of faces per element // write the number of faces per element
forAll(idList, i) forAll(idList, i)
{ {
const label id = idList[i] + offset_; const label id = idList[i];
const labelUList& cFace = mesh_.cells()[id]; const labelUList& cFace = mesh_.cells()[id];
os.write(cFace.size()); os.write(cFace.size());
@ -328,7 +165,7 @@ void Foam::ensightPartCells::writeConnectivity
// write the number of points per element face // write the number of points per element face
forAll(idList, i) forAll(idList, i)
{ {
const label id = idList[i] + offset_; const label id = idList[i];
const labelUList& cFace = mesh_.cells()[id]; const labelUList& cFace = mesh_.cells()[id];
forAll(cFace, facei) forAll(cFace, facei)
@ -343,7 +180,7 @@ void Foam::ensightPartCells::writeConnectivity
// write the points describing each element face // write the points describing each element face
forAll(idList, i) forAll(idList, i)
{ {
const label id = idList[i] + offset_; const label id = idList[i];
const labelUList& cFace = mesh_.cells()[id]; const labelUList& cFace = mesh_.cells()[id];
forAll(cFace, cFacei) forAll(cFace, cFacei)
@ -380,12 +217,12 @@ void Foam::ensightPartCells::writeConnectivity
else else
{ {
// write primitive // write primitive
const cellShapeList& cellShapes = mesh_.cellShapes(); const cellShapeList& shapes = mesh_.cellShapes();
forAll(idList, i) forAll(idList, i)
{ {
const label id = idList[i] + offset_; const label id = idList[i];
const cellShape& cellPoints = cellShapes[id]; const cellShape& cellPoints = shapes[id];
// convert global -> local index // convert global -> local index
// (note: Ensight indices start with 1) // (note: Ensight indices start with 1)
@ -399,9 +236,97 @@ void Foam::ensightPartCells::writeConnectivity
} }
void Foam::ensightPartCells::writeGeometry(ensightGeoFile& os) const void Foam::ensightPartCells::write
(
ensightGeoFile& os,
const pointField& points
) const
{ {
ensightPart::writeGeometry(os, points_); if (size())
{
const localPoints ptList = calcLocalPoints();
const labelUList& pointMap = ptList.list;
os.beginPart(index(), name());
os.beginCoordinates(ptList.nPoints);
for (direction cmpt=0; cmpt < point::nComponents; ++cmpt)
{
forAll(pointMap, ptI)
{
if (pointMap[ptI] > -1)
{
os.write(points[ptI].component(cmpt));
os.newline();
}
}
}
// write each element type
const List<ensightCells::elemType> enums =
ensightCells::elemEnum.enums();
forAllConstIter(List<ensightCells::elemType>, enums, iter)
{
const ensightCells::elemType what = *iter;
writeConnectivity
(
os,
ensightCells::key(what),
cellIds(what),
pointMap
);
}
}
}
void Foam::ensightPartCells::write(ensightGeoFile& os) const
{
this->write(os, mesh_.points());
}
void Foam::ensightPartCells::writeSummary(Ostream& os) const
{
os.beginBlock(type());
os.writeEntry("id", index()+1); // Ensight starts with 1
os.writeEntry("name", name());
os.writeEntry("size", size());
os.endBlock() << flush;
}
void Foam::ensightPartCells::dumpInfo(Ostream& os) const
{
os.beginBlock(type());
os.writeEntry("id", index()+1); // Ensight starts with 1
os.writeEntry("name", name());
os.writeEntry("size", size());
const List<ensightCells::elemType> enums = ensightCells::elemEnum.enums();
forAllConstIter(List<ensightCells::elemType>, enums, iter)
{
const ensightCells::elemType what = *iter;
const labelUList& addr = this->cellIds(what);
os.writeKeyword(ensightCells::key(what));
// DIY flat output
os << addr.size() << '(';
forAll(addr, i)
{
if (i) os << ' ';
os << addr[i];
}
os << ')' << endEntry;
}
os.endBlock() << flush;
} }

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -36,6 +36,7 @@ SourceFiles
#define ensightPartCells_H #define ensightPartCells_H
#include "ensightPart.H" #include "ensightPart.H"
#include "ensightCells.H"
#include "typeInfo.H" #include "typeInfo.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -49,28 +50,22 @@ namespace Foam
class ensightPartCells class ensightPartCells
: :
public ensightCells,
public ensightPart public ensightPart
{ {
// Private data
//- Mesh referenced
const polyMesh& mesh_;
// Private Member Functions // Private Member Functions
//- Disallow default bitwise assignment
void operator=(const ensightPartCells&);
//- Classify the cell types, set elemLists.
void classify
(
const polyMesh&,
const labelUList& idLabels = labelUList::null()
);
//- Track points used //- Track points used
virtual localPoints calcLocalPoints() const; localPoints calcLocalPoints() const;
//- Track the points used
// virtual void makeLocalPointMap();
//- Element connectivity //- Element connectivity
virtual void writeConnectivity void writeConnectivity
( (
ensightGeoFile&, ensightGeoFile&,
const word& key, const word& key,
@ -79,28 +74,11 @@ class ensightPartCells
) const; ) const;
protected: //- Disallow default bitwise copy construct
ensightPartCells(const ensightPartCells&) = delete;
//- Addressable ensight element types //- Disallow default bitwise assignment
enum elemType void operator=(const ensightPartCells&) = delete;
{
tetra4Elements,
pyramid5Elements,
penta6Elements,
hexa8Elements,
nfacedElements
};
// Static data members
static const List<word> elemTypes_;
// Protected data
//- Mesh referenced
const polyMesh& mesh_;
public: public:
@ -110,16 +88,17 @@ public:
// Constructors // Constructors
//- Construct empty part with number and description
ensightPartCells(label partNumber, const string& partDescription);
//- Construct from polyMesh without zones //- Construct from polyMesh without zones
ensightPartCells(label partNumber, const polyMesh&); ensightPartCells
(
label partIndex,
const polyMesh&
);
//- Construct from polyMesh and list of (non-zoned) cells //- Construct from polyMesh and list of (non-zoned) cells
ensightPartCells ensightPartCells
( (
label partNumber, label partIndex,
const polyMesh&, const polyMesh&,
const labelUList& const labelUList&
); );
@ -127,26 +106,11 @@ public:
//- Construct from polyMesh and cellZone //- Construct from polyMesh and cellZone
ensightPartCells ensightPartCells
( (
label partNumber, label partIndex,
const polyMesh&, const polyMesh&,
const cellZone& const cellZone&
); );
//- Construct as copy
ensightPartCells(const ensightPartCells&);
//- Reconstruct part characteristics (eg, element types) from Istream
// A part reconstructed in this manner can be used when writing fields,
// but cannot be used to write a new geometry
// \sa Foam::ensightPart::reconstruct
ensightPartCells(Istream&);
//- Reconstruct part characteristics on freestore from Istream
static autoPtr<ensightPartCells> New(Istream& is)
{
return autoPtr<ensightPartCells>(new ensightPartCells(is));
}
//- Destructor //- Destructor
virtual ~ensightPartCells(); virtual ~ensightPartCells();
@ -154,14 +118,36 @@ public:
// Member Functions // Member Functions
//- Write geometry // Access
virtual void writeGeometry(ensightGeoFile&) const;
//- Static listing of the element types //- Part index (0-based)
virtual const List<word>& elementTypes() const virtual label index() const
{ {
return elemTypes_; return ensightCells::index();
} }
//- Number of elements in this part
virtual label size() const
{
return ensightCells::size();
}
// Output
//- Write geometry
virtual void write(ensightGeoFile&) const;
//- Helper: write geometry given the pointField
virtual void write(ensightGeoFile&, const pointField&) const;
//- Write summary information about the object
virtual void writeSummary(Ostream&) const;
//- Print various types of debugging information
virtual void dumpInfo(Ostream&) const;
}; };

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -24,182 +24,15 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "ensightPartFaces.H" #include "ensightPartFaces.H"
#include "IOstreams.H"
#include "IStringStream.H"
#include "dictionary.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
defineTypeNameAndDebug(ensightPartFaces, 0); defineTypeNameAndDebug(ensightPartFaces, 0);
addToRunTimeSelectionTable(ensightPart, ensightPartFaces, istream);
} }
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
const Foam::List<Foam::word> Foam::ensightPartFaces::elemTypes_
(
IStringStream
(
"(tria3 quad4 nsided)"
)()
);
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::ensightPartFaces::classify(const faceList& faces)
{
// count the shapes
label nTri = 0;
label nQuad = 0;
label nPoly = 0;
forAll(faces, facei)
{
const face& f = faces[facei];
if (f.size() == 3)
{
nTri++;
}
else if (f.size() == 4)
{
nQuad++;
}
else
{
nPoly++;
}
}
// we can avoid double looping, but at the cost of allocation
labelList triCells(nTri);
labelList quadCells(nQuad);
labelList polygonCells(nPoly);
nTri = 0;
nQuad = 0;
nPoly = 0;
// classify the shapes
forAll(faces, facei)
{
const face& f = faces[facei];
if (f.size() == 3)
{
triCells[nTri++] = facei;
}
else if (f.size() == 4)
{
quadCells[nQuad++] = facei;
}
else
{
polygonCells[nPoly++] = facei;
}
}
// MUST match with elementTypes
elemLists_.setSize(elementTypes().size());
elemLists_[tria3Elements].transfer(triCells);
elemLists_[quad4Elements].transfer(quadCells);
elemLists_[nsidedElements].transfer(polygonCells);
size_ = faces.size();
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::ensightPartFaces::ensightPartFaces
(
label partNumber,
const string& partDescription
)
:
ensightPart(partNumber, partDescription),
faces_(faceList::null()),
contiguousPoints_(false)
{
isCellData_ = false;
offset_ = 0;
size_ = 0;
}
Foam::ensightPartFaces::ensightPartFaces
(
label partNumber,
const string& partDescription,
const pointField& points,
const faceList& faces,
const bool contiguousPoints
)
:
ensightPart(partNumber, partDescription, points),
faces_(faces),
contiguousPoints_(contiguousPoints)
{
isCellData_ = false;
offset_ = 0;
size_ = 0;
// classify the face shapes
classify(faces);
}
Foam::ensightPartFaces::ensightPartFaces
(
label partNumber,
const polyMesh& mesh,
const polyPatch& patch
)
:
ensightPart(partNumber, patch.name(), mesh.points()),
faces_(mesh.faces()),
contiguousPoints_(false)
{
isCellData_ = false;
offset_ = patch.start();
// classify the face shapes
classify(patch);
}
Foam::ensightPartFaces::ensightPartFaces(const ensightPartFaces& part)
:
ensightPart(part),
faces_(part.faces_),
contiguousPoints_(part.contiguousPoints_)
{}
Foam::ensightPartFaces::ensightPartFaces(Istream& is)
:
ensightPart(),
faces_(faceList::null()),
contiguousPoints_(false)
{
isCellData_ = false;
reconstruct(is);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::ensightPartFaces::~ensightPartFaces()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::ensightPart::localPoints Foam::ensightPartFaces::calcLocalPoints() const Foam::ensightPart::localPoints Foam::ensightPartFaces::calcLocalPoints() const
{ {
@ -215,14 +48,13 @@ Foam::ensightPart::localPoints Foam::ensightPartFaces::calcLocalPoints() const
labelList& usedPoints = ptList.list; labelList& usedPoints = ptList.list;
label nPoints = 0; label nPoints = 0;
forAll(elemLists_, typeI) // add all points from faces
{ const labelUList& idList = this->faceIds();
const labelUList& idList = elemLists_[typeI];
// add all points from faces // add all points from faces
forAll(idList, i) forAll(idList, i)
{ {
const label id = idList[i] + offset_; const label id = idList[i] + start_;
const face& f = faces_[id]; const face& f = faces_[id];
forAll(f, fp) forAll(f, fp)
@ -233,7 +65,7 @@ Foam::ensightPart::localPoints Foam::ensightPartFaces::calcLocalPoints() const
} }
} }
} }
}
// this is not absolutely necessary, but renumber anyhow // this is not absolutely necessary, but renumber anyhow
nPoints = 0; nPoints = 0;
@ -250,6 +82,58 @@ Foam::ensightPart::localPoints Foam::ensightPartFaces::calcLocalPoints() const
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::ensightPartFaces::ensightPartFaces
(
label partIndex,
const string& description,
const pointField& points,
const faceList& faces,
const bool contiguousPoints
)
:
ensightFaces(partIndex),
ensightPart(description),
start_(0),
patchIndex_(-1),
faces_(faces),
points_(points),
contiguousPoints_(contiguousPoints)
{
// classify the face shapes
classify(faces);
}
Foam::ensightPartFaces::ensightPartFaces
(
label partIndex,
const polyMesh& mesh,
const polyPatch& patch
)
:
ensightFaces(partIndex),
ensightPart(patch.name()),
start_(patch.start()),
patchIndex_(patch.index()),
faces_(mesh.faces()),
points_(mesh.points()),
contiguousPoints_(false)
{
// classify the face shapes
classify(patch);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::ensightPartFaces::~ensightPartFaces()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::ensightPartFaces::writeConnectivity void Foam::ensightPartFaces::writeConnectivity
( (
ensightGeoFile& os, ensightGeoFile& os,
@ -259,6 +143,8 @@ void Foam::ensightPartFaces::writeConnectivity
const labelUList& pointMap const labelUList& pointMap
) const ) const
{ {
if (idList.empty()) return;
os.writeKeyword(key); os.writeKeyword(key);
os.write(idList.size()); os.write(idList.size());
os.newline(); os.newline();
@ -269,7 +155,7 @@ void Foam::ensightPartFaces::writeConnectivity
// write the number of points per face // write the number of points per face
forAll(idList, i) forAll(idList, i)
{ {
const label id = idList[i] + offset_; const label id = idList[i] + start_;
const face& f = faces[id]; const face& f = faces[id];
os.write(f.size()); os.write(f.size());
@ -280,7 +166,7 @@ void Foam::ensightPartFaces::writeConnectivity
// write the points describing the face // write the points describing the face
forAll(idList, i) forAll(idList, i)
{ {
const label id = idList[i] + offset_; const label id = idList[i] + start_;
const face& f = faces[id]; const face& f = faces[id];
// convert global -> local index // convert global -> local index
@ -313,9 +199,99 @@ void Foam::ensightPartFaces::writeConnectivity
} }
void Foam::ensightPartFaces::writeGeometry(ensightGeoFile& os) const void Foam::ensightPartFaces::write
(
ensightGeoFile& os,
const pointField& points
) const
{ {
ensightPart::writeGeometry(os, points_); if (ensightPart::size())
{
const localPoints ptList = calcLocalPoints();
const labelUList& pointMap = ptList.list;
os.beginPart(index(), name());
os.beginCoordinates(ptList.nPoints);
for (direction cmpt=0; cmpt < point::nComponents; ++cmpt)
{
forAll(pointMap, ptI)
{
if (pointMap[ptI] > -1)
{
os.write(points[ptI].component(cmpt));
os.newline();
}
}
}
// write part
const List<ensightFaces::elemType> enums =
ensightFaces::elemEnum.enums();
forAllConstIter(List<ensightFaces::elemType>, enums, iter)
{
const ensightFaces::elemType what = *iter;
writeConnectivity
(
os,
ensightFaces::key(what),
faceIds(what),
pointMap
);
}
}
}
void Foam::ensightPartFaces::write(ensightGeoFile& os) const
{
this->write(os, points_);
}
void Foam::ensightPartFaces::writeSummary(Ostream& os) const
{
os.beginBlock(type());
os.writeEntry("id", index()+1); // Ensight starts with 1
os.writeEntry("name", name());
os.writeEntry("start", start_);
os.writeEntry("size", size());
os.endBlock() << flush;
}
void Foam::ensightPartFaces::dumpInfo(Ostream& os) const
{
os.beginBlock(type());
os.writeEntry("id", index()+1); // Ensight starts with 1
os.writeEntry("name", name());
os.writeEntry("start", start_);
os.writeEntry("size", size());
const List<ensightFaces::elemType> enums = ensightFaces::elemEnum.enums();
forAllConstIter(List<ensightFaces::elemType>, enums, iter)
{
const ensightFaces::elemType what = *iter;
const labelUList& addr = this->faceIds(what);
os.writeKeyword(ensightFaces::key(what));
// DIY flat output
os << addr.size() << '(';
forAll(addr, i)
{
if (i) os << ' ';
os << addr[i];
}
os << ')' << endEntry;
}
os.endBlock() << flush;
} }

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -25,7 +25,7 @@ Class
Foam::ensightPartFaces Foam::ensightPartFaces
Description Description
An implementation of ensightPart to hold volume mesh faces. An implementation of ensightPart to hold mesh faces.
SourceFiles SourceFiles
ensightPartFaces.C ensightPartFaces.C
@ -36,6 +36,8 @@ SourceFiles
#define ensightPartFaces_H #define ensightPartFaces_H
#include "ensightPart.H" #include "ensightPart.H"
#include "ensightFaces.H"
#include "typeInfo.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -48,18 +50,34 @@ namespace Foam
class ensightPartFaces class ensightPartFaces
: :
public ensightFaces,
public ensightPart public ensightPart
{ {
// Private data
//- Start offset for patch
const label start_;
//- Patch index
const label patchIndex_;
//- Faces referenced
const faceList& faces_;
//- pointField referenced
const pointField& points_;
//- Can skip local point renumbering when points are contiguous
const bool contiguousPoints_;
// Private Member Functions // Private Member Functions
//- Disallow default bitwise assignment
void operator=(const ensightPartFaces&);
//- Track points used //- Track points used
virtual localPoints calcLocalPoints() const; localPoints calcLocalPoints() const;
//- Element connectivity //- Element connectivity
virtual void writeConnectivity void writeConnectivity
( (
ensightGeoFile&, ensightGeoFile&,
const word& key, const word& key,
@ -68,36 +86,6 @@ class ensightPartFaces
) const; ) const;
protected:
//- Addressable ensight element types
enum elemType
{
tria3Elements,
quad4Elements,
nsidedElements
};
// Static data members
static const List<word> elemTypes_;
// Protected data
//- Faces referenced
const faceList& faces_;
//- Can skip local point renumbering when points are contiguous
const bool contiguousPoints_;
// Protected Member Functions
//- Classify the face shapes, set elemLists.
void classify(const faceList&);
//- Helper: write connectivity //- Helper: write connectivity
void writeConnectivity void writeConnectivity
( (
@ -109,22 +97,27 @@ protected:
) const; ) const;
//- Disallow default bitwise copy construct
ensightPartFaces(const ensightPartFaces&) = delete;
//- Disallow default bitwise assignment
void operator=(const ensightPartFaces&) = delete;
public: public:
//- Runtime type information //- Runtime type information
TypeName("ensightFaces"); TypeName("ensightFaces");
// Constructors // Constructors
//- Construct empty part with number and description //- Construct part with 0-based index, description, points and faces
ensightPartFaces(label partNumber, const string& partDescription);
//- Construct part with number, description, points and faces
// Can skip local point renumbering when points are contiguous // Can skip local point renumbering when points are contiguous
ensightPartFaces ensightPartFaces
( (
label partNumber, label partIndex,
const string& partDescription, const string& description,
const pointField&, const pointField&,
const faceList&, const faceList&,
const bool contiguousPoints = false const bool contiguousPoints = false
@ -133,26 +126,11 @@ public:
//- Construct from polyMesh and polyPatch //- Construct from polyMesh and polyPatch
ensightPartFaces ensightPartFaces
( (
label partNumber, label partIndex,
const polyMesh&, const polyMesh&,
const polyPatch& const polyPatch&
); );
//- Construct as copy
ensightPartFaces(const ensightPartFaces&);
//- Reconstruct part characteristics (eg, element types) from Istream
// A part reconstructed in this manner can be used when writing fields,
// but cannot be used to write a new geometry
// \sa Foam::ensightPart::reconstruct
ensightPartFaces(Istream&);
//- Reconstruct part characteristics on freestore from Istream
static autoPtr<ensightPartFaces> New(Istream& is)
{
return autoPtr<ensightPartFaces>(new ensightPartFaces(is));
}
//- Destructor //- Destructor
virtual ~ensightPartFaces(); virtual ~ensightPartFaces();
@ -160,14 +138,44 @@ public:
// Member Functions // Member Functions
//- Write geometry // Access
virtual void writeGeometry(ensightGeoFile&) const;
//- Static listing of the element types //- Part index (0-based)
virtual const List<word>& elementTypes() const virtual label index() const
{ {
return elemTypes_; return ensightFaces::index();
} }
//- Number of elements in this part
virtual label size() const
{
return ensightFaces::size();
}
//- Return the patch index, -1 when not in use.
inline label patchIndex() const
{
return patchIndex_;
}
// Output
//- Write summary information about the object
virtual void writeSummary(Ostream&) const;
//- Write geometry
virtual void write(ensightGeoFile&) const;
//- Helper: write geometry given the pointField
virtual void write(ensightGeoFile&, const pointField&) const;
//- Print various types of debugging information
virtual void dumpInfo(Ostream&) const;
}; };

View File

@ -1,170 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 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/>.
Description
Output for ensightPart
\*---------------------------------------------------------------------------*/
#include "ensightPart.H"
#include "dictionary.H"
#include "IOstreams.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::ensightPart::reconstruct(Istream& is)
{
dictionary dict(is);
dict.lookup("id") >> number_;
dict.lookup("name") >> name_;
offset_ = 0;
dict.readIfPresent("offset", offset_);
// populate elemLists_
elemLists_.setSize(elementTypes().size());
forAll(elementTypes(), elemI)
{
word key(elementTypes()[elemI]);
elemLists_[elemI].clear();
dict.readIfPresent(key, elemLists_[elemI]);
size_ += elemLists_[elemI].size();
}
is.check("ensightPart::reconstruct(Istream&)");
}
bool Foam::ensightPart::writeSummary(Ostream& os) const
{
os << indent << type() << nl
<< indent << token::BEGIN_BLOCK << incrIndent << nl;
// Ensight starts with 1
os.writeKeyword("id") << (number() + 1) << token::END_STATEMENT << nl;
os.writeKeyword("name") << name() << token::END_STATEMENT << nl;
os.writeKeyword("offset") << offset() << token::END_STATEMENT << nl;
os.writeKeyword("size") << size() << token::END_STATEMENT << nl;
os << decrIndent << indent << token::END_BLOCK << nl << endl;
return true;
}
bool Foam::ensightPart::writeData(Ostream& os) const
{
os << indent << type() << nl
<< indent << token::BEGIN_BLOCK << incrIndent << nl;
os.writeKeyword("id") << number() << token::END_STATEMENT << nl;
os.writeKeyword("name") << name() << token::END_STATEMENT << nl;
os.writeKeyword("offset") << offset() << token::END_STATEMENT << nl;
forAll(elementTypes(), typeI)
{
word key(elementTypes()[typeI]);
if (elemLists_[typeI].size())
{
elemLists_[typeI].writeEntry(key, os);
}
}
os << decrIndent << indent << token::END_BLOCK << nl << endl;
return true;
}
void Foam::ensightPart::writeGeometry
(
ensightGeoFile& os,
const pointField& points
) const
{
if (size())
{
const localPoints ptList = calcLocalPoints();
const labelUList& pointMap = ptList.list;
os.beginPart(number(), name());
os.beginCoordinates(ptList.nPoints);
for (direction cmpt=0; cmpt < point::nComponents; ++cmpt)
{
forAll(pointMap, ptI)
{
if (pointMap[ptI] > -1)
{
os.write(points[ptI].component(cmpt));
os.newline();
}
}
}
// write parts
forAll(elementTypes(), elemI)
{
if (elemLists_[elemI].size())
{
writeConnectivity
(
os,
elementTypes()[elemI],
elemLists_[elemI],
pointMap
);
}
}
}
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Foam::Ostream& Foam::operator<<
(
Ostream& os,
const ensightPart& part
)
{
part.writeData(os);
return os;
}
Foam::ensightGeoFile& Foam::operator<<
(
ensightGeoFile& os,
const ensightPart& part
)
{
part.writeGeometry(os);
return os;
}
// ************************************************************************* //

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -29,21 +29,12 @@ License
Foam::ensightParts::ensightParts(const polyMesh& mesh) Foam::ensightParts::ensightParts(const polyMesh& mesh)
: :
partsList_() StorageType()
{ {
recalculate(mesh); recalculate(mesh);
} }
Foam::ensightParts::ensightParts(const IOobject& ioObj)
:
partsList_()
{
IOPtrList<ensightPart> ioList(ioObj);
partsList_.transfer(ioList);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::ensightParts::~ensightParts() Foam::ensightParts::~ensightParts()
@ -54,19 +45,9 @@ Foam::ensightParts::~ensightParts()
void Foam::ensightParts::recalculate(const polyMesh& mesh) void Foam::ensightParts::recalculate(const polyMesh& mesh)
{ {
partsList_.clear(); StorageType::clear();
// extra space for unzoned cells
label nPart =
(
mesh.cellZones().size()
+ mesh.boundaryMesh().size()
+ 1
);
partsList_.setSize(nPart);
nPart = 0;
label nPart = 0;
label nZoneCells = 0; label nZoneCells = 0;
// do cell zones // do cell zones
@ -77,13 +58,7 @@ void Foam::ensightParts::recalculate(const polyMesh& mesh)
if (cZone.size()) if (cZone.size())
{ {
partsList_.set this->append(new ensightPartCells(nPart++, mesh, cZone));
(
nPart,
new ensightPartCells(nPart, mesh, cZone)
);
nPart++;
} }
} }
@ -92,13 +67,7 @@ void Foam::ensightParts::recalculate(const polyMesh& mesh)
// special case: no zones at all - do entire mesh // special case: no zones at all - do entire mesh
if (nZoneCells == 0) if (nZoneCells == 0)
{ {
partsList_.set this->append(new ensightPartCells(nPart++, mesh));
(
nPart,
new ensightPartCells(nPart, mesh)
);
nPart++;
} }
else if (mesh.nCells() > nZoneCells) else if (mesh.nCells() > nZoneCells)
{ {
@ -128,13 +97,7 @@ void Foam::ensightParts::recalculate(const polyMesh& mesh)
if (unzoned.size()) if (unzoned.size())
{ {
partsList_.set this->append(new ensightPartCells(nPart++, mesh, unzoned));
(
nPart,
new ensightPartCells(nPart, mesh, unzoned)
);
nPart++;
} }
} }
@ -145,96 +108,41 @@ void Foam::ensightParts::recalculate(const polyMesh& mesh)
const polyPatch& patch = mesh.boundaryMesh()[patchi]; const polyPatch& patch = mesh.boundaryMesh()[patchi];
if (patch.size() && !isA<processorPolyPatch>(patch)) if (patch.size() && !isA<processorPolyPatch>(patch))
{ {
partsList_.set this->append(new ensightPartFaces(nPart++, mesh, patch));
( }
nPart,
new ensightPartFaces(nPart, mesh, patch)
);
nPart++;
} }
} }
// truncate to correct size
partsList_.setSize(nPart);
}
void Foam::ensightParts::write(ensightGeoFile& os) const
void Foam::ensightParts::renumber
(
const labelUList& origCellId,
const labelUList& origFaceId
)
{ {
forAll(partsList_, partI) // Some feedback
{ Info<< "Write geometry part (" << flush;
if (partsList_[partI].isCellData())
{
partsList_[partI].renumber(origCellId);
}
else
{
partsList_[partI].renumber(origFaceId);
}
}
}
forAllConstIter(StorageType, *this, iter)
void Foam::ensightParts::writeGeometry(ensightGeoFile& os) const
{ {
// with some feedback Info<< ' ' << (*iter).index() << flush;
Info<< "write geometry part (" << flush; (*iter).write(os);
forAll(partsList_, partI)
{
Info<< " " << partI << flush;
partsList_[partI].writeGeometry(os);
} }
Info<< " )" << endl; Info<< " )" << endl;
} }
bool Foam::ensightParts::writeSummary(Ostream& os) const void Foam::ensightParts::writeSummary(Ostream& os) const
{ {
forAll(partsList_, partI) forAllConstIter(StorageType, *this, iter)
{ {
partsList_[partI].writeSummary(os); (*iter).writeSummary(os);
} }
return true;
} }
void Foam::ensightParts::writeData(Ostream& os) const void Foam::ensightParts::dumpInfo(Ostream& os) const
{ {
// Begin write list forAllConstIter(StorageType, *this, iter)
os << nl << partsList_.size()
<< nl << token::BEGIN_LIST;
// Write list contents
forAll(partsList_, i)
{ {
os << nl << partsList_[i]; (*iter).dumpInfo(os);
} }
// End write list
os << nl << token::END_LIST << nl;
// Check state of IOstream
os.check("ensightParts::writeData(Ostream&)");
}
// * * * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * //
Foam::ensightGeoFile& Foam::operator<<
(
ensightGeoFile& os,
const ensightParts& parts
)
{
parts.writeGeometry(os);
return os;
} }

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -29,13 +29,13 @@ Description
SourceFiles SourceFiles
ensightParts.C ensightParts.C
ensightPartsTemplates.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef ensightParts_H #ifndef ensightParts_H
#define ensightParts_H #define ensightParts_H
#include "SLPtrList.H"
#include "ensightPart.H" #include "ensightPart.H"
#include "ensightPartFaces.H" #include "ensightPartFaces.H"
#include "ensightPartCells.H" #include "ensightPartCells.H"
@ -46,43 +46,34 @@ SourceFiles
namespace Foam namespace Foam
{ {
// Forward declaration of friend functions and operators
class ensightParts;
ensightGeoFile& operator<<(ensightGeoFile&, const ensightParts&);
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class ensightParts Declaration Class ensightParts Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class ensightParts class ensightParts
:
public SLPtrList<ensightPart>
{ {
// Private Data
//- List of parts
PtrList<ensightPart> partsList_;
// Private Member Functions // Private Member Functions
//- Disallow default bitwise copy construct //- Disallow default bitwise copy construct
ensightParts(const ensightParts&); ensightParts(const ensightParts&) = delete;
//- Disallow default bitwise assignment //- Disallow default bitwise assignment
void operator=(const ensightParts&); void operator=(const ensightParts&) = delete;
public: public:
//- Storage type used
typedef SLPtrList<ensightPart> StorageType;
// Constructors // Constructors
//- Construct from polyMesh //- Construct from polyMesh
ensightParts(const polyMesh&); ensightParts(const polyMesh&);
//- Construct from IOobject
ensightParts(const IOobject&);
//- Destructor //- Destructor
~ensightParts(); ~ensightParts();
@ -93,41 +84,19 @@ public:
//- Clear old information and construct anew from polyMesh //- Clear old information and construct anew from polyMesh
void recalculate(const polyMesh&); void recalculate(const polyMesh&);
//- Renumber elements
void renumber
(
const labelUList& origCellId,
const labelUList& origFaceId
);
//- Number of parts //- Number of parts
label size() const using StorageType::size;
{
return partsList_.size();
}
//- Write the geometry //- Write the geometry
void writeGeometry(ensightGeoFile&) const; void write(ensightGeoFile&) const;
//- Write summary information about the objects //- Write summary information about the objects
bool writeSummary(Ostream&) const; void writeSummary(Ostream&) const;
//- Write the lists //- Print various types of debugging information
void writeData(Ostream&) const; void dumpInfo(Ostream&) const;
//- Write generalized volume field components
template<class Type>
void writeField
(
ensightFile&,
const GeometricField<Type, fvPatchField, volMesh>&
) const;
// Friend Operators
//- Write geometry
friend ensightGeoFile& operator<<(ensightGeoFile&, const ensightParts&);
}; };
@ -137,10 +106,6 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "ensightPartsTemplates.C"
#endif
#endif #endif
// ************************************************************************* // // ************************************************************************* //

View File

@ -1,75 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ 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/>.
Description
Template to write generalized field components
\*---------------------------------------------------------------------------*/
#include "ensightParts.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
void Foam::ensightParts::writeField
(
ensightFile& os,
const GeometricField<Type, fvPatchField, volMesh>& field
) const
{
// find offset to patch parts (ie, the first face data)
label patchOffset = 0;
forAll(partsList_, partI)
{
if (partsList_[partI].isFaceData())
{
patchOffset = partI;
break;
}
}
forAll(partsList_, partI)
{
label patchi = partI - patchOffset;
if (partsList_[partI].isCellData())
{
partsList_[partI].writeField
(
os,
field
);
}
else if (patchi < field.boundaryField().size())
{
partsList_[partI].writeField
(
os,
field.boundaryField()[patchi]
);
}
}
}
// ************************************************************************* //

View File

@ -28,6 +28,7 @@ License
#include "OFstream.H" #include "OFstream.H"
#include "OSspecific.H" #include "OSspecific.H"
#include "ensightPartFaces.H" #include "ensightPartFaces.H"
#include "ensightSerialOutput.H"
#include "ensightPTraits.H" #include "ensightPTraits.H"
#include "OStringStream.H" #include "OStringStream.H"
#include "regExp.H" #include "regExp.H"
@ -121,7 +122,13 @@ Foam::fileName Foam::ensightSurfaceWriter::writeUncollated
// Write field // Write field
osField.writeKeyword(ensightPTraits<Type>::typeName); osField.writeKeyword(ensightPTraits<Type>::typeName);
ensPart.writeField(osField, values, isNodeValues); ensightSerialOutput::writeField
(
values,
ensPart,
osField,
isNodeValues
);
return osCase.name(); return osCase.name();
} }
@ -337,12 +344,21 @@ Foam::fileName Foam::ensightSurfaceWriter::writeCollated
varName, varName,
writeFormat_ writeFormat_
); );
if (verbose) if (verbose)
{ {
Info<< "Writing field file to " << osField.name() << endl; Info<< "Writing field file to " << osField.name() << endl;
} }
// Write field
osField.writeKeyword(ensightPTraits<Type>::typeName); osField.writeKeyword(ensightPTraits<Type>::typeName);
ensPart.writeField(osField, values, isNodeValues); ensightSerialOutput::writeField
(
values,
ensPart,
osField,
isNodeValues
);
// place a timestamp in the directory for future reference // place a timestamp in the directory for future reference
{ {