From faac56c1de44bb88f4246d8903ff5fffdcf6f7d0 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@Germany> Date: Fri, 28 Jan 2011 19:20:22 +0100 Subject: [PATCH] ENH: ensight binary surface output, formatOptions in sampleDict - For example, // optionally define extra controls for the output formats formatOptions { ensight { format binary; } } These are passed to the writer that support a dictionary of options. Otherwise the normal null constructor is used. --- .../postProcessing/sampling/sample/sampleDict | 10 ++++++++++ .../sampledSurfaces/sampledSurfaces.C | 10 +++++++--- .../writers/ensight/ensightSurfaceWriter.C | 14 ++++++++++++++ .../writers/ensight/ensightSurfaceWriter.H | 3 +++ .../sampledSurface/writers/surfaceWriter.C | 18 ++++++++++++++++++ .../sampledSurface/writers/surfaceWriter.H | 19 +++++++++++++++++++ 6 files changed, 71 insertions(+), 3 deletions(-) diff --git a/applications/utilities/postProcessing/sampling/sample/sampleDict b/applications/utilities/postProcessing/sampling/sample/sampleDict index cd0ae63fe4d..c34ce71daf9 100644 --- a/applications/utilities/postProcessing/sampling/sample/sampleDict +++ b/applications/utilities/postProcessing/sampling/sample/sampleDict @@ -38,6 +38,16 @@ setFormat raw; // but without any values! surfaceFormat vtk; +// optionally define extra controls for the output formats +formatOptions +{ + ensight + { + format ascii; + } +} + + // interpolationScheme. choice of // cell : use cell-centre value only; constant over cells (default) // cellPoint : use cell-centre and vertex values diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C index a4c34132141..581b7e206bb 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C @@ -220,11 +220,15 @@ void Foam::sampledSurfaces::read(const dictionary& dict) clearFieldGroups(); dict.lookup("interpolationScheme") >> interpolationScheme_; - - word writeType(dict.lookup("surfaceFormat")); + const word writeType(dict.lookup("surfaceFormat")); // define the surface formatter - formatter_ = surfaceWriter::New(writeType); + // optionally defined extra controls for the output formats + formatter_ = surfaceWriter::New + ( + writeType, + dict.subOrEmptyDict("formatOptions").subOrEmptyDict(writeType) + ); PtrList<sampledSurface> newList ( diff --git a/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.C b/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.C index 135d566db09..d83ec611a10 100644 --- a/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.C @@ -37,6 +37,7 @@ License namespace Foam { makeSurfaceWriterType(ensightSurfaceWriter); + addToRunTimeSelectionTable(surfaceWriter, ensightSurfaceWriter, wordDict); } @@ -120,6 +121,19 @@ Foam::ensightSurfaceWriter::ensightSurfaceWriter() {} +Foam::ensightSurfaceWriter::ensightSurfaceWriter(const dictionary& options) +: + surfaceWriter(), + writeFormat_(IOstream::ASCII) +{ + // choose ascii or binary format + if (options.found("format")) + { + writeFormat_ = IOstream::formatEnum(options.lookup("format")); + } +} + + // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // Foam::ensightSurfaceWriter::~ensightSurfaceWriter() diff --git a/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.H b/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.H index 891947ffb47..628c178d4e6 100644 --- a/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.H @@ -84,6 +84,9 @@ public: //- Construct null ensightSurfaceWriter(); + //- Construct with some output options + ensightSurfaceWriter(const dictionary& options); + //- Destructor virtual ~ensightSurfaceWriter(); diff --git a/src/sampling/sampledSurface/writers/surfaceWriter.C b/src/sampling/sampledSurface/writers/surfaceWriter.C index 0f52c6f4aa8..f297e0934fa 100644 --- a/src/sampling/sampledSurface/writers/surfaceWriter.C +++ b/src/sampling/sampledSurface/writers/surfaceWriter.C @@ -38,6 +38,7 @@ namespace Foam { defineTypeNameAndDebug(surfaceWriter, 0); defineRunTimeSelectionTable(surfaceWriter, word); + defineRunTimeSelectionTable(surfaceWriter, wordDict); addNamedToRunTimeSelectionTable ( surfaceWriter, @@ -83,6 +84,23 @@ Foam::surfaceWriter::New(const word& writeType) } +Foam::autoPtr<Foam::surfaceWriter> +Foam::surfaceWriter::New(const word& writeType, const dictionary& optDict) +{ + // find constructors with dictionary options + wordDictConstructorTable::iterator cstrIter = + wordDictConstructorTablePtr_->find(writeType); + + if (cstrIter == wordDictConstructorTablePtr_->end()) + { + // revert to versions without options + return Foam::surfaceWriter::New(writeType); + } + + return autoPtr<surfaceWriter>(cstrIter()(optDict)); +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::surfaceWriter::surfaceWriter() diff --git a/src/sampling/sampledSurface/writers/surfaceWriter.H b/src/sampling/sampledSurface/writers/surfaceWriter.H index 8e24418d392..be265178499 100644 --- a/src/sampling/sampledSurface/writers/surfaceWriter.H +++ b/src/sampling/sampledSurface/writers/surfaceWriter.H @@ -70,12 +70,31 @@ public: () ); + declareRunTimeSelectionTable + ( + autoPtr, + surfaceWriter, + wordDict, + ( + const dictionary& optDict + ), + (optDict) + ); + // Selectors //- Return a reference to the selected surfaceWriter static autoPtr<surfaceWriter> New(const word& writeType); + //- Return a reference to the selected surfaceWriter + // Select with extra write option + static autoPtr<surfaceWriter> New + ( + const word& writeType, + const dictionary& writeOptions + ); + // Constructors -- GitLab