ENH: support surface writer output transform (#2505)

- this allows the "relocation" of sampled surfaces. For example,
  to reposition into a different coordinate system for importing
  into CAD.

- incorporate output scaling for all surface writer types.

  This was previously done on an adhoc basis for different writers,
  but with now included in the base-level so that all writers
  can automatically use scale + transform.

  Example:

  formatOptions
  {
      vtk
      {
          scale 1000;  // m -> mm
          transform
          {
              origin  (0.05 0 0);
              rotation axisAngle;
              axis    (0 0 1);
              angle   -45;
          }
      }
  }
This commit is contained in:
Mark Olesen
2022-06-08 12:36:36 +02:00
committed by Andrew Heather
parent 675c168014
commit ad0235a751
28 changed files with 286 additions and 127 deletions

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.
@ -150,7 +150,7 @@ void Foam::surfaceWriters::abaqusWriter::writeGeometry
<< "** Points" << nl << "** Points" << nl
<< "**" << nl; << "**" << nl;
fileFormats::ABAQUSCore::writePoints(os, points, geometryScale_); fileFormats::ABAQUSCore::writePoints(os, points);
// Write faces, with on-the-fly decomposition (triangulation) // Write faces, with on-the-fly decomposition (triangulation)
@ -237,7 +237,6 @@ void Foam::surfaceWriters::abaqusWriter::writeGeometry
Foam::surfaceWriters::abaqusWriter::abaqusWriter() Foam::surfaceWriters::abaqusWriter::abaqusWriter()
: :
surfaceWriter(), surfaceWriter(),
geometryScale_(1),
noGeometry_(false), noGeometry_(false),
outputLayout_(outputLayoutType::BY_FIELD) outputLayout_(outputLayoutType::BY_FIELD)
{} {}
@ -249,7 +248,6 @@ Foam::surfaceWriters::abaqusWriter::abaqusWriter
) )
: :
surfaceWriter(options), surfaceWriter(options),
geometryScale_(options.getOrDefault<scalar>("scale", 1)),
noGeometry_(options.getOrDefault("noGeometry", false)), noGeometry_(options.getOrDefault("noGeometry", false)),
outputLayout_(outputLayoutType::BY_FIELD) outputLayout_(outputLayoutType::BY_FIELD)
{} {}
@ -328,7 +326,8 @@ Foam::fileName Foam::surfaceWriters::abaqusWriter::write()
} }
const meshedSurf& surf = surface(); // const meshedSurf& surf = surface();
const meshedSurfRef& surf = adjustSurface();
if (Pstream::master() || !parallel_) if (Pstream::master() || !parallel_)
{ {

View File

@ -31,11 +31,12 @@ Description
The formatOptions for abaqus: The formatOptions for abaqus:
\table \table
Property | Description | Required | Default Property | Description | Reqd | Default
scale | output geometry scaling | no | 1 scale | Output geometry scaling | no | 1
transform | Output coordinate transform | no |
fieldLevel | Subtract field level before scaling | no | empty dict fieldLevel | Subtract field level before scaling | no | empty dict
fieldScale | Output field 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
For example, For example,
@ -112,9 +113,6 @@ class abaqusWriter
{ {
// Private Data // Private Data
//- Output geometry scaling
const scalar geometryScale_;
//- BETA feature //- BETA feature
bool noGeometry_; bool noGeometry_;

View File

@ -126,7 +126,8 @@ Foam::fileName Foam::surfaceWriters::abaqusWriter::writeTemplate
} }
const meshedSurf& surf = surface(); // const meshedSurf& surf = surface();
const meshedSurfRef& surf = adjustSurface();
if (Pstream::master() || !parallel_) if (Pstream::master() || !parallel_)
{ {

View File

@ -169,7 +169,8 @@ Foam::fileName Foam::surfaceWriters::boundaryDataWriter::write()
// 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()));
const meshedSurf& surf = surface(); // const meshedSurf& surf = surface();
const meshedSurfRef& surf = adjustSurface();
if (Pstream::master() || !parallel_) if (Pstream::master() || !parallel_)
{ {
@ -230,7 +231,8 @@ Foam::fileName Foam::surfaceWriters::boundaryDataWriter::writeTemplate
// 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()));
const meshedSurf& surf = surface(); // const meshedSurf& surf = surface();
const meshedSurfRef& surf = adjustSurface();
if (Pstream::master() || !parallel_) if (Pstream::master() || !parallel_)
{ {

View File

@ -49,6 +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
scale | Output geometry scaling | no | 1
transform | Output coordinate transform | no |
fieldLevel | Subtract field level before scaling | no | empty dict fieldLevel | Subtract field level before scaling | no | empty dict
fieldScale | Output field scaling | no | empty dict fieldScale | Output field scaling | no | empty dict
\endtable \endtable

View File

@ -31,6 +31,8 @@ License
#include "Time.H" #include "Time.H"
#include "globalIndex.H" #include "globalIndex.H"
#include "coordinateRotation.H"
#include "transformField.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -44,8 +46,6 @@ namespace Foam
Foam::scalar Foam::surfaceWriter::defaultMergeDim = 1e-8; Foam::scalar Foam::surfaceWriter::defaultMergeDim = 1e-8;
const Foam::meshedSurf::emptySurface Foam::surfaceWriter::emptySurface_;
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
@ -139,9 +139,12 @@ Foam::surfaceWriter::New
Foam::surfaceWriter::surfaceWriter() Foam::surfaceWriter::surfaceWriter()
: :
surf_(std::cref<meshedSurf>(emptySurface_)), surf_(),
surfComp_(), mergedSurf_(),
useComponents_(false), adjustedSurf_(),
mergeDim_(defaultMergeDim),
geometryScale_(1),
geometryTransform_(),
upToDate_(false), upToDate_(false),
wroteGeom_(false), wroteGeom_(false),
parallel_(true), parallel_(true),
@ -149,8 +152,6 @@ Foam::surfaceWriter::surfaceWriter()
isPointData_(false), isPointData_(false),
verbose_(false), verbose_(false),
nFields_(0), nFields_(0),
mergeDim_(defaultMergeDim),
merged_(),
currTime_(), currTime_(),
outputPath_(), outputPath_(),
fieldLevel_(), fieldLevel_(),
@ -165,6 +166,20 @@ Foam::surfaceWriter::surfaceWriter(const dictionary& options)
surfaceWriter() surfaceWriter()
{ {
options.readIfPresent("verbose", verbose_); options.readIfPresent("verbose", verbose_);
geometryScale_ = 1;
geometryTransform_.clear();
options.readIfPresent("scale", geometryScale_);
const dictionary* dictptr;
// Optional cartesian coordinate system transform
if ((dictptr = options.findDict("transform", keyType::LITERAL))!= nullptr)
{
geometryTransform_ = coordSystem::cartesian(*dictptr);
}
fieldLevel_ = options.subOrEmptyDict("fieldLevel"); fieldLevel_ = options.subOrEmptyDict("fieldLevel");
fieldScale_ = options.subOrEmptyDict("fieldScale"); fieldScale_ = options.subOrEmptyDict("fieldScale");
} }
@ -294,9 +309,7 @@ void Foam::surfaceWriter::clear()
{ {
close(); close();
expire(); expire();
useComponents_ = false; surf_.clear();
surf_ = std::cref<meshedSurf>(emptySurface_);
surfComp_.clear();
} }
@ -307,9 +320,7 @@ void Foam::surfaceWriter::setSurface
) )
{ {
expire(); expire();
useComponents_ = false; surf_.reset(surf);
surf_ = std::cref<meshedSurf>(surf);
surfComp_.clear();
parallel_ = (parallel && Pstream::parRun()); parallel_ = (parallel && Pstream::parRun());
} }
@ -322,9 +333,7 @@ void Foam::surfaceWriter::setSurface
) )
{ {
expire(); expire();
useComponents_ = true; surf_.reset(points, faces);
surf_ = std::cref<meshedSurf>(emptySurface_);
surfComp_.reset(points, faces);
parallel_ = (parallel && Pstream::parRun()); parallel_ = (parallel && Pstream::parRun());
} }
@ -366,7 +375,8 @@ bool Foam::surfaceWriter::expire()
upToDate_ = false; upToDate_ = false;
wroteGeom_ = false; wroteGeom_ = false;
merged_.clear(); adjustedSurf_.clear();
mergedSurf_.clear();
// Field count (nFields_) is a different type of accounting // Field count (nFields_) is a different type of accounting
// and is unaffected by geometry changes // and is unaffected by geometry changes
@ -377,18 +387,13 @@ bool Foam::surfaceWriter::expire()
bool Foam::surfaceWriter::hasSurface() const bool Foam::surfaceWriter::hasSurface() const
{ {
return (useComponents_ || (&emptySurface_ != &(surf_.get()))); return surf_.valid();
} }
bool Foam::surfaceWriter::empty() const bool Foam::surfaceWriter::empty() const
{ {
const bool value = const bool value = surf_.faces().empty();
(
useComponents_
? surfComp_.faces().empty()
: surf_.get().faces().empty()
);
return (parallel_ ? returnReduce(value, andOp<bool>()) : value); return (parallel_ ? returnReduce(value, andOp<bool>()) : value);
} }
@ -396,12 +401,7 @@ bool Foam::surfaceWriter::empty() const
Foam::label Foam::surfaceWriter::size() const Foam::label Foam::surfaceWriter::size() const
{ {
const label value = const label value = surf_.faces().size();
(
useComponents_
? surfComp_.faces().size()
: surf_.get().faces().size()
);
return (parallel_ ? returnReduce(value, sumOp<label>()) : value); return (parallel_ ? returnReduce(value, sumOp<label>()) : value);
} }
@ -422,17 +422,20 @@ bool Foam::surfaceWriter::merge() const
{ {
bool changed = false; bool changed = false;
if (parallel_ && Pstream::parRun() && !upToDate_) if (!upToDate_)
{ {
if (useComponents_) adjustedSurf_.clear();
if (parallel_ && Pstream::parRun())
{ {
changed = merged_.merge(surfComp_, mergeDim_); changed = mergedSurf_.merge(surf_, mergeDim_);
} }
else else
{ {
changed = merged_.merge(surf_.get(), mergeDim_); mergedSurf_.clear();
} }
} }
upToDate_ = true; upToDate_ = true;
if (changed) if (changed)
@ -450,17 +453,45 @@ const Foam::meshedSurf& Foam::surfaceWriter::surface() const
if (parallel_ && Pstream::parRun()) if (parallel_ && Pstream::parRun())
{ {
return merged_; return mergedSurf_;
} }
if (useComponents_) return surf_;
}
const Foam::meshedSurfRef& Foam::surfaceWriter::adjustSurface() const
{
if (!upToDate_)
{ {
return surfComp_; adjustedSurf_.clear();
} }
else
if (!adjustedSurf_.valid())
{ {
return surf_.get(); adjustedSurf_.reset(surface());
if
(
geometryTransform_.valid()
&&
(
(magSqr(geometryTransform_.origin()) > ROOTVSMALL)
|| !geometryTransform_.R().is_identity()
)
)
{
// Forward transform
adjustedSurf_.movePoints
(
geometryTransform_.globalPosition(adjustedSurf_.points0())
);
}
adjustedSurf_.scalePoints(geometryScale_);
} }
return adjustedSurf_;
} }
@ -488,11 +519,11 @@ Foam::tmp<Foam::Field<Type>> Foam::surfaceWriter::mergeFieldTemplate
( (
Pstream::master() Pstream::master()
&& this->isPointData() && this->isPointData()
&& merged_.pointsMap().size() && mergedSurf_.pointsMap().size()
) )
{ {
inplaceReorder(merged_.pointsMap(), allFld); inplaceReorder(mergedSurf_.pointsMap(), allFld);
allFld.resize(merged_.points().size()); allFld.resize(mergedSurf_.points().size());
} }
return tfield; return tfield;
@ -577,6 +608,28 @@ Foam::tmp<Foam::Field<Type>> Foam::surfaceWriter::adjustFieldTemplate
// Apply scaling // Apply scaling
tadjusted.ref() *= value; tadjusted.ref() *= value;
} }
// Rotate fields (vector and non-spherical tensors)
if
(
(pTraits<Type>::rank != 0 && pTraits<Type>::nComponents > 1)
&& geometryTransform_.valid()
&& !geometryTransform_.R().is_identity()
)
{
if (!tadjusted)
{
// Steal or clone
tadjusted.reset(tfield.ptr());
}
Foam::transform
(
tadjusted.ref(),
geometryTransform_.R(),
tadjusted()
);
}
} }
return (tadjusted ? tadjusted : tfield); return (tadjusted ? tadjusted : tfield);

View File

@ -57,16 +57,28 @@ Description
{ {
"p.*" 0.01; // [Pa] -> [mbar] "p.*" 0.01; // [Pa] -> [mbar]
} }
scale 1000; // [m] -> [mm]
transform
{
origin (0 0 0);
rotation axisAngle;
axis (1 0 0);
angle 45;
}
} }
} }
\endverbatim \endverbatim
Format options: Format options:
\table \table
Property | Description | Required | Default Property | Description | Reqd | Default
verbose | Additional output verbosity | no | no verbose | Additional output verbosity | no | no
fieldLevel | Subtract field level before scaling | no | empty dict scale | Output geometry scaling | no | 1
fieldScale | Output field scaling | no | empty dict transform | Output coordinate transform | no |
fieldLevel | Subtract field level before scaling | no | empty dict
fieldScale | Output field scaling | no | empty dict
\endtable \endtable
Note Note
@ -83,10 +95,10 @@ SourceFiles
#ifndef Foam_surfaceWriter_H #ifndef Foam_surfaceWriter_H
#define Foam_surfaceWriter_H #define Foam_surfaceWriter_H
#include <functional>
#include "typeInfo.H" #include "typeInfo.H"
#include "autoPtr.H" #include "autoPtr.H"
#include "tmp.H" #include "tmp.H"
#include "cartesianCS.H"
#include "Field.H" #include "Field.H"
#include "fileName.H" #include "fileName.H"
#include "instant.H" #include "instant.H"
@ -118,23 +130,31 @@ class surfaceWriter
{ {
protected: protected:
// Static Data Members // Private Data
//- Placeholder //- Reference to surface or surface components
static const meshedSurf::emptySurface emptySurface_; meshedSurfRef surf_;
//- Surface after merging (parallel)
mutable mergedSurf mergedSurf_;
//- The surface after point coordinate transforms and scaling
mutable meshedSurfRef adjustedSurf_;
//- Dimension for merging
scalar mergeDim_;
//- Output geometry scaling after rotate/translate
scalar geometryScale_;
//- Local coordinate system transformation
coordSystem::cartesian geometryTransform_;
protected:
// Protected Data // Protected Data
//- Reference to a surface
std::reference_wrapper<const meshedSurf> surf_;
//- Reference to raw surface components
meshedSurfRef surfComp_;
//- Use raw surface components instead of surface reference
bool useComponents_;
//- The topology/surface is up-to-date? //- The topology/surface is up-to-date?
mutable bool upToDate_; mutable bool upToDate_;
@ -156,12 +176,6 @@ protected:
//- The number of fields //- The number of fields
label nFields_; label nFields_;
//- Dimension for merging
scalar mergeDim_;
//- Merging information and the resulting merged surface (parallel)
mutable mergedSurf merged_;
//- The current time value/name //- The current time value/name
instant currTime_; instant currTime_;
@ -184,10 +198,14 @@ protected:
//- or simply mark the surface as being up-to-date //- or simply mark the surface as being up-to-date
virtual bool merge() const; virtual bool merge() const;
//- Merge surfaces (if not upToDate) and return merged or //- Merge surfaces (if not upToDate) and return merged (parallel)
//- the regular surface //- or regular surface (non-parallel)
const meshedSurf& surface() const; const meshedSurf& surface() const;
//- Merge surfaces (if not upToDate) and return merged (parallel)
//- or regular surface (non-parallel)
//- and apply any coordinate system changes and/or output scaling.
const meshedSurfRef& adjustSurface() const;
//- Gather (merge) fields with renumbering and shrinking for point data //- Gather (merge) fields with renumbering and shrinking for point data
template<class Type> template<class Type>
@ -433,6 +451,16 @@ public:
// \return old value // \return old value
inline scalar mergeDim(const scalar dist) noexcept; inline scalar mergeDim(const scalar dist) noexcept;
//- The current value of the geometry scaling
inline scalar scale() const noexcept;
//- Change the geometry scaling
// \return old value
inline scalar scale(const scalar factor) noexcept;
//- The current (cartesian) coordinate system transformation
inline const coordSystem::cartesian& transform() const noexcept;
// Time // Time

View File

@ -103,6 +103,28 @@ inline Foam::scalar Foam::surfaceWriter::mergeDim(const scalar dist) noexcept
} }
inline Foam::scalar Foam::surfaceWriter::scale() const noexcept
{
return geometryScale_;
}
inline Foam::scalar Foam::surfaceWriter::scale(const scalar factor) noexcept
{
// This is probably not yet needed -> adjustedSurf_.clear();
scalar old(geometryScale_);
geometryScale_ = factor;
return old;
}
inline const Foam::coordSystem::cartesian&
Foam::surfaceWriter::transform() const noexcept
{
return geometryTransform_;
}
inline bool Foam::surfaceWriter::hasTime() const inline bool Foam::surfaceWriter::hasTime() const
{ {
return currTime_.name().size(); return currTime_.name().size();

View File

@ -45,7 +45,9 @@ Description
\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
scale | Output geometry scaling | no | 1
transform | Output coordinate transform | no |
fieldLevel | Subtract field level before scaling | no | empty dict fieldLevel | Subtract field level before scaling | no | empty dict
fieldScale | Output field scaling | no | empty dict fieldScale | Output field scaling | no | empty dict
\endtable \endtable

View File

@ -94,7 +94,8 @@ Foam::fileName Foam::surfaceWriters::ensightWriter::writeCollated
Info<< endl; Info<< endl;
} }
const meshedSurf& surf = surface(); // const meshedSurf& surf = surface();
const meshedSurfRef& surf = adjustSurface();
if (Pstream::master() || !parallel_) if (Pstream::master() || !parallel_)
{ {

View File

@ -59,7 +59,8 @@ Foam::fileName Foam::surfaceWriters::ensightWriter::writeUncollated()
} }
const meshedSurf& surf = surface(); // const meshedSurf& surf = surface();
const meshedSurfRef& surf = adjustSurface();
if (Pstream::master() || !parallel_) if (Pstream::master() || !parallel_)
{ {
@ -159,7 +160,8 @@ Foam::fileName Foam::surfaceWriters::ensightWriter::writeUncollated
Info<< endl; Info<< endl;
} }
const meshedSurf& surf = surface(); // const meshedSurf& surf = surface();
const meshedSurfRef& surf = adjustSurface();
if (Pstream::master() || !parallel_) if (Pstream::master() || !parallel_)
{ {

View File

@ -119,7 +119,8 @@ Foam::fileName Foam::surfaceWriters::foamWriter::write()
} }
const meshedSurf& surf = surface(); // const meshedSurf& surf = surface();
const meshedSurfRef& surf = adjustSurface();
if (Pstream::master() || !parallel_) if (Pstream::master() || !parallel_)
{ {

View File

@ -53,7 +53,9 @@ Description
\table \table
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 | Use file compression | no | false
scale | Output geometry scaling | no | 1
transform | Output coordinate transform | no |
fieldLevel | Subtract field level before scaling | no | empty dict fieldLevel | Subtract field level before scaling | no | empty dict
fieldScale | Output field scaling | no | empty dict fieldScale | Output field scaling | no | empty dict
\endtable \endtable

View File

@ -196,7 +196,7 @@ void Foam::surfaceWriters::nastranWriter::writeGeometry
forAll(points, pointi) forAll(points, pointi)
{ {
writeCoord(os, points[pointi]*geometryScale_, pointi); writeCoord(os, points[pointi], pointi);
} }
// Write faces, with on-the-fly decomposition (triangulation) // Write faces, with on-the-fly decomposition (triangulation)
@ -310,7 +310,6 @@ Foam::surfaceWriters::nastranWriter::nastranWriter()
writeFormat_(fieldFormat::SHORT), writeFormat_(fieldFormat::SHORT),
fieldMap_(), fieldMap_(),
commonGeometry_(false), commonGeometry_(false),
geometryScale_(1),
separator_() separator_()
{ {
// if (writeFormat_ == fieldFormat::FREE) // if (writeFormat_ == fieldFormat::FREE)
@ -337,7 +336,6 @@ Foam::surfaceWriters::nastranWriter::nastranWriter
), ),
fieldMap_(), fieldMap_(),
commonGeometry_(options.getOrDefault("commonGeometry", false)), commonGeometry_(options.getOrDefault("commonGeometry", false)),
geometryScale_(options.getOrDefault<scalar>("scale", 1)),
separator_() separator_()
{ {
if (writeFormat_ == fieldFormat::FREE) if (writeFormat_ == fieldFormat::FREE)
@ -411,7 +409,8 @@ Foam::fileName Foam::surfaceWriters::nastranWriter::write()
} }
const meshedSurf& surf = surface(); // const meshedSurf& surf = surface();
const meshedSurfRef& surf = adjustSurface();
if (Pstream::master() || !parallel_) if (Pstream::master() || !parallel_)
{ {

View File

@ -32,13 +32,14 @@ Description
The formatOptions for nastran: The formatOptions for nastran:
\table \table
Property | Description | Required | Default Property | Description | Reqd | Default
fields | field pairs for PLOAD2/PLOAD4 | yes | fields | Field pairs for PLOAD2/PLOAD4 | yes |
format | short / long / free | no | long format | Nastran format (short/long/free) | no | long
scale | output geometry scaling | no | 1 scale | Output geometry scaling | no | 1
transform | Output coordinate transform | no |
fieldLevel | Subtract field level before scaling | no | empty dict fieldLevel | Subtract field level before scaling | no | empty dict
fieldScale | Output field 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
For example, For example,
@ -144,9 +145,6 @@ private:
//- Use common geometry file //- Use common geometry file
bool commonGeometry_; bool commonGeometry_;
//- Output geometry scaling
const scalar geometryScale_;
//- Separator (used for free format) //- Separator (used for free format)
word separator_; word separator_;

View File

@ -232,7 +232,8 @@ Foam::fileName Foam::surfaceWriters::nastranWriter::writeTemplate
} }
const meshedSurf& surf = surface(); // const meshedSurf& surf = surface();
const meshedSurfRef& surf = adjustSurface();
if (Pstream::master() || !parallel_) if (Pstream::master() || !parallel_)
{ {

View File

@ -125,7 +125,8 @@ Foam::fileName Foam::surfaceWriters::proxyWriter::write()
Info<< "Writing geometry to " << outputFile << endl; Info<< "Writing geometry to " << outputFile << endl;
} }
const meshedSurf& surf = surface(); // const meshedSurf& surf = surface();
const meshedSurfRef& surf = adjustSurface();
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.
@ -51,7 +51,9 @@ Note
\table \table
Property | Description | Required | Default Property | Description | Required | Default
format | ascii/binary | no | ascii format | ascii/binary | no | ascii
compression | File compression | no | false compression | Use file compression | no | false
scale | Output geometry scaling | no | 1
transform | Output coordinate transform | no |
\endtable \endtable
SourceFiles SourceFiles

View File

@ -61,8 +61,7 @@ Foam::surfaceWriters::rawWriter::rawWriter()
surfaceWriter(), surfaceWriter(),
streamOpt_(), streamOpt_(),
precision_(IOstream::defaultPrecision()), precision_(IOstream::defaultPrecision()),
writeNormal_(false), writeNormal_(false)
geometryScale_(1)
{} {}
@ -81,8 +80,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))
{} {}
@ -137,7 +135,8 @@ Foam::fileName Foam::surfaceWriters::rawWriter::write()
} }
const meshedSurf& surf = surface(); // const meshedSurf& surf = surface();
const meshedSurfRef& surf = adjustSurface();
if (Pstream::master() || !parallel_) if (Pstream::master() || !parallel_)
{ {
@ -167,11 +166,11 @@ Foam::fileName Foam::surfaceWriters::rawWriter::write()
// Write faces centres (optionally faceArea normals) // Write faces centres (optionally faceArea normals)
for (const face& f : faces) for (const face& f : faces)
{ {
writePoint(os, f.centre(points)*geometryScale_); writePoint(os, f.centre(points));
if (withFaceNormal) if (withFaceNormal)
{ {
os << ' '; os << ' ';
writePoint(os, f.areaNormal(points)*geometryScale_); writePoint(os, f.areaNormal(points));
} }
os << nl; os << nl;
} }

View File

@ -34,8 +34,9 @@ Description
\table \table
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
transform | Output coordinate transform | no |
fieldLevel | Subtract field level before scaling | no | empty dict fieldLevel | Subtract field level before scaling | no | empty dict
fieldScale | Output field 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
@ -116,9 +117,6 @@ class rawWriter
//- Output face area normal //- Output face area normal
const bool writeNormal_; const bool writeNormal_;
//- Output geometry scaling
const scalar geometryScale_;
// Private Member Functions // Private Member Functions

View File

@ -114,7 +114,8 @@ Foam::fileName Foam::surfaceWriters::rawWriter::writeTemplate
Info<< " to " << outputFile << endl; Info<< " to " << outputFile << endl;
} }
const meshedSurf& surf = surface(); // const meshedSurf& surf = surface();
const meshedSurfRef& surf = adjustSurface();
if (Pstream::master() || !parallel_) if (Pstream::master() || !parallel_)
{ {
@ -159,7 +160,7 @@ Foam::fileName Foam::surfaceWriters::rawWriter::writeTemplate
// Node values // Node values
forAll(values, elemi) forAll(values, elemi)
{ {
writePoint(os, points[elemi]*geometryScale_); writePoint(os, points[elemi]);
writeData(os, values[elemi]); writeData(os, values[elemi]);
os << nl; os << nl;
} }
@ -171,12 +172,12 @@ Foam::fileName Foam::surfaceWriters::rawWriter::writeTemplate
{ {
const face& f = faces[elemi]; const face& f = faces[elemi];
writePoint(os, f.centre(points)*geometryScale_); writePoint(os, f.centre(points));
writeData(os, values[elemi]); writeData(os, values[elemi]);
if (withFaceNormal) if (withFaceNormal)
{ {
os << ' '; os << ' ';
writePoint(os, f.areaNormal(points)*geometryScale_); writePoint(os, f.areaNormal(points));
} }
os << nl; os << nl;
} }

View File

@ -137,7 +137,8 @@ Foam::fileName Foam::surfaceWriters::starcdWriter::write()
Info<< "Writing geometry to " << outputFile << endl; Info<< "Writing geometry to " << outputFile << endl;
} }
const meshedSurf& surf = surface(); // const meshedSurf& surf = surface();
const meshedSurfRef& surf = adjustSurface();
if (Pstream::master() || !parallel_) if (Pstream::master() || !parallel_)
{ {
@ -215,7 +216,8 @@ Foam::fileName Foam::surfaceWriters::starcdWriter::writeTemplate
} }
const meshedSurf& surf = surface(); // const meshedSurf& surf = surface();
const meshedSurfRef& surf = adjustSurface();
if (Pstream::master() || !parallel_) if (Pstream::master() || !parallel_)
{ {

View File

@ -34,6 +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
scale | Output geometry scaling | no | 1
transform | Output coordinate transform | no |
fieldLevel | Subtract field level before scaling | no | empty dict fieldLevel | Subtract field level before scaling | no | empty dict
fieldScale | Output field scaling | no | empty dict fieldScale | Output field scaling | no | empty dict
\endtable \endtable

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.
@ -212,7 +212,8 @@ Foam::fileName Foam::surfaceWriters::vtkWriter::write()
Info<< "Writing geometry to " << outputFile << endl; Info<< "Writing geometry to " << outputFile << endl;
} }
const meshedSurf& surf = surface(); // const meshedSurf& surf = surface();
const meshedSurfRef& surf = adjustSurface();
if (!writer_ && (Pstream::master() || !parallel_)) if (!writer_ && (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-2021 OpenCFD Ltd. Copyright (C) 2015-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -36,6 +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
scale | Output geometry scaling | no | 1
transform | Output coordinate transform | no |
fieldLevel | Subtract field level before scaling | no | empty dict fieldLevel | Subtract field level before scaling | no | empty dict
fieldScale | Output field 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

View File

@ -214,7 +214,8 @@ Foam::fileName Foam::surfaceWriters::x3dWriter::write()
Info<< "Writing geometry to " << outputFile << endl; Info<< "Writing geometry to " << outputFile << endl;
} }
const meshedSurf& surf = surface(); // const meshedSurf& surf = surface();
const meshedSurfRef& surf = adjustSurface();
if (Pstream::master() || !parallel_) if (Pstream::master() || !parallel_)
{ {
@ -278,7 +279,8 @@ Foam::fileName Foam::surfaceWriters::x3dWriter::writeTemplate
} }
const meshedSurf& surf = surface(); // const meshedSurf& surf = surface();
const meshedSurfRef& surf = adjustSurface();
if (Pstream::master() || !parallel_) if (Pstream::master() || !parallel_)
{ {

View File

@ -32,9 +32,11 @@ Description
The formatOptions for x3d: The formatOptions for x3d:
\table \table
Property | Description | Required | Default Property | Description | Required | Default
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
compression | Use file compression | no | false
scale | Output geometry scaling | no | 1
transform | Output coordinate transform | no |
fieldLevel | Subtract field level before scaling | no | empty dict fieldLevel | Subtract field level before scaling | no | empty dict
fieldScale | Output field scaling | no | empty dict fieldScale | Output field scaling | no | empty dict
\endtable \endtable

View File

@ -92,9 +92,9 @@ plane
libs (sampling); libs (sampling);
writeControl writeTime; writeControl writeTime;
fields ( cellZoneID U );
surfaceFormat vtk; surfaceFormat vtk;
fields ( cellZoneID U );
surfaces surfaces
{ {
@ -104,6 +104,25 @@ plane
point (0 0 0); point (0 0 0);
normal (0 0 1); normal (0 0 1);
interpolate false; interpolate false;
surfaceFormat ensight;
formatOptions
{
ensight
{
scale 2; // Some arbitrary scaling
// Align with global x-axis, translate by arbitrary amount
transform
{
origin (0.05 -0.05 0);
rotation axisAngle;
axis (0 0 1);
angle -45;
}
}
}
} }
slices slices
@ -122,6 +141,23 @@ plane
axis (0 0 1); axis (0 0 1);
angle 45; angle 45;
} }
formatOptions
{
vtk
{
scale 2; // Some arbitrary scaling
// Align with global x-axis, translate by arbitrary amount
transform
{
origin (0.05 0 0);
rotation axisAngle;
axis (0 0 1);
angle -45;
}
}
}
} }
} }
} }