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

View File

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

View File

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

View File

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

View File

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

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019-2021 OpenCFD Ltd.
Copyright (C) 2019-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -152,7 +152,9 @@ Foam::surfaceWriter::surfaceWriter()
mergeDim_(defaultMergeDim),
merged_(),
currTime_(),
outputPath_()
outputPath_(),
fieldLevel_(),
fieldScale_()
{
surfaceWriter::close();
}
@ -163,6 +165,8 @@ Foam::surfaceWriter::surfaceWriter(const dictionary& options)
surfaceWriter()
{
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>> \
ThisClass::mergeField(const Field<Type>& fld) const \
{ \
return mergeFieldTemplate(fld); \
} \
\
void ThisClass::adjustOutputField \
( \
const word& fieldName, \
Field<Type>& fld \
) const \
{ \
adjustOutputFieldTemplate(fieldName, fld); \
}
defineSurfaceWriterMergeMethod(Foam::surfaceWriter, Foam::label);
defineSurfaceWriterMergeMethod(Foam::surfaceWriter, Foam::scalar);
defineSurfaceWriterMergeMethod(Foam::surfaceWriter, Foam::vector);
defineSurfaceWriterMergeMethod(Foam::surfaceWriter, Foam::sphericalTensor);
defineSurfaceWriterMergeMethod(Foam::surfaceWriter, Foam::symmTensor);
defineSurfaceWriterMergeMethod(Foam::surfaceWriter, Foam::tensor)
defineSurfaceFieldMethods(Foam::surfaceWriter, Foam::label);
defineSurfaceFieldMethods(Foam::surfaceWriter, Foam::scalar);
defineSurfaceFieldMethods(Foam::surfaceWriter, Foam::vector);
defineSurfaceFieldMethods(Foam::surfaceWriter, Foam::sphericalTensor);
defineSurfaceFieldMethods(Foam::surfaceWriter, Foam::symmTensor);
defineSurfaceFieldMethods(Foam::surfaceWriter, Foam::tensor)
#undef defineSurfaceWriterMergeMethod
#undef defineSurfaceFieldMethod
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -47,14 +47,26 @@ Description
someFormat // Eg, ensight, vtk, etc
{
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
Format options:
\table
Property | Description | Required | Default
verbose | Additional output verbosity | no | no
Property | Description | Required | Default
verbose | Additional output verbosity | no | no
fieldLevel | Subtract field level before scaling | no | empty dict
fieldScale | Output field scaling | no | empty dict
\endtable
Note
@ -156,6 +168,12 @@ protected:
//- The full output directory and file (surface) name
fileName outputPath_;
//- Field level to remove (on output)
dictionary fieldLevel_;
//- Field scaling (on output)
dictionary fieldScale_;
// Protected Member Functions
@ -175,18 +193,28 @@ protected:
template<class Type>
tmp<Field<Type>> mergeFieldTemplate(const Field<Type>& fld) const;
#undef declareSurfaceWriterMergeMethod
#define declareSurfaceWriterMergeMethod(Type) \
tmp<Field<Type>> mergeField(const Field<Type>& fld) const;
//- Apply refLevel and fieldScaling
template<class Type>
void adjustOutputFieldTemplate
(
const word& fieldName,
Field<Type>& fld
) const;
declareSurfaceWriterMergeMethod(label);
declareSurfaceWriterMergeMethod(scalar);
declareSurfaceWriterMergeMethod(vector);
declareSurfaceWriterMergeMethod(sphericalTensor);
declareSurfaceWriterMergeMethod(symmTensor);
declareSurfaceWriterMergeMethod(tensor);
#undef declareSurfaceFieldMethod
#define declareSurfaceFieldMethods(Type) \
\
tmp<Field<Type>> mergeField(const Field<Type>& fld) const; \
void adjustOutputField(const word& fieldName, Field<Type>& fld) const;
#undef declareSurfaceWriterMergeMethod
declareSurfaceFieldMethods(label);
declareSurfaceFieldMethods(scalar);
declareSurfaceFieldMethods(vector);
declareSurfaceFieldMethods(sphericalTensor);
declareSurfaceFieldMethods(symmTensor);
declareSurfaceFieldMethods(tensor);
#undef declareSurfaceFieldMethods
//- Dummy templated write operation
template<class Type>

View File

@ -41,11 +41,13 @@ Description
}
\endverbatim
Format options:
Format options for ensight:
\table
Property | Description | Required | Default
format | ascii/binary | no | ascii
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
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_)
{
Info<< "Writing case file to " << outputFile << endl;
Info<< "Writing case file to " << outputFile << nl;
}
// Implicit geometry merge()
tmp<Field<Type>> tfield = mergeField(localValues);
adjustOutputField(fieldName, tfield.ref());
if (verbose_)
{
Info<< endl;
}
const meshedSurf& surf = surface();
if (Pstream::master() || !parallel_)

View File

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

View File

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

View File

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

View File

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

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2015-2020 OpenCFD Ltd.
Copyright (C) 2015-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -36,7 +36,8 @@ Description
fields | field pairs for PLOAD2/PLOAD4 | yes |
format | short / long / free | no | long
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
\endtable
@ -146,9 +147,6 @@ private:
//- Output geometry scaling
const scalar geometryScale_;
//- Output field scaling
const dictionary fieldScale_;
//- Separator (used for free format)
word separator_;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2015-2020 OpenCFD Ltd.
Copyright (C) 2015-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -34,7 +34,8 @@ Description
\table
Property | Description | Required | Default
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
The geometry is written via the MeshedSurfaceProxy, the fields
@ -101,9 +102,6 @@ class starcdWriter
//- Output stream option
IOstreamOption streamOpt_;
//- Output field scaling
const dictionary fieldScale_;
// Private Member Functions

View File

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

View File

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

View File

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

View File

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

View File

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