ENH: improve surfaceFieldValue sampling and writing (#1999)

- ensure surface writing is time-step and nFields aware.
  This avoids overwriting (ignoring) previous output fields.

- allow sampled surfaces to be used for weight fields as well.
  Not sure why this restriction was still there.

- remove old compatibility reading of orientedFields.
  Last used in v1612, now removed.

- only use face sampling. For surfaceFieldValue we can only do
  something meaningful with face values.

ENH: modify interface methods for surfaceWriter

- replace direct modification of values with setter methods.
  Eg,
     old: writer.isPointData() = true;
     new: writer.isPointData(true);

  This makes it possible to add internal hooks to catch state changes.

ENH: allow post-construction change to sampledSurface interpolation

- rename interpolate() method to isPointData() for consistency with
  other classes and to indicate that it is a query.

- additional isPointData(bool) setter method to change the expected
  representation type after construction

- remove 'interpolate' restriction on isoSurfacePoint which was
  previously flagged as an error but within sampledSurfaces can use
  sampleScheme cellPoint and obtain representative samples.
  Relax this restriction since this particular iso-surface algorithm
  is slated for removal in the foreseeable future.
This commit is contained in:
Mark Olesen
2021-02-10 11:16:50 +01:00
parent 0990d30b73
commit 2954f55f6a
17 changed files with 176 additions and 148 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2016-2020 OpenCFD Ltd.
Copyright (C) 2016-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -652,13 +652,9 @@ Foam::sampledIsoSurface::sampledIsoSurface
// Not possible for ALGO_POINT
simpleSubMesh_ = false;
if (!sampledSurface::interpolate())
{
FatalIOErrorInFunction(dict)
<< "Non-interpolated iso-surface (point) not supported"
<< " since triangles span across cells." << nl
<< exit(FatalIOError);
}
// Previously emitted an error about using ALGO_POINT with
// non-interpolated, but that was before we had "sampleScheme"
// at the top level
if (isoValues_.size() > 1)
{

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2020 OpenCFD Ltd.
Copyright (C) 2016-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -70,6 +70,10 @@ Usage
- triangulate is topo-only
- simpleSubMesh and multiple isoValues are not available for point.
Note
For the isoMethod \b point should use a "cellPoint" sampleScheme
since the triangles generated with this algorithm span across cells.
SourceFiles
sampledIsoSurface.C
sampledIsoSurfaceTemplates.C
@ -215,7 +219,7 @@ protected:
public:
//- Runtime type information
TypeName("samplediIsoSurfacePoint");
TypeName("sampledIsoSurface");
// Constructors

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -60,6 +60,10 @@ Usage
mergeTol | tolerance for merging points | no | 1e-6
\endtable
Note
For the isoMethod \b point should use a "cellPoint" sampleScheme
since the triangles generated with this algorithm span across cells.
SourceFiles
sampledIsoSurfacePoint.C

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2020 OpenCFD Ltd.
Copyright (C) 2016-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -287,7 +287,7 @@ bool Foam::sampledMeshedSurface::update(const meshSearch& meshSearcher)
// Collect the samplePoints and sampleElements
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if (sampledSurface::interpolate())
if (sampledSurface::isPointData())
{
// With point interpolation
@ -422,7 +422,7 @@ bool Foam::sampledMeshedSurface::update(const meshSearch& meshSearcher)
: mesh().cellCentres()
);
if (sampledSurface::interpolate())
if (sampledSurface::isPointData())
{
label vertI = 0;
forAll(samplePoints_, pointi)

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018-2020 OpenCFD Ltd.
Copyright (C) 2018-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -97,7 +97,7 @@ Foam::sampledSurface::sampledSurface(const word& name, std::nullptr_t)
mesh_(NullObjectRef<polyMesh>()),
enabled_(true),
invariant_(false),
interpolate_(false),
isPointData_(false),
area_(-1)
{}
@ -106,14 +106,14 @@ Foam::sampledSurface::sampledSurface
(
const word& name,
const polyMesh& mesh,
const bool interpolate
const bool interpolateToPoints
)
:
name_(name),
mesh_(mesh),
enabled_(true),
invariant_(false),
interpolate_(interpolate),
isPointData_(interpolateToPoints),
area_(-1)
{}
@ -129,7 +129,7 @@ Foam::sampledSurface::sampledSurface
mesh_(mesh),
enabled_(dict.getOrDefault("enabled", true)),
invariant_(dict.getOrDefault("invariant", false)),
interpolate_(dict.getOrDefault("interpolate", false)),
isPointData_(dict.getOrDefault("interpolate", false)),
area_(-1)
{}
@ -155,6 +155,14 @@ Foam::scalar Foam::sampledSurface::area() const
}
bool Foam::sampledSurface::isPointData(const bool on)
{
bool old(isPointData_);
isPointData_ = on;
return old;
}
bool Foam::sampledSurface::withSurfaceFields() const
{
return false;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2020 OpenCFD Ltd.
Copyright (C) 2016-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -121,8 +121,8 @@ private:
//- Geometry is invariant (never changes)
bool invariant_;
//- Interpolate information to the nodes?
bool interpolate_;
//- Is point vs cell data
bool isPointData_;
//- Total surface area (demand-driven)
mutable scalar area_;
@ -249,7 +249,7 @@ public:
(
const word& name,
const polyMesh& mesh,
const bool interpolate = false
const bool interpolateToPoints = false
);
//- Construct from dictionary
@ -311,12 +311,16 @@ public:
return invariant_;
}
//- Interpolation to nodes requested for surface
bool interpolate() const
//- Using interpolation to surface points
bool isPointData() const
{
return interpolate_;
return isPointData_;
}
//- Change point/cell representation, may trigger an expire().
// \return old value
virtual bool isPointData(const bool on);
//- Does the surface need an update?
virtual bool needsUpdate() const = 0;
@ -561,6 +565,12 @@ public:
//- Print information
virtual void print(Ostream& os) const;
// Housekeeping
//- Same as isPointData()
bool interpolate() const { return isPointData_; }
};

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2016-2020 OpenCFD Ltd.
Copyright (C) 2016-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -171,14 +171,14 @@ void Foam::sampledSurfaces::countFields()
const sampledSurface& s = (*this)[surfi];
surfaceWriter& outWriter = writers_[surfi];
outWriter.nFields() =
outWriter.nFields
(
nVolumeFields
+ (s.withSurfaceFields() ? nSurfaceFields : 0)
+
(
// Face-id field, but not if the writer manages that itself
!s.interpolate() && s.hasFaceIds() && !outWriter.usesFaceIds()
!s.isPointData() && s.hasFaceIds() && !outWriter.usesFaceIds()
? 1 : 0
)
);
@ -360,7 +360,7 @@ bool Foam::sampledSurfaces::read(const dictionary& dict)
newWriter(writerType, formatOptions, surfDict)
);
writers_[surfi].isPointData() = surfs[surfi].interpolate();
writers_[surfi].isPointData(surfs[surfi].isPointData());
// Use outputDir/TIME/surface-name
writers_[surfi].useTimeDir(true);
@ -426,7 +426,7 @@ bool Foam::sampledSurfaces::read(const dictionary& dict)
newWriter(writerType, formatOptions, surfDict)
);
writers_[surfi].isPointData() = surfs[surfi].interpolate();
writers_[surfi].isPointData(surfs[surfi].isPointData());
// Use outputDir/TIME/surface-name
writers_[surfi].useTimeDir(true);
@ -565,7 +565,7 @@ bool Foam::sampledSurfaces::performAction(unsigned request)
outWriter.beginTime(obr_.time());
// Face-id field, but not if the writer manages that itself
if (!s.interpolate() && s.hasFaceIds() && !outWriter.usesFaceIds())
if (!s.isPointData() && s.hasFaceIds() && !outWriter.usesFaceIds())
{
// This is still quite horrible.
@ -723,7 +723,7 @@ bool Foam::sampledSurfaces::expire(const bool force)
}
writers_[surfi].expire();
writers_[surfi].mergeDim() = mergeDim;
writers_[surfi].mergeDim(mergeDim);
nFaces_[surfi] = 0;
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015-2020 OpenCFD Ltd.
Copyright (C) 2015-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -108,7 +108,7 @@ void Foam::sampledSurfaces::performAction
Field<Type> values;
if (s.interpolate())
if (s.isPointData())
{
if (!interpPtr)
{
@ -151,7 +151,7 @@ void Foam::sampledSurfaces::performAction
if ((request & actions_[surfi]) & ACTION_STORE)
{
if (s.interpolate())
if (s.isPointData())
{
storeRegistryField<Type, polySurfacePointGeoMesh>
(