ENH: consolidate 'formatOptions' handling for coordSetWriter/surfaceWriter

- replaced ad hoc handling of formatOptions with coordSetWriter and
  surfaceWriter helpers.

  Accompanying this change, it is now possible to specify "default"
  settings to be inherited, format-specific settings and have a
  similar layering with surface-specific overrides.

- snappyHexMesh now conforms to setFormats

  Eg,

      formatOptions
      {
          default
          {
              verbose     true;
              format      binary;
          }
          vtk
          {
              precision   10;
          }
     }

     surfaces
     {
         surf1
         {
             ...

             formatOptions
             {
                 ensight
                 {
                     scale   1000;
                 }
             }
         }
     }
This commit is contained in:
Mark Olesen
2022-11-08 14:52:58 +01:00
committed by Andrew Heather
parent b7592c1ee8
commit 5b29ff0e42
20 changed files with 336 additions and 84 deletions

View File

@ -58,22 +58,20 @@ namespace Foam
Foam::autoPtr<Foam::coordSetWriter> Foam::sampledSets::newWriter
(
word writeType,
const dictionary& formatOptions,
word writerType,
const dictionary& topDict,
const dictionary& setDict
)
{
// Per-set adjustment
setDict.readIfPresent<word>("setFormat", writeType);
setDict.readIfPresent<word>("setFormat", writerType);
dictionary options = formatOptions.subOrEmptyDict(writeType);
options.merge
return coordSetWriter::New
(
setDict.subOrEmptyDict("formatOptions").subOrEmptyDict(writeType)
writerType,
// Top-level/set-specific "formatOptions"
coordSetWriter::formatOptions(topDict, setDict, writerType)
);
return coordSetWriter::New(writeType, options);
}
@ -338,7 +336,7 @@ void Foam::sampledSets::initDict(const dictionary& dict, const bool initial)
writers_.set
(
seti,
newWriter(writeFormat_, writeFormatOptions_, subDict)
newWriter(writeFormat_, dict_, subDict)
);
// Use outputDir/TIME/set-name
@ -396,7 +394,7 @@ void Foam::sampledSets::initDict(const dictionary& dict, const bool initial)
writers_.set
(
seti,
newWriter(writeFormat_, writeFormatOptions_, subDict)
newWriter(writeFormat_, dict_, subDict)
);
// Use outputDir/TIME/set-name
@ -446,7 +444,6 @@ Foam::sampledSets::sampledSets
searchEngine_(mesh_),
samplePointScheme_(),
writeFormat_(),
writeFormatOptions_(dict.subOrEmptyDict("formatOptions")),
selectedFieldNames_(),
writers_(),
probeFilePtrs_(),
@ -484,7 +481,6 @@ Foam::sampledSets::sampledSets
searchEngine_(mesh_),
samplePointScheme_(),
writeFormat_(),
writeFormatOptions_(dict.subOrEmptyDict("formatOptions")),
selectedFieldNames_(),
writers_(),
probeFilePtrs_(),
@ -548,12 +544,6 @@ bool Foam::sampledSets::read(const dictionary& dict)
probeFilePtrs_.clear();
}
// const dictionary formatOptions(dict.subOrEmptyDict("formatOptions"));
// Writer type and format options
// const word writerType =
// (eptr ? dict.get<word>("setFormat") : word::null);
// writerType_ = (eptr ? dict.get<word>("setFormat") : word::null);
initDict(dict, true);
// Have some sets, so sort out which fields are needed and report

View File

@ -184,9 +184,6 @@ class sampledSets
//- Output format to use
word writeFormat_;
//- Dictionary containing writer options
dictionary writeFormatOptions_;
// Output control
@ -221,9 +218,9 @@ class sampledSets
//- A new coordSet writer, with per-set formatOptions
static autoPtr<coordSetWriter> newWriter
(
word writeType,
const dictionary& formatOptions,
const dictionary& surfDict
word writerType,
const dictionary& topDict,
const dictionary& setDict
);
//- Perform sampling action with store/write

View File

@ -190,22 +190,20 @@ Foam::IOobjectList Foam::sampledSurfaces::preCheckFields()
Foam::autoPtr<Foam::surfaceWriter> Foam::sampledSurfaces::newWriter
(
word writeType,
const dictionary& formatOptions,
word writerType,
const dictionary& topDict,
const dictionary& surfDict
)
{
// Per-surface adjustment
surfDict.readIfPresent<word>("surfaceFormat", writeType);
surfDict.readIfPresent<word>("surfaceFormat", writerType);
dictionary options = formatOptions.subOrEmptyDict(writeType);
options.merge
return surfaceWriter::New
(
surfDict.subOrEmptyDict("formatOptions").subOrEmptyDict(writeType)
writerType,
// Top-level/surface-specific "formatOptions"
surfaceWriter::formatOptions(topDict, surfDict, writerType)
);
return surfaceWriter::New(writeType, options);
}
@ -305,8 +303,6 @@ bool Foam::sampledSurfaces::read(const dictionary& dict)
const word writerType =
(eptr ? dict.get<word>("surfaceFormat") : word::null);
const dictionary formatOptions(dict.subOrEmptyDict("formatOptions"));
// Store on registry?
const bool dfltStore = dict.getOrDefault("store", false);
@ -355,7 +351,7 @@ bool Foam::sampledSurfaces::read(const dictionary& dict)
writers_.set
(
surfi,
newWriter(writerType, formatOptions, surfDict)
newWriter(writerType, dict, surfDict)
);
writers_[surfi].isPointData(surfs[surfi].isPointData());
@ -417,7 +413,7 @@ bool Foam::sampledSurfaces::read(const dictionary& dict)
writers_.set
(
surfi,
newWriter(writerType, formatOptions, surfDict)
newWriter(writerType, dict, surfDict)
);
writers_[surfi].isPointData(surfs[surfi].isPointData());

View File

@ -62,9 +62,13 @@ Description
formatOptions
{
default
{
verbose true;
}
vtk
{
precision 10;
precision 10;
}
}
@ -222,8 +226,8 @@ class sampledSurfaces
//- A new surfaceWriter, with per-surface formatOptions
static autoPtr<surfaceWriter> newWriter
(
word writeType,
const dictionary& formatOptions,
word writerType,
const dictionary& topDict,
const dictionary& surfDict
);