ENH: Added finiteArea support to foamToVTK

This commit is contained in:
Andrew Heather
2017-11-21 16:33:33 +00:00
committed by Andrew Heather
parent a14eb71160
commit c2ff8ea99e
14 changed files with 316 additions and 88 deletions

View File

@ -97,25 +97,6 @@ using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// file-scope helper
static bool inFileNameList
(
const fileNameList& nameList,
const word& name
)
{
forAll(nameList, i)
{
if (nameList[i] == name)
{
return true;
}
}
return false;
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
timeSelector::addOptions(); timeSelector::addOptions();
@ -641,7 +622,7 @@ int main(int argc, char *argv[])
Info<< "Write " << cloudName << " ("; Info<< "Write " << cloudName << " (";
bool cloudExists = inFileNameList(currentCloudDirs, cloudName); bool cloudExists = currentCloudDirs.found(cloudName);
reduce(cloudExists, orOp<bool>()); reduce(cloudExists, orOp<bool>());
{ {

View File

@ -3,11 +3,13 @@ EXE_INC = \
-I$(LIB_SRC)/conversion/lnInclude \ -I$(LIB_SRC)/conversion/lnInclude \
-I$(LIB_SRC)/lagrangian/basic/lnInclude \ -I$(LIB_SRC)/lagrangian/basic/lnInclude \
-I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/finiteArea/lnInclude \
-I$(LIB_SRC)/dynamicMesh/lnInclude \ -I$(LIB_SRC)/dynamicMesh/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude -I$(LIB_SRC)/meshTools/lnInclude
EXE_LIBS = \ EXE_LIBS = \
-lconversion \ -lconversion \
-ldynamicMesh \ -ldynamicMesh \
-lfiniteArea \
-llagrangian \ -llagrangian \
-lgenericPatchFields -lgenericPatchFields

View File

@ -155,6 +155,7 @@ Note
#include "Cloud.H" #include "Cloud.H"
#include "passiveParticle.H" #include "passiveParticle.H"
#include "stringOps.H" #include "stringOps.H"
#include "areaFields.H"
#include "meshSubsetHelper.H" #include "meshSubsetHelper.H"
#include "readFields.H" #include "readFields.H"
@ -862,6 +863,119 @@ int main(int argc, char *argv[])
); );
// Finite-area mesh and fields - need not exist
autoPtr<faMesh> aMeshPtr;
{
const bool throwing = FatalError.throwExceptions();
try
{
aMeshPtr.reset(new faMesh(meshRef.baseMesh()));
}
catch (Foam::error& err)
{
aMeshPtr.clear();
}
FatalError.throwExceptions(throwing);
}
if (aMeshPtr.valid())
{
// Construct the area fields
PtrList<const areaScalarField> aScalarFld;
PtrList<const areaVectorField> aVectorFld;
PtrList<const areaSphericalTensorField> aSphTensorf;
PtrList<const areaSymmTensorField> aSymTensorFld;
PtrList<const areaTensorField> aTensorFld;
const faMesh& aMesh = aMeshPtr();
if (!specifiedFields || selectedFields.size())
{
readFields
(
aMesh,
objects,
selectedFields,
aScalarFld
);
print(" areaScalar :", Info, aScalarFld);
readFields
(
aMesh,
objects,
selectedFields,
aVectorFld
);
print(" areaVector :", Info, aVectorFld);
readFields
(
aMesh,
objects,
selectedFields,
aSphTensorf
);
print(" areaSphericalTensor :", Info, aSphTensorf);
readFields
(
aMesh,
objects,
selectedFields,
aSymTensorFld
);
print(" areaSymmTensor :", Info, aSymTensorFld);
readFields
(
aMesh,
objects,
selectedFields,
aTensorFld
);
print(" areaTensor :", Info, aTensorFld);
}
const label nAreaFields =
(
aScalarFld.size()
+ aVectorFld.size()
+ aSphTensorf.size()
+ aSymTensorFld.size()
+ aTensorFld.size()
);
fileName outputName(fvPath/"finiteArea");
mkDir(outputName);
const auto& pp = aMesh.patch();
vtk::surfaceMeshWriter writer
(
pp,
aMesh.name(),
outputName/"finiteArea" + "_" + timeDesc,
fmtType
);
// Number of fields
writer.beginCellData(nAreaFields);
writer.write(aScalarFld);
writer.write(aVectorFld);
writer.write(aSphTensorf);
writer.write(aSymTensorFld);
writer.write(aTensorFld);
writer.endCellData();
writer.writeFooter();
}
PtrList<const pointScalarField> pScalarFld; PtrList<const pointScalarField> pScalarFld;
PtrList<const pointVectorField> pVectorFld; PtrList<const pointVectorField> pVectorFld;
PtrList<const pointSphericalTensorField> pSphTensorFld; PtrList<const pointSphericalTensorField> pSphTensorFld;

View File

@ -72,6 +72,38 @@ label readFields
} }
template<class GeoField>
void readFields
(
const typename GeoField::Mesh& mesh,
const IOobjectList& objects,
const HashSet<word>& selectedFields,
PtrList<const GeoField>& fields
)
{
// Search list of objects for fields of type GeomField
IOobjectList fieldObjects(objects.lookupClass(GeoField::typeName));
// Construct the fields
fields.setSize(fieldObjects.size());
label nFields = 0;
forAllIters(fieldObjects, iter)
{
if (selectedFields.empty() || selectedFields.found(iter()->name()))
{
fields.set
(
nFields++,
new GeoField(*iter(), mesh)
);
}
}
fields.setSize(nFields);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam } // End namespace Foam

View File

@ -1,8 +1,10 @@
EXE_INC = \ EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/finiteArea/lnInclude \
-I$(LIB_SRC)/fileFormats/lnInclude \ -I$(LIB_SRC)/fileFormats/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude -I$(LIB_SRC)/meshTools/lnInclude
LIB_LIBS = \ LIB_LIBS = \
-lfiniteVolume \ -lfiniteVolume \
-lfiniteArea \
-lmeshTools -lmeshTools

View File

@ -40,6 +40,7 @@ SourceFiles
#include "OFstream.H" #include "OFstream.H"
#include "volFields.H" #include "volFields.H"
#include "surfaceFields.H" #include "surfaceFields.H"
#include "areaFields.H"
#include "indirectPrimitivePatch.H" #include "indirectPrimitivePatch.H"
#include "foamVtkOutputOptions.H" #include "foamVtkOutputOptions.H"
@ -152,6 +153,13 @@ public:
const GeometricField<Type, fvsPatchField, surfaceMesh>& field const GeometricField<Type, fvsPatchField, surfaceMesh>& field
); );
//- Write surface field
template<class Type>
void write
(
const GeometricField<Type, faPatchField, areaMesh>& field
);
// Write fields (collectively) // Write fields (collectively)
@ -164,6 +172,16 @@ public:
const GeometricField<Type, fvsPatchField, surfaceMesh> const GeometricField<Type, fvsPatchField, surfaceMesh>
>& sflds >& sflds
); );
//- Write surface fields
template<class Type>
void write
(
const UPtrList
<
const GeometricField<Type, faPatchField, areaMesh>
>& sflds
);
}; };

View File

@ -74,8 +74,7 @@ void Foam::vtk::surfaceMeshWriter::write
} }
else else
{ {
format().openDataArray<float, nCmpt>(field.name()) format().openDataArray<float, nCmpt>(field.name()).closeTag();
.closeTag();
} }
format().writeSize(payLoad); format().writeSize(payLoad);
@ -90,6 +89,36 @@ void Foam::vtk::surfaceMeshWriter::write
} }
template<class Type>
void Foam::vtk::surfaceMeshWriter::write
(
const GeometricField<Type, faPatchField, areaMesh>& field
)
{
const int nCmpt(pTraits<Type>::nComponents);
const uint64_t payLoad(pp_.size() * nCmpt * sizeof(float));
if (legacy_)
{
legacy::floatField(os(), field.name(), nCmpt, pp_.size());
}
else
{
format().openDataArray<float, nCmpt>(field.name()).closeTag();
}
format().writeSize(payLoad);
vtk::writeList(format(), field.primitiveField());
format().flush();
if (!legacy_)
{
format().endDataArray();
}
}
template<class Type> template<class Type>
void Foam::vtk::surfaceMeshWriter::write void Foam::vtk::surfaceMeshWriter::write
( (
@ -106,4 +135,20 @@ void Foam::vtk::surfaceMeshWriter::write
} }
template<class Type>
void Foam::vtk::surfaceMeshWriter::write
(
const UPtrList
<
const GeometricField<Type, faPatchField, areaMesh>
>& sflds
)
{
for (const auto& field : sflds)
{
write(field);
}
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -1,5 +1,6 @@
EXE_INC = \ EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/finiteArea/lnInclude \
-I$(LIB_SRC)/fileFormats/lnInclude \ -I$(LIB_SRC)/fileFormats/lnInclude \
-I$(LIB_SRC)/conversion/lnInclude \ -I$(LIB_SRC)/conversion/lnInclude \
-I$(LIB_SRC)/sampling/lnInclude \ -I$(LIB_SRC)/sampling/lnInclude \
@ -9,6 +10,7 @@ EXE_INC = \
LIB_LIBS = \ LIB_LIBS = \
-lfiniteVolume \ -lfiniteVolume \
-lfiniteArea \
-lconversion \ -lconversion \
-lsampling \ -lsampling \
-lfluidThermophysicalModels \ -lfluidThermophysicalModels \

View File

@ -26,6 +26,7 @@ License
#include "vtkWrite.H" #include "vtkWrite.H"
#include "dictionary.H" #include "dictionary.H"
#include "Time.H" #include "Time.H"
#include "areaFields.H"
#include "foamVtkInternalWriter.H" #include "foamVtkInternalWriter.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
@ -59,12 +60,6 @@ Foam::functionObjects::vtkWrite::vtkWrite
} }
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::vtkWrite::~vtkWrite()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::vtkWrite::read(const dictionary& dict) bool Foam::functionObjects::vtkWrite::read(const dictionary& dict)
@ -125,21 +120,6 @@ bool Foam::functionObjects::vtkWrite::execute()
bool Foam::functionObjects::vtkWrite::write() bool Foam::functionObjects::vtkWrite::write()
{ {
// Count number of fields to be written: only needed for legacy vtk format
label nFields = 0;
if (writeOpts_.legacy())
{
nFields =
(
(writeIds_ ? 1 : 0)
+ countFields<volScalarField>()
+ countFields<volVectorField>()
+ countFields<volSphericalTensorField>()
+ countFields<volSymmTensorField>()
+ countFields<volTensorField>()
);
}
// const word timeDesc = // const word timeDesc =
// useTimeName ? time_.timeName() : Foam::name(time_.timeIndex()); // useTimeName ? time_.timeName() : Foam::name(time_.timeIndex());
@ -165,7 +145,8 @@ bool Foam::functionObjects::vtkWrite::write()
} }
} }
// Create file and write header // internal mesh
{
const fileName outputName const fileName outputName
( (
vtkDir/vtkName vtkDir/vtkName
@ -176,6 +157,21 @@ bool Foam::functionObjects::vtkWrite::write()
Info<< name() << " output Time: " << time_.timeName() << nl Info<< name() << " output Time: " << time_.timeName() << nl
<< " Internal : " << outputName << endl; << " Internal : " << outputName << endl;
// Number of fields to be written: only needed for legacy vtk format
label nVolFields = 0;
if (writeOpts_.legacy())
{
nVolFields =
(
(writeIds_ ? 1 : 0)
+ countFields<volScalarField>()
+ countFields<volVectorField>()
+ countFields<volSphericalTensorField>()
+ countFields<volSymmTensorField>()
+ countFields<volTensorField>()
);
}
vtk::vtuCells vtuMeshCells vtk::vtuCells vtuMeshCells
( (
mesh_, mesh_,
@ -194,7 +190,7 @@ bool Foam::functionObjects::vtkWrite::write()
// CellData // CellData
{ {
writer.beginCellData(nFields); writer.beginCellData(nVolFields);
// Write cellID field // Write cellID field
if (writeIds_) if (writeIds_)
@ -213,6 +209,7 @@ bool Foam::functionObjects::vtkWrite::write()
} }
writer.writeFooter(); writer.writeFooter();
}
return true; return true;
} }

View File

@ -77,6 +77,7 @@ SourceFiles
#include "fvMeshFunctionObject.H" #include "fvMeshFunctionObject.H"
#include "foamVtkInternalWriter.H" #include "foamVtkInternalWriter.H"
#include "foamVtkSurfaceMeshWriter.H"
#include "wordRes.H" #include "wordRes.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -121,6 +122,15 @@ class vtkWrite
label writeFields(vtk::internalWriter& writer, bool verbose=true) const; label writeFields(vtk::internalWriter& writer, bool verbose=true) const;
//- Write selected fields for GeoField type.
template<class GeoField>
label writeFields
(
vtk::surfaceMeshWriter& writer,
bool verbose=true
) const;
//- Disallow default bitwise copy construct //- Disallow default bitwise copy construct
vtkWrite(const vtkWrite&) = delete; vtkWrite(const vtkWrite&) = delete;
@ -146,7 +156,7 @@ public:
//- Destructor //- Destructor
virtual ~vtkWrite(); virtual ~vtkWrite() = default;
// Member Functions // Member Functions

View File

@ -58,4 +58,29 @@ Foam::functionObjects::vtkWrite::writeFields
} }
template<class GeoField>
Foam::label
Foam::functionObjects::vtkWrite::writeFields
(
vtk::surfaceMeshWriter& writer,
bool verbose
) const
{
const wordList names = obr_.sortedNames<GeoField>(selectFields_);
if (verbose && names.size())
{
Info<< " " << GeoField::typeName
<< " " << flatOutput(names) << endl;
}
for (const word& fieldName : names)
{
writer.write(obr_.lookupObject<GeoField>(fieldName));
}
return names.size();
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -37,7 +37,7 @@ writeFormat ascii;
writePrecision 6; writePrecision 6;
writeCompression uncompressed; writeCompression off;
timeFormat general; timeFormat general;

View File

@ -35,7 +35,7 @@ purgeWrite 0;
writeFormat ascii; writeFormat ascii;
writeCompression uncompressed; writeCompression off;
timeFormat general; timeFormat general;

View File

@ -35,7 +35,7 @@ purgeWrite 0;
writeFormat ascii; writeFormat ascii;
writeCompression uncompressed; writeCompression off;
timeFormat general; timeFormat general;