ENH: add fieldLevel handling for surface writers (#2382)

- this can be used to apply a uniform field level to remove from
  a sampled field. For example,

      fieldLevel
      {
          "p.*"   1e5;        // Absolute -> gauge [Pa]
          T       273.15;     // [K] -> [C]
          U       #eval{ 10/sqrt(3) };  // Uniform mag(U)=10
      }

  After the fieldLevel has been removed, any fieldScale is applied.
  For example

      fieldScale
      {
          "p.*"   0.01;       // [Pa] -> [mbar]
      }

  The fieldLevel for vector and tensor fields may still need some
  further refinement.
This commit is contained in:
Mark Olesen
2022-02-28 13:56:42 +01:00
parent cb10045094
commit 1a55829ef9
25 changed files with 245 additions and 220 deletions

View File

@ -238,7 +238,6 @@ Foam::surfaceWriters::abaqusWriter::abaqusWriter()
: :
surfaceWriter(), surfaceWriter(),
geometryScale_(1), geometryScale_(1),
fieldScale_(),
noGeometry_(false), noGeometry_(false),
outputLayout_(outputLayoutType::BY_FIELD) outputLayout_(outputLayoutType::BY_FIELD)
{} {}
@ -251,7 +250,6 @@ Foam::surfaceWriters::abaqusWriter::abaqusWriter
: :
surfaceWriter(options), surfaceWriter(options),
geometryScale_(options.getOrDefault<scalar>("scale", 1)), geometryScale_(options.getOrDefault<scalar>("scale", 1)),
fieldScale_(options.subOrEmptyDict("fieldScale")),
noGeometry_(options.getOrDefault("noGeometry", false)), noGeometry_(options.getOrDefault("noGeometry", false)),
outputLayout_(outputLayoutType::BY_FIELD) outputLayout_(outputLayoutType::BY_FIELD)
{} {}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2020 OpenCFD Ltd. Copyright (C) 2020-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -33,7 +33,8 @@ Description
\table \table
Property | Description | Required | Default Property | Description | Required | Default
scale | output geometry scaling | no | 1 scale | output geometry scaling | no | 1
fieldScale | output field scaling (dictionary) | no | empty fieldLevel | Subtract field level before scaling | no | empty dict
fieldScale | Output field scaling | no | empty dict
noGeometry | Suppress geometry output (beta feature) | no | false noGeometry | Suppress geometry output (beta feature) | no | false
\endtable \endtable
@ -44,9 +45,13 @@ Description
abaqus abaqus
{ {
scale 1000; // [m] -> [mm] scale 1000; // [m] -> [mm]
fieldLevel
{
p 1e5; // Absolute -> gauge [Pa]
}
fieldScale fieldScale
{ {
"p.*" 0.01; // [Pa] -> [mbar] "p.*" 0.01; // [Pa] -> [mbar]
} }
} }
} }
@ -110,9 +115,6 @@ class abaqusWriter
//- Output geometry scaling //- Output geometry scaling
const scalar geometryScale_; const scalar geometryScale_;
//- Output field scaling
const dictionary fieldScale_;
//- BETA feature //- BETA feature
bool noGeometry_; bool noGeometry_;

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2020 OpenCFD Ltd. Copyright (C) 2020-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -117,30 +117,17 @@ Foam::fileName Foam::surfaceWriters::abaqusWriter::writeTemplate
outputFile.ext("inp"); outputFile.ext("inp");
// Output scaling for the variable, but not for integer types. // Implicit geometry merge()
// could also solve with clever templating tmp<Field<Type>> tfield = mergeField(localValues);
const scalar varScale = adjustOutputField(fieldName, tfield.ref());
(
std::is_integral<Type>::value
? scalar(1)
: fieldScale_.getOrDefault<scalar>(fieldName, 1)
);
if (verbose_) if (verbose_)
{ {
Info<< "Writing field " << fieldName;
if (!equal(varScale, 1))
{
Info<< " (scaling " << varScale << ')';
}
Info<< " to " << outputFile << endl; Info<< " to " << outputFile << endl;
} }
// Implicit geometry merge()
tmp<Field<Type>> tfield = mergeField(localValues) * varScale;
const meshedSurf& surf = surface(); const meshedSurf& surf = surface();
if (Pstream::master() || !parallel_) if (Pstream::master() || !parallel_)

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2015 OpenFOAM Foundation Copyright (C) 2015 OpenFOAM Foundation
Copyright (C) 2015-2021 OpenCFD Ltd. Copyright (C) 2015-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -56,8 +56,7 @@ Foam::surfaceWriters::boundaryDataWriter::boundaryDataWriter()
: :
surfaceWriter(), surfaceWriter(),
header_(true), header_(true),
streamOpt_(), streamOpt_()
fieldScale_()
{} {}
@ -72,8 +71,7 @@ Foam::surfaceWriters::boundaryDataWriter::boundaryDataWriter
( (
IOstreamOption::formatEnum("format", options, IOstreamOption::ASCII), IOstreamOption::formatEnum("format", options, IOstreamOption::ASCII),
IOstreamOption::compressionEnum("compression", options) IOstreamOption::compressionEnum("compression", options)
), )
fieldScale_(options.subOrEmptyDict("fieldScale"))
{} {}
@ -220,25 +218,20 @@ Foam::fileName Foam::surfaceWriters::boundaryDataWriter::writeTemplate
const fileName outputFile(surfaceDir/timeName()/fieldName); const fileName outputFile(surfaceDir/timeName()/fieldName);
// Implicit geometry merge()
tmp<Field<Type>> tfield = mergeField(localValues);
// Output scaling for the variable, but not for integer types. adjustOutputField(fieldName, tfield.ref());
// could also solve with clever templating
const scalar varScale = if (verbose_)
( {
std::is_integral<Type>::value Info<< " to " << outputFile << endl;
? scalar(1) }
: fieldScale_.getOrDefault<scalar>(fieldName, 1)
);
// Dummy Time to use as objectRegistry // Dummy Time to use as objectRegistry
autoPtr<Time> dummyTimePtr(Time::New(argList::envGlobalPath())); autoPtr<Time> dummyTimePtr(Time::New(argList::envGlobalPath()));
// Implicit geometry merge()
tmp<Field<Type>> tfield = mergeField(localValues) * varScale;
const meshedSurf& surf = surface(); const meshedSurf& surf = surface();
if (Pstream::master() || !parallel_) if (Pstream::master() || !parallel_)

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2015-2021 OpenCFD Ltd. Copyright (C) 2015-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -49,7 +49,8 @@ Description
header | Generate files with FoamFile header | no | true header | Generate files with FoamFile header | no | true
format | ascii/binary | no | ascii format | ascii/binary | no | ascii
compression | Use file compression | no | false compression | Use file compression | no | false
fieldScale | output field scaling (dictionary) | no | empty fieldLevel | Subtract field level before scaling | no | empty dict
fieldScale | Output field scaling | no | empty dict
\endtable \endtable
Typical way of working: Typical way of working:
@ -65,9 +66,13 @@ Description
boundaryData boundaryData
{ {
format binary; format binary;
fieldLevel
{
p 1e5; // Absolute -> gauge [Pa]
}
fieldScale fieldScale
{ {
"p.*" 0.01; // [Pa] -> [mbar] "p.*" 0.01; // [Pa] -> [mbar]
} }
} }
} }
@ -157,9 +162,6 @@ class boundaryDataWriter
//- Output stream option //- Output stream option
IOstreamOption streamOpt_; IOstreamOption streamOpt_;
//- Output field scaling
const dictionary fieldScale_;
// Private Member Functions // Private Member Functions

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2019-2021 OpenCFD Ltd. Copyright (C) 2019-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -152,7 +152,9 @@ Foam::surfaceWriter::surfaceWriter()
mergeDim_(defaultMergeDim), mergeDim_(defaultMergeDim),
merged_(), merged_(),
currTime_(), currTime_(),
outputPath_() outputPath_(),
fieldLevel_(),
fieldScale_()
{ {
surfaceWriter::close(); surfaceWriter::close();
} }
@ -163,6 +165,8 @@ Foam::surfaceWriter::surfaceWriter(const dictionary& options)
surfaceWriter() surfaceWriter()
{ {
options.readIfPresent("verbose", verbose_); options.readIfPresent("verbose", verbose_);
fieldLevel_ = options.subOrEmptyDict("fieldLevel");
fieldScale_ = options.subOrEmptyDict("fieldScale");
} }
@ -501,21 +505,89 @@ Foam::tmp<Foam::Field<Type>> Foam::surfaceWriter::mergeFieldTemplate
} }
#define defineSurfaceWriterMergeMethod(ThisClass, Type) \ template<class Type>
void Foam::surfaceWriter::adjustOutputFieldTemplate
(
const word& fieldName,
Field<Type>& fld
) const
{
if (verbose_)
{
Info<< "Writing field " << fieldName;
}
// Output scaling for the variable, but not for integer types
// which are typically ids etc.
if (!std::is_integral<Type>::value)
{
scalar value;
// Remove *uniform* reference level
if
(
fieldLevel_.readIfPresent(fieldName, value, keyType::REGEX)
&& !equal(value, 0)
)
{
// Could also detect brackets (...) and read accordingly
// or automatically scale by 1/sqrt(nComponents) instead ...
Type refLevel;
for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; ++cmpt)
{
setComponent(refLevel, cmpt) = value;
}
if (verbose_)
{
Info<< " [level " << refLevel << ']';
}
fld -= refLevel;
}
// Apply scaling
if
(
fieldScale_.readIfPresent(fieldName, value, keyType::REGEX)
&& !equal(value, 1)
)
{
if (verbose_)
{
Info<< " [scaling " << value << ']';
}
fld *= value;
}
}
}
#define defineSurfaceFieldMethods(ThisClass, Type) \
Foam::tmp<Foam::Field<Type>> \ Foam::tmp<Foam::Field<Type>> \
ThisClass::mergeField(const Field<Type>& fld) const \ ThisClass::mergeField(const Field<Type>& fld) const \
{ \ { \
return mergeFieldTemplate(fld); \ return mergeFieldTemplate(fld); \
} \
\
void ThisClass::adjustOutputField \
( \
const word& fieldName, \
Field<Type>& fld \
) const \
{ \
adjustOutputFieldTemplate(fieldName, fld); \
} }
defineSurfaceWriterMergeMethod(Foam::surfaceWriter, Foam::label); defineSurfaceFieldMethods(Foam::surfaceWriter, Foam::label);
defineSurfaceWriterMergeMethod(Foam::surfaceWriter, Foam::scalar); defineSurfaceFieldMethods(Foam::surfaceWriter, Foam::scalar);
defineSurfaceWriterMergeMethod(Foam::surfaceWriter, Foam::vector); defineSurfaceFieldMethods(Foam::surfaceWriter, Foam::vector);
defineSurfaceWriterMergeMethod(Foam::surfaceWriter, Foam::sphericalTensor); defineSurfaceFieldMethods(Foam::surfaceWriter, Foam::sphericalTensor);
defineSurfaceWriterMergeMethod(Foam::surfaceWriter, Foam::symmTensor); defineSurfaceFieldMethods(Foam::surfaceWriter, Foam::symmTensor);
defineSurfaceWriterMergeMethod(Foam::surfaceWriter, Foam::tensor) defineSurfaceFieldMethods(Foam::surfaceWriter, Foam::tensor)
#undef defineSurfaceWriterMergeMethod #undef defineSurfaceFieldMethod
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -47,14 +47,26 @@ Description
someFormat // Eg, ensight, vtk, etc someFormat // Eg, ensight, vtk, etc
{ {
verbose true; verbose true;
fieldLevel
{
"p.*" 1e5; // Absolute -> gauge [Pa]
T 273.15; // [K] -> [C]
U #eval{ 10/sqrt(3) }; // Uniform magU=10
}
fieldScale
{
"p.*" 0.01; // [Pa] -> [mbar]
}
} }
} }
\endverbatim \endverbatim
Format options: Format options:
\table \table
Property | Description | Required | Default Property | Description | Required | Default
verbose | Additional output verbosity | no | no verbose | Additional output verbosity | no | no
fieldLevel | Subtract field level before scaling | no | empty dict
fieldScale | Output field scaling | no | empty dict
\endtable \endtable
Note Note
@ -156,6 +168,12 @@ protected:
//- The full output directory and file (surface) name //- The full output directory and file (surface) name
fileName outputPath_; fileName outputPath_;
//- Field level to remove (on output)
dictionary fieldLevel_;
//- Field scaling (on output)
dictionary fieldScale_;
// Protected Member Functions // Protected Member Functions
@ -175,18 +193,28 @@ protected:
template<class Type> template<class Type>
tmp<Field<Type>> mergeFieldTemplate(const Field<Type>& fld) const; tmp<Field<Type>> mergeFieldTemplate(const Field<Type>& fld) const;
#undef declareSurfaceWriterMergeMethod //- Apply refLevel and fieldScaling
#define declareSurfaceWriterMergeMethod(Type) \ template<class Type>
tmp<Field<Type>> mergeField(const Field<Type>& fld) const; void adjustOutputFieldTemplate
(
const word& fieldName,
Field<Type>& fld
) const;
declareSurfaceWriterMergeMethod(label); #undef declareSurfaceFieldMethod
declareSurfaceWriterMergeMethod(scalar); #define declareSurfaceFieldMethods(Type) \
declareSurfaceWriterMergeMethod(vector); \
declareSurfaceWriterMergeMethod(sphericalTensor); tmp<Field<Type>> mergeField(const Field<Type>& fld) const; \
declareSurfaceWriterMergeMethod(symmTensor); void adjustOutputField(const word& fieldName, Field<Type>& fld) const;
declareSurfaceWriterMergeMethod(tensor);
#undef declareSurfaceWriterMergeMethod declareSurfaceFieldMethods(label);
declareSurfaceFieldMethods(scalar);
declareSurfaceFieldMethods(vector);
declareSurfaceFieldMethods(sphericalTensor);
declareSurfaceFieldMethods(symmTensor);
declareSurfaceFieldMethods(tensor);
#undef declareSurfaceFieldMethods
//- Dummy templated write operation //- Dummy templated write operation
template<class Type> template<class Type>

View File

@ -41,11 +41,13 @@ Description
} }
\endverbatim \endverbatim
Format options: Format options for ensight:
\table \table
Property | Description | Required | Default Property | Description | Required | Default
format | ascii/binary | no | ascii format | ascii/binary | no | ascii
collateTimes | use common geometry for times | no | true collateTimes | use common geometry for times | no | true
fieldLevel | Subtract field level before scaling | no | empty dict
fieldScale | Output field scaling | no | empty dict
\endtable \endtable
The collated format maintains an internal list of the known times The collated format maintains an internal list of the known times

View File

@ -83,14 +83,19 @@ Foam::fileName Foam::surfaceWriters::ensightWriter::writeCollated
if (verbose_) if (verbose_)
{ {
Info<< "Writing case file to " << outputFile << endl; Info<< "Writing case file to " << outputFile << nl;
} }
// Implicit geometry merge() // Implicit geometry merge()
tmp<Field<Type>> tfield = mergeField(localValues); tmp<Field<Type>> tfield = mergeField(localValues);
adjustOutputField(fieldName, tfield.ref());
if (verbose_)
{
Info<< endl;
}
const meshedSurf& surf = surface(); const meshedSurf& surf = surface();
if (Pstream::master() || !parallel_) if (Pstream::master() || !parallel_)

View File

@ -148,13 +148,19 @@ Foam::fileName Foam::surfaceWriters::ensightWriter::writeUncollated
if (verbose_) if (verbose_)
{ {
Info<< "Writing case file to " << outputFile << endl; Info<< "Writing case file to " << outputFile << nl;
} }
// Implicit geometry merge()
// geometry merge() implicit
tmp<Field<Type>> tfield = mergeField(localValues); tmp<Field<Type>> tfield = mergeField(localValues);
adjustOutputField(fieldName, tfield.ref());
if (verbose_)
{
Info<< endl;
}
const meshedSurf& surf = surface(); const meshedSurf& surf = surface();
if (Pstream::master() || !parallel_) if (Pstream::master() || !parallel_)

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015-2020 OpenCFD Ltd. Copyright (C) 2015-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -50,8 +50,7 @@ namespace surfaceWriters
Foam::surfaceWriters::foamWriter::foamWriter() Foam::surfaceWriters::foamWriter::foamWriter()
: :
surfaceWriter(), surfaceWriter(),
streamOpt_(), streamOpt_()
fieldScale_()
{} {}
@ -65,8 +64,7 @@ Foam::surfaceWriters::foamWriter::foamWriter
( (
IOstreamOption::formatEnum("format", options, IOstreamOption::ASCII), IOstreamOption::formatEnum("format", options, IOstreamOption::ASCII),
IOstreamOption::compressionEnum("compression", options) IOstreamOption::compressionEnum("compression", options)
), )
fieldScale_(options.subOrEmptyDict("fieldScale"))
{} {}
@ -195,30 +193,17 @@ Foam::fileName Foam::surfaceWriters::foamWriter::writeTemplate
); );
// Output scaling for the variable, but not for integer types. // Implicit geometry merge()
// could also solve with clever templating tmp<Field<Type>> tfield = mergeField(localValues);
const scalar varScale = adjustOutputField(fieldName, tfield.ref());
(
std::is_integral<Type>::value
? scalar(1)
: fieldScale_.getOrDefault<scalar>(fieldName, 1)
);
if (verbose_) if (verbose_)
{ {
Info<< "Writing field " << fieldName;
if (!equal(varScale, 1))
{
Info<< " (scaling " << varScale << ')';
}
Info<< " to " << surfaceDir << endl; Info<< " to " << surfaceDir << endl;
} }
// Implicit geometry merge()
tmp<Field<Type>> tfield = mergeField(localValues) * varScale;
if (Pstream::master()) if (Pstream::master())
{ {
if (!isDir(outputFile.path())) if (!isDir(outputFile.path()))

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015-2020 OpenCFD Ltd. Copyright (C) 2015-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -37,10 +37,13 @@ Description
{ {
format ascii; format ascii;
compression true; compression true;
fieldLevel
{
p 1e5; // Absolute -> gauge [Pa]
}
fieldScale fieldScale
{ {
"p.*" 0.01; // [Pa] -> [mbar] "p.*" 0.01; // [Pa] -> [mbar]
} }
} }
} }
@ -51,7 +54,8 @@ Description
Property | Description | Required | Default Property | Description | Required | Default
format | ascii/binary | no | ascii format | ascii/binary | no | ascii
compression | output file compression | no | false compression | output file compression | no | false
fieldScale | output field scaling (dictionary) | no | empty fieldLevel | Subtract field level before scaling | no | empty dict
fieldScale | Output field scaling | no | empty dict
\endtable \endtable
\section Output file locations \section Output file locations
@ -112,9 +116,6 @@ class foamWriter
//- Output stream option (default: ASCII, uncompressed) //- Output stream option (default: ASCII, uncompressed)
IOstreamOption streamOpt_; IOstreamOption streamOpt_;
//- Output field scaling
const dictionary fieldScale_;
// Private Member Functions // Private Member Functions

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2015-2020 OpenCFD Ltd. Copyright (C) 2015-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -311,7 +311,6 @@ Foam::surfaceWriters::nastranWriter::nastranWriter()
fieldMap_(), fieldMap_(),
commonGeometry_(false), commonGeometry_(false),
geometryScale_(1), geometryScale_(1),
fieldScale_(),
separator_() separator_()
{ {
// if (writeFormat_ == fieldFormat::FREE) // if (writeFormat_ == fieldFormat::FREE)
@ -339,7 +338,6 @@ Foam::surfaceWriters::nastranWriter::nastranWriter
fieldMap_(), fieldMap_(),
commonGeometry_(options.getOrDefault("commonGeometry", false)), commonGeometry_(options.getOrDefault("commonGeometry", false)),
geometryScale_(options.getOrDefault<scalar>("scale", 1)), geometryScale_(options.getOrDefault<scalar>("scale", 1)),
fieldScale_(options.subOrEmptyDict("fieldScale")),
separator_() separator_()
{ {
if (writeFormat_ == fieldFormat::FREE) if (writeFormat_ == fieldFormat::FREE)

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2015-2020 OpenCFD Ltd. Copyright (C) 2015-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -36,7 +36,8 @@ Description
fields | field pairs for PLOAD2/PLOAD4 | yes | fields | field pairs for PLOAD2/PLOAD4 | yes |
format | short / long / free | no | long format | short / long / free | no | long
scale | output geometry scaling | no | 1 scale | output geometry scaling | no | 1
fieldScale | output field scaling (dictionary) | no | empty fieldLevel | Subtract field level before scaling | no | empty dict
fieldScale | Output field scaling | no | empty dict
commonGeometry | use separate geometry files | no | false commonGeometry | use separate geometry files | no | false
\endtable \endtable
@ -146,9 +147,6 @@ private:
//- Output geometry scaling //- Output geometry scaling
const scalar geometryScale_; const scalar geometryScale_;
//- Output field scaling
const dictionary fieldScale_;
//- Separator (used for free format) //- Separator (used for free format)
word separator_; word separator_;

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2015-2020 OpenCFD Ltd. Copyright (C) 2015-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -223,31 +223,17 @@ Foam::fileName Foam::surfaceWriters::nastranWriter::writeTemplate
} }
outputFile.ext("bdf"); outputFile.ext("bdf");
// Implicit geometry merge()
tmp<Field<Type>> tfield = mergeField(localValues);
// Output scaling for the variable, but not for integer types. adjustOutputField(fieldName, tfield.ref());
// could also solve with clever templating
const scalar varScale =
(
std::is_integral<Type>::value
? scalar(1)
: fieldScale_.getOrDefault<scalar>(fieldName, 1)
);
if (verbose_) if (verbose_)
{ {
Info<< "Writing field " << fieldName;
if (!equal(varScale, 1))
{
Info<< " (scaling " << varScale << ')';
}
Info<< " to " << outputFile << endl; Info<< " to " << outputFile << endl;
} }
// Implicit geometry merge()
tmp<Field<Type>> tfield = mergeField(localValues) * varScale;
const meshedSurf& surf = surface(); const meshedSurf& surf = surface();
if (Pstream::master() || !parallel_) if (Pstream::master() || !parallel_)

View File

@ -62,8 +62,7 @@ Foam::surfaceWriters::rawWriter::rawWriter()
streamOpt_(), streamOpt_(),
precision_(IOstream::defaultPrecision()), precision_(IOstream::defaultPrecision()),
writeNormal_(false), writeNormal_(false),
geometryScale_(1), geometryScale_(1)
fieldScale_()
{} {}
@ -83,8 +82,7 @@ Foam::surfaceWriters::rawWriter::rawWriter
options.getOrDefault("precision", IOstream::defaultPrecision()) options.getOrDefault("precision", IOstream::defaultPrecision())
), ),
writeNormal_(options.getOrDefault("normal", false)), writeNormal_(options.getOrDefault("normal", false)),
geometryScale_(options.getOrDefault<scalar>("scale", 1)), geometryScale_(options.getOrDefault<scalar>("scale", 1))
fieldScale_(options.subOrEmptyDict("fieldScale"))
{} {}

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015-2021 OpenCFD Ltd. Copyright (C) 2015-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -35,8 +35,9 @@ Description
Property | Description | Required | Default Property | Description | Required | Default
compression | Use file compression | no | false compression | Use file compression | no | false
precision | Write precision in ascii | no | same as IOstream precision | Write precision in ascii | no | same as IOstream
scale | output geometry scaling | no | 1 scale | Output geometry scaling | no | 1
fieldScale | output field scaling (dictionary) | no | empty fieldLevel | Subtract field level before scaling | no | empty dict
fieldScale | Output field scaling | no | empty dict
normal | Write face area normal in output | no | false normal | Write face area normal in output | no | false
\endtable \endtable
@ -118,9 +119,6 @@ class rawWriter
//- Output geometry scaling //- Output geometry scaling
const scalar geometryScale_; const scalar geometryScale_;
//- Output field scaling
const dictionary fieldScale_;
// Private Member Functions // Private Member Functions

View File

@ -106,30 +106,16 @@ Foam::fileName Foam::surfaceWriters::rawWriter::writeTemplate
outputFile.ext("raw"); outputFile.ext("raw");
// Output scaling for the variable, but not for integer types. // Implicit geometry merge()
// could also solve with clever templating tmp<Field<Type>> tfield = mergeField(localValues);
const scalar varScale = adjustOutputField(fieldName, tfield.ref());
(
std::is_integral<Type>::value
? scalar(1)
: fieldScale_.getOrDefault<scalar>(fieldName, 1)
);
if (verbose_) if (verbose_)
{ {
Info<< "Writing field " << fieldName;
if (!equal(varScale, 1))
{
Info<< " (scaling " << varScale << ')';
}
Info<< " to " << outputFile << endl; Info<< " to " << outputFile << endl;
} }
// Implicit geometry merge()
tmp<Field<Type>> tfield = mergeField(localValues) * varScale;
const meshedSurf& surf = surface(); const meshedSurf& surf = surface();
if (Pstream::master() || !parallel_) if (Pstream::master() || !parallel_)

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2015-2020 OpenCFD Ltd. Copyright (C) 2015-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -69,8 +69,7 @@ namespace Foam
Foam::surfaceWriters::starcdWriter::starcdWriter() Foam::surfaceWriters::starcdWriter::starcdWriter()
: :
surfaceWriter(), surfaceWriter(),
streamOpt_(), streamOpt_()
fieldScale_()
{} {}
@ -84,8 +83,7 @@ Foam::surfaceWriters::starcdWriter::starcdWriter
( (
IOstreamOption::ASCII, IOstreamOption::ASCII,
IOstreamOption::compressionEnum("compression", options) IOstreamOption::compressionEnum("compression", options)
), )
fieldScale_(options.subOrEmptyDict("fieldScale"))
{} {}
@ -208,31 +206,17 @@ Foam::fileName Foam::surfaceWriters::starcdWriter::writeTemplate
outputFile /= fieldName + '_' + outputPath_.name(); outputFile /= fieldName + '_' + outputPath_.name();
outputFile.ext("usr"); outputFile.ext("usr");
// Implicit geometry merge()
tmp<Field<Type>> tfield = mergeField(localValues);
// Output scaling for the variable, but not for integer types. adjustOutputField(fieldName, tfield.ref());
// could also solve with clever templating
const scalar varScale =
(
std::is_integral<Type>::value
? scalar(1)
: fieldScale_.getOrDefault<scalar>(fieldName, 1)
);
if (verbose_) if (verbose_)
{ {
Info<< "Writing field " << fieldName;
if (!equal(varScale, 1))
{
Info<< " (scaling " << varScale << ')';
}
Info<< " to " << outputFile << endl; Info<< " to " << outputFile << endl;
} }
// Implicit geometry merge()
tmp<Field<Type>> tfield = mergeField(localValues) * varScale;
const meshedSurf& surf = surface(); const meshedSurf& surf = surface();
if (Pstream::master() || !parallel_) if (Pstream::master() || !parallel_)

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2015-2020 OpenCFD Ltd. Copyright (C) 2015-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -34,7 +34,8 @@ Description
\table \table
Property | Description | Required | Default Property | Description | Required | Default
compression | Use file compression | no | false compression | Use file compression | no | false
fieldScale | output field scaling (dictionary) | no | empty fieldLevel | Subtract field level before scaling | no | empty dict
fieldScale | Output field scaling | no | empty dict
\endtable \endtable
The geometry is written via the MeshedSurfaceProxy, the fields The geometry is written via the MeshedSurfaceProxy, the fields
@ -101,9 +102,6 @@ class starcdWriter
//- Output stream option //- Output stream option
IOstreamOption streamOpt_; IOstreamOption streamOpt_;
//- Output field scaling
const dictionary fieldScale_;
// Private Member Functions // Private Member Functions

View File

@ -67,7 +67,6 @@ Foam::surfaceWriters::vtkWriter::vtkWriter()
fmtType_(static_cast<unsigned>(vtk::formatType::INLINE_BASE64)), fmtType_(static_cast<unsigned>(vtk::formatType::INLINE_BASE64)),
precision_(IOstream::defaultPrecision()), precision_(IOstream::defaultPrecision()),
writeNormal_(false), writeNormal_(false),
fieldScale_(),
writer_(nullptr) writer_(nullptr)
{} {}
@ -81,7 +80,6 @@ Foam::surfaceWriters::vtkWriter::vtkWriter
fmtType_(static_cast<unsigned>(opts.fmt())), fmtType_(static_cast<unsigned>(opts.fmt())),
precision_(opts.precision()), precision_(opts.precision()),
writeNormal_(false), writeNormal_(false),
fieldScale_(),
writer_(nullptr) writer_(nullptr)
{} {}
@ -98,7 +96,6 @@ Foam::surfaceWriters::vtkWriter::vtkWriter
options.getOrDefault("precision", IOstream::defaultPrecision()) options.getOrDefault("precision", IOstream::defaultPrecision())
), ),
writeNormal_(options.getOrDefault("normal", false)), writeNormal_(options.getOrDefault("normal", false)),
fieldScale_(options.subOrEmptyDict("fieldScale")),
writer_(nullptr) writer_(nullptr)
{ {
// format: ascii | binary // format: ascii | binary
@ -288,31 +285,17 @@ Foam::fileName Foam::surfaceWriters::vtkWriter::writeTemplate
// Open file, writing geometry (if required) // Open file, writing geometry (if required)
fileName outputFile = this->write(); fileName outputFile = this->write();
// Implicit geometry merge()
tmp<Field<Type>> tfield = mergeField(localValues);
// Output scaling for the variable, but not for integer types. adjustOutputField(fieldName, tfield.ref());
// could also solve with clever templating
const scalar varScale =
(
std::is_integral<Type>::value
? scalar(1)
: fieldScale_.getOrDefault<scalar>(fieldName, 1)
);
if (verbose_) if (verbose_)
{ {
Info<< "Writing field " << fieldName;
if (!equal(varScale, 1))
{
Info<< " (scaling " << varScale << ')';
}
Info<< " to " << outputFile << endl; Info<< " to " << outputFile << endl;
} }
// Implicit geometry merge()
tmp<Field<Type>> tfield = mergeField(localValues) * varScale;
if (Pstream::master() || !parallel_) if (Pstream::master() || !parallel_)
{ {
if (!nFields_ && writer_->legacy()) if (!nFields_ && writer_->legacy())

View File

@ -36,7 +36,8 @@ Description
format | ascii or binary format | no | binary format | ascii or binary format | no | binary
legacy | Legacy VTK output | no | false legacy | Legacy VTK output | no | false
precision | Write precision in ascii | no | same as IOstream precision | Write precision in ascii | no | same as IOstream
fieldScale | Output field scaling (dictionary) | no | empty fieldLevel | Subtract field level before scaling | no | empty dict
fieldScale | Output field scaling | no | empty dict
normal | Write face area-normal in output | no | false normal | Write face area-normal in output | no | false
\endtable \endtable
@ -49,9 +50,13 @@ Description
format binary; format binary;
legacy false; legacy false;
precision 10; precision 10;
fieldLevel
{
p 1e5; // Absolute -> gauge [Pa]
}
fieldScale fieldScale
{ {
"p.*" 0.01; // [Pa] -> [mbar] "p.*" 0.01; // [Pa] -> [mbar]
} }
} }
} }
@ -114,9 +119,6 @@ class vtkWriter
//- Output face area normal //- Output face area normal
const bool writeNormal_; const bool writeNormal_;
//- Output field scaling
const dictionary fieldScale_;
//- Backend writer - master only //- Backend writer - master only
autoPtr<Foam::vtk::surfaceWriter> writer_; autoPtr<Foam::vtk::surfaceWriter> writer_;

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2019-2020 OpenCFD Ltd. Copyright (C) 2019-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -269,16 +269,19 @@ Foam::fileName Foam::surfaceWriters::x3dWriter::writeTemplate
outputFile /= fieldName + '_' + outputPath_.name(); outputFile /= fieldName + '_' + outputPath_.name();
outputFile.ext("x3d"); outputFile.ext("x3d");
if (verbose_)
{
Info<< "Writing field " << fieldName << " to " << outputFile << endl;
}
const meshedSurf& surf = surface();
// Implicit geometry merge() // Implicit geometry merge()
tmp<Field<Type>> tfield = mergeField(localValues); tmp<Field<Type>> tfield = mergeField(localValues);
adjustOutputField(fieldName, tfield.ref());
if (verbose_)
{
Info<< " to " << outputFile << endl;
}
const meshedSurf& surf = surface();
if (Pstream::master() || !parallel_) if (Pstream::master() || !parallel_)
{ {
const auto& values = tfield(); const auto& values = tfield();

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2019-2020 OpenCFD Ltd. Copyright (C) 2019-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -35,6 +35,8 @@ Description
compression | Use file compression | no | false compression | Use file compression | no | false
range | The min/max range for colour table | no | automatic range | The min/max range for colour table | no | automatic
colourMap | The colour map for rendering | no | coolToWarm colourMap | The colour map for rendering | no | coolToWarm
fieldLevel | Subtract field level before scaling | no | empty dict
fieldScale | Output field scaling | no | empty dict
\endtable \endtable
\section Output file locations \section Output file locations
@ -57,6 +59,9 @@ Description
`-- <field1>_surfaceName.x3d `-- <field1>_surfaceName.x3d
\endverbatim \endverbatim
Note
The range is applied after any field scaling.
SourceFiles SourceFiles
x3dSurfaceWriter.C x3dSurfaceWriter.C

View File

@ -10,7 +10,7 @@ debug
writeControl timeStep; writeControl timeStep;
writeInterval 1; writeInterval 1;
fields (rho U); fields (p rho U);
sampleScheme cellPoint; sampleScheme cellPoint;
interpolationScheme cellPoint; interpolationScheme cellPoint;
@ -24,6 +24,11 @@ debug
{ {
collateTimes true; collateTimes true;
// collateTimes false; // collateTimes false;
fieldLevel
{
"p.*" 1e5;
U 0;
}
} }
raw raw
{ {