sampledSurface::writers: Added writeFormat option to select ascii or binary

e.g. in tutorials/incompressible/pisoFoam/LES/motorBike/motorBike/system/cuttingPlane

    surfaceFormat   vtk;
    writeFormat     binary;
    fields          (p U);

selects writing the VTK surface files in binary format which significantly
speeds-up reading of the files in paraview.

Currently binary writing is supported in VTK and EnSight formats.
This commit is contained in:
Henry Weller
2020-01-29 14:59:31 +00:00
parent ccc8a78ec1
commit b55bc28698
12 changed files with 53 additions and 54 deletions

View File

@ -525,12 +525,7 @@ void Foam::functionObjects::fieldValues::surfaceFieldValue::initialise
surfaceWriterPtr_.reset surfaceWriterPtr_.reset
( (
surfaceWriter::New surfaceWriter::New(surfaceFormat, dict).ptr()
(
surfaceFormat,
dict.subOrEmptyDict("formatOptions").
subOrEmptyDict(surfaceFormat)
).ptr()
); );
} }
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -194,12 +194,7 @@ void Foam::FacePostProcessing<CloudType>::write()
autoPtr<surfaceWriter> writer autoPtr<surfaceWriter> writer
( (
surfaceWriter::New surfaceWriter::New(surfaceFormat_, this->coeffDict())
(
surfaceFormat_,
this->coeffDict().subOrEmptyDict("formatOptions").
subOrEmptyDict(surfaceFormat_)
)
); );
writer->write writer->write

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -241,12 +241,7 @@ bool Foam::sampledSurfaces::read(const dictionary& dict)
const word writeType(dict.lookup("surfaceFormat")); const word writeType(dict.lookup("surfaceFormat"));
// Define the surface formatter // Define the surface formatter
// Optionally defined extra controls for the output formats formatter_ = surfaceWriter::New(writeType, dict);
formatter_ = surfaceWriter::New
(
writeType,
dict.subOrEmptyDict("formatOptions").subOrEmptyDict(writeType)
);
PtrList<sampledSurface> newList PtrList<sampledSurface> newList
( (

View File

@ -37,15 +37,15 @@ namespace Foam
defineSurfaceWriterWriteFields(nastranSurfaceWriter); defineSurfaceWriterWriteFields(nastranSurfaceWriter);
template<> template<>
const char* NamedEnum<nastranSurfaceWriter::writeFormat, 3>::names[] = const char* NamedEnum<nastranSurfaceWriter::format, 3>::names[] =
{ {
"short", "short",
"long", "long",
"free" "free"
}; };
const NamedEnum<nastranSurfaceWriter::writeFormat, 3> const NamedEnum<nastranSurfaceWriter::format, 3>
nastranSurfaceWriter::writeFormatNames_; nastranSurfaceWriter::formatNames_;
} }
@ -60,7 +60,7 @@ void Foam::nastranSurfaceWriter::formatOS(OFstream& os) const
label prec = 0; label prec = 0;
label offset = 7; label offset = 7;
switch (writeFormat_) switch (format_)
{ {
case (wfShort): case (wfShort):
case (wfFree): case (wfFree):
@ -100,7 +100,7 @@ void Foam::nastranSurfaceWriter::writeCoord
// 8 PS : single point constraints (blank) // 8 PS : single point constraints (blank)
// 9 SEID : super-element ID // 9 SEID : super-element ID
switch (writeFormat_) switch (format_)
{ {
case wfShort: case wfShort:
{ {
@ -155,7 +155,7 @@ void Foam::nastranSurfaceWriter::writeCoord
default: default:
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Unknown writeFormat enumeration" << abort(FatalError); << "Unknown format enumeration" << abort(FatalError);
} }
} }
} }
@ -182,7 +182,7 @@ void Foam::nastranSurfaceWriter::writeFace
// For CTRIA3 elements, cols 7 onwards are not used // For CTRIA3 elements, cols 7 onwards are not used
switch (writeFormat_) switch (format_)
{ {
case wfShort: case wfShort:
{ {
@ -248,7 +248,7 @@ void Foam::nastranSurfaceWriter::writeFace
default: default:
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Unknown writeFormat enumeration" << abort(FatalError); << "Unknown format enumeration" << abort(FatalError);
} }
} }
@ -322,7 +322,7 @@ Foam::nastranSurfaceWriter::nastranSurfaceWriter
) )
: :
surfaceWriter(writeFormat), surfaceWriter(writeFormat),
writeFormat_(wfShort), format_(wfShort),
fieldMap_(), fieldMap_(),
scale_(1.0) scale_(1.0)
{} {}
@ -331,21 +331,28 @@ Foam::nastranSurfaceWriter::nastranSurfaceWriter
Foam::nastranSurfaceWriter::nastranSurfaceWriter(const dictionary& optDict) Foam::nastranSurfaceWriter::nastranSurfaceWriter(const dictionary& optDict)
: :
surfaceWriter(optDict), surfaceWriter(optDict),
writeFormat_(wfLong), format_(wfLong),
fieldMap_(), fieldMap_(),
scale_(optDict.lookupOrDefault("scale", 1.0)) scale_(1.0)
{ {
if (optDict.found("format")) const dictionary& nastranDict(optDict.lookup("nastranOptions"));
if (nastranDict.found("format"))
{ {
writeFormat_ = writeFormatNames_.read(optDict.lookup("format")); format_ = formatNames_.read(nastranDict.lookup("format"));
} }
List<Tuple2<word, word>> fieldSet(optDict.lookup("fields")); List<Tuple2<word, word>> fieldSet(nastranDict.lookup("fields"));
forAll(fieldSet, i) forAll(fieldSet, i)
{ {
fieldMap_.insert(fieldSet[i].first(), fieldSet[i].second()); fieldMap_.insert(fieldSet[i].first(), fieldSet[i].second());
} }
if (nastranDict.found("scale"))
{
nastranDict.lookup("scale") >> scale_;
}
} }

View File

@ -27,18 +27,17 @@ Class
Description Description
A surface writer for the Nastran file format - both surface mesh and fields A surface writer for the Nastran file format - both surface mesh and fields
formatOptions nastranOptions
{
nastran
{ {
// From OpenFOAM field name to Nastran field name // From OpenFOAM field name to Nastran field name
fields ((pMean PLOAD2)); fields ((pMean PLOAD2));
// Optional scale // Optional scale
scale 2.0; scale 2.0;
// Optional format // Optional format
format free; // short, long, free format free; // short, long, free
} }
};
SourceFiles SourceFiles
nastranSurfaceWriter.C nastranSurfaceWriter.C
@ -68,14 +67,14 @@ class nastranSurfaceWriter
{ {
public: public:
enum writeFormat enum format
{ {
wfShort, wfShort,
wfLong, wfLong,
wfFree wfFree
}; };
static const NamedEnum<writeFormat, 3> writeFormatNames_; static const NamedEnum<format, 3> formatNames_;
private: private:
@ -83,7 +82,7 @@ private:
// Private Data // Private Data
//- Write option //- Write option
writeFormat writeFormat_; format format_;
//- Map of OpenFOAM field name vs nastran field name //- Map of OpenFOAM field name vs nastran field name
HashTable<word> fieldMap_; HashTable<word> fieldMap_;

View File

@ -48,7 +48,7 @@ void Foam::nastranSurfaceWriter::writeFaceValue
Type scaledValue = scale_*value; Type scaledValue = scale_*value;
switch (writeFormat_) switch (format_)
{ {
case wfShort: case wfShort:
{ {

View File

@ -36,7 +36,6 @@ namespace Foam
makeSurfaceWriterType(vtkSurfaceWriter); makeSurfaceWriterType(vtkSurfaceWriter);
} }
static bool binary = false;
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -45,8 +44,10 @@ void Foam::vtkSurfaceWriter::writeGeometry
std::ostream& os, std::ostream& os,
const pointField& points, const pointField& points,
const faceList& faces const faceList& faces
) ) const
{ {
const bool binary = (writeFormat_ == IOstream::BINARY);
// VTK header // VTK header
vtkWriteOps::writeHeader(os, binary, "sampleSurface"); vtkWriteOps::writeHeader(os, binary, "sampleSurface");
os << "DATASET POLYDATA" << nl; os << "DATASET POLYDATA" << nl;
@ -103,6 +104,8 @@ void Foam::vtkSurfaceWriter::Write
const bool isNodeValues const bool isNodeValues
) const ) const
{ {
const bool binary = (writeFormat_ == IOstream::BINARY);
if (!isDir(outputDir)) if (!isDir(outputDir))
{ {
mkDir(outputDir); mkDir(outputDir);

View File

@ -25,7 +25,8 @@ Class
Foam::vtkSurfaceWriter Foam::vtkSurfaceWriter
Description Description
A surfaceWriter for VTK legacy format. A surfaceWriter for VTK legacy format
with support for writing ASCII or binary.
SourceFiles SourceFiles
vtkSurfaceWriter.C vtkSurfaceWriter.C
@ -52,12 +53,12 @@ class vtkSurfaceWriter
{ {
// Private Member Functions // Private Member Functions
static void writeGeometry void writeGeometry
( (
std::ostream&, std::ostream&,
const pointField&, const pointField&,
const faceList& const faceList&
); ) const;
//- Templated write operation //- Templated write operation
template<class Type> template<class Type>

View File

@ -13,6 +13,7 @@ surfaces
writeControl writeTime; writeControl writeTime;
surfaceFormat vtk; surfaceFormat vtk;
writeFormat binary;
fields (p U Q); fields (p U Q);
interpolationScheme cellPoint; interpolationScheme cellPoint;

View File

@ -14,6 +14,7 @@ cuttingPlane
writeControl writeTime; writeControl writeTime;
surfaceFormat vtk; surfaceFormat vtk;
fields ( p U ); fields ( p U );
interpolationScheme cellPoint; interpolationScheme cellPoint;

View File

@ -13,6 +13,7 @@ cuttingPlane
writeControl writeTime; writeControl writeTime;
surfaceFormat vtk; surfaceFormat vtk;
writeFormat binary;
fields (p U); fields (p U);
interpolationScheme cellPoint; interpolationScheme cellPoint;

View File

@ -66,6 +66,7 @@ functions
startTime 10; startTime 10;
surfaceFormat vtk; surfaceFormat vtk;
writeFormat binary;
fields (p_rgh U); fields (p_rgh U);
interpolationScheme cellPoint; interpolationScheme cellPoint;