ENH: minor changes to rationalize sampledSurface

- make hasFaceId a top-level virtual method and remove keepIds
  equivalent from sampledTriSurfaceMesh. This makes the property
  available without casting.

- New sampling type 'none'.
  Can be used to temporarily disable a sampling surface definition,
  or to provide boilerplate for overwriting later.
This commit is contained in:
Mark Olesen
2018-10-19 16:02:44 +02:00
parent b76f2421dc
commit d63b4cd4f4
11 changed files with 412 additions and 89 deletions

View File

@ -38,6 +38,7 @@ surfMeshSample/distanceSurface/surfMeshSampleDistanceSurface.C
surfMeshSample/plane/surfMeshSamplePlane.C
surfMeshSample/triSurfaceMesh/surfMeshSampleDiscrete.C
sampledSurface/sampledNone/sampledNone.C
sampledSurface/sampledPatch/sampledPatch.C
sampledSurface/sampledPatchInternalField/sampledPatchInternalField.C
sampledSurface/sampledPlane/sampledPlane.C

View File

@ -0,0 +1,107 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "sampledNone.H"
#include "dictionary.H"
#include "polyMesh.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(sampledNone, 0);
addNamedToRunTimeSelectionTable(sampledSurface, sampledNone, word, none);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::sampledNone::sampledNone()
:
sampledSurface(word::null, nullptr)
{}
Foam::sampledNone::sampledNone(const word& name)
:
sampledSurface(name, nullptr)
{}
Foam::sampledNone::sampledNone
(
const word& name,
const polyMesh& mesh,
const dictionary& dict
)
:
sampledSurface(name, nullptr)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::sampledNone::needsUpdate() const
{
return false;
}
bool Foam::sampledNone::expire()
{
return false;
}
bool Foam::sampledNone::update()
{
return false;
}
#undef makeDummy
#define makeDummy(Func,Type) \
Foam::tmp<Foam::Field<Foam::Type>> \
Foam::sampledNone::Func(const interpolation<Type>&) const \
{ \
return tmp<Field<Type>>::New(); \
}
makeDummy(sample, scalar);
makeDummy(sample, vector);
makeDummy(sample, sphericalTensor);
makeDummy(sample, symmTensor);
makeDummy(sample, tensor);
makeDummy(interpolate, scalar);
makeDummy(interpolate, vector);
makeDummy(interpolate, sphericalTensor);
makeDummy(interpolate, symmTensor);
makeDummy(interpolate, tensor);
#undef makeDummy
// ************************************************************************* //

View File

@ -0,0 +1,211 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::sampledNone
Description
A no operation sampledSurface that can be used when a sampler
is expected but is not desired. For example, to temporarily disable
a sampling definition, or to provide a boilerplate definition that
is overwritten at a later stage in a dictionary.
Usage
\table
Property | Description | Required | Default
type | 'none' | yes |
\endtable
SourceFiles
sampledNone.C
\*---------------------------------------------------------------------------*/
#ifndef sampledNone_H
#define sampledNone_H
#include "sampledSurface.H"
#include "MeshedSurfaces.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class sampledNone Declaration
\*---------------------------------------------------------------------------*/
class sampledNone
:
public meshedSurface,
public sampledSurface
{
typedef meshedSurface Mesh;
public:
//- Runtime type information
TypeName("sampledNone");
// Constructors
//- Construct null
explicit sampledNone();
//- Construct null, with specified name
explicit sampledNone(const word& name);
//- Construct null, with dictionary
sampledNone(const word& name, const polyMesh&, const dictionary&);
//- Destructor
virtual ~sampledNone() = default;
// Member Functions
//- Does the surface need an update?
virtual bool needsUpdate() const;
//- Mark the surface as needing an update.
virtual bool expire();
//- Update the surface as required.
virtual bool update();
//- Points of surface
virtual const pointField& points() const
{
return Mesh::points();
}
//- Faces of surface
virtual const faceList& faces() const
{
return Mesh::surfFaces();
}
//- Const access to per-face zone/region information
virtual const labelList& zoneIds() const
{
return Foam::emptyLabelList;
}
//- Face area magnitudes
virtual const vectorField& Sf() const
{
return Mesh::Sf();
}
//- Face area magnitudes
virtual const scalarField& magSf() const
{
return Mesh::magSf();
}
//- Face centres
virtual const vectorField& Cf() const
{
return Mesh::Cf();
}
// Sample
//- Sample volume field onto surface faces
virtual tmp<scalarField> sample
(
const interpolation<scalar>& sampler
) const;
//- Sample volume field onto surface faces
virtual tmp<vectorField> sample
(
const interpolation<vector>& sampler
) const;
//- Sample volume field onto surface faces
virtual tmp<sphericalTensorField> sample
(
const interpolation<sphericalTensor>& sampler
) const;
//- Sample volume field onto surface faces
virtual tmp<symmTensorField> sample
(
const interpolation<symmTensor>& sampler
) const;
//- Sample volume field onto surface faces
virtual tmp<tensorField> sample
(
const interpolation<tensor>& sampler
) const;
// Interpolate
//- Interpolate volume field onto surface points
virtual tmp<scalarField> interpolate
(
const interpolation<scalar>& interpolator
) const;
//- Interpolate volume field onto surface points
virtual tmp<vectorField> interpolate
(
const interpolation<vector>& interpolator
) const;
//- Interpolate volume field onto surface points
virtual tmp<sphericalTensorField> interpolate
(
const interpolation<sphericalTensor>& interpolator
) const;
//- Interpolate volume field onto surface points
virtual tmp<symmTensorField> interpolate
(
const interpolation<symmTensor>& interpolator
) const;
//- Interpolate volume field onto surface points
virtual tmp<tensorField> interpolate
(
const interpolation<tensor>& interpolator
) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -27,7 +27,6 @@ License
#include "polyMesh.H"
#include "demandDrivenData.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
@ -37,7 +36,7 @@ namespace Foam
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::sampledSurface::clearGeom() const
{
@ -79,6 +78,15 @@ Foam::autoPtr<Foam::sampledSurface> Foam::sampledSurface::New
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::sampledSurface::sampledSurface(const word& name, std::nullptr_t)
:
name_(name),
mesh_(NullObjectRef<polyMesh>()),
interpolate_(false),
area_(-1)
{}
Foam::sampledSurface::sampledSurface
(
const word& name,
@ -123,8 +131,7 @@ Foam::scalar Foam::sampledSurface::area() const
{
if (area_ < 0)
{
area_ = sum(magSf());
reduce(area_, sumOp<scalar>());
area_ = gSum(magSf());
}
return area_;
@ -187,7 +194,7 @@ void Foam::sampledSurface::print(Ostream& os) const
}
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
Foam::Ostream& Foam::operator<<(Ostream& os, const sampledSurface& s)
{

View File

@ -70,12 +70,6 @@ SourceFiles
namespace Foam
{
// Forward declarations
class sampledSurface;
Ostream& operator<<(Ostream& os, const sampledSurface& s);
/*---------------------------------------------------------------------------*\
Class sampledSurface Declaration
\*---------------------------------------------------------------------------*/
@ -84,6 +78,8 @@ class sampledSurface
:
public meshedSurf
{
private:
// Private data
//- Name of sample surface
@ -127,6 +123,8 @@ protected:
virtual void clearGeom() const;
//- Construct null
explicit sampledSurface(const word& name, std::nullptr_t);
public:
@ -180,7 +178,7 @@ public:
sampledSurface
(
const word& name,
const polyMesh&,
const polyMesh& mesh,
const bool interpolate = false
);
@ -188,8 +186,8 @@ public:
sampledSurface
(
const word& name,
const polyMesh&,
const dictionary&
const polyMesh& mesh,
const dictionary& dict
);
//- Clone
@ -206,8 +204,8 @@ public:
static autoPtr<sampledSurface> New
(
const word& name,
const polyMesh&,
const dictionary&
const polyMesh& mesh,
const dictionary& dict
);
@ -267,6 +265,21 @@ public:
//- The total surface area
scalar area() const;
//- If element ids/order of the original surface are available
virtual bool hasFaceIds() const
{
return false;
}
//- List of element ids/order of the original surface,
//- when hasFaceIds is true.
const labelList& originalIds() const
{
return Foam::emptyLabelList;
}
// Sample (faces)
//- Sample volume field onto surface faces
virtual tmp<scalarField> sample
@ -330,6 +343,8 @@ public:
) const;
// Interpolate (points)
//- Interpolate volume field onto surface points
virtual tmp<scalarField> interpolate
(
@ -374,12 +389,14 @@ public:
//- Print information
virtual void print(Ostream& os) const;
//- Ostream operator
friend Ostream& operator<<(Ostream& os, const sampledSurface& s);
};
// Global Operators
//- Ostream operator
Ostream& operator<<(Ostream& os, const sampledSurface& s);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam

View File

@ -58,7 +58,7 @@ Foam::scalar Foam::sampledSurfaces::mergeTol_ = 1e-10;
void Foam::sampledSurfaces::writeGeometry() const
{
// Write to time directory under outputPath_
// Skip surface without faces (eg, a failed cut-plane)
// Skip surfaces without faces (eg, a failed cut-plane)
const fileName outputDir = outputPath_/time_.timeName();
@ -95,23 +95,18 @@ void Foam::sampledSurfaces::writeOriginalIds()
{
const sampledSurface& s = operator[](surfi);
if (isA<sampledTriSurfaceMesh>(s))
if (s.hasFaceIds())
{
const sampledTriSurfaceMesh& surf =
dynamicCast<const sampledTriSurfaceMesh&>(s);
const labelList& idLst = s.originalIds();
if (surf.keepIds())
// Transcribe from label to scalar
Field<scalar> ids(idLst.size());
forAll(idLst, i)
{
const labelList& idLst = surf.originalIds();
Field<scalar> ids(idLst.size());
forAll(idLst, i)
{
ids[i] = idLst[i];
}
writeSurface(ids, surfi, fieldName, outputDir);
ids[i] = idLst[i];
}
writeSurface(ids, surfi, fieldName, outputDir);
}
}
}
@ -130,25 +125,17 @@ Foam::sampledSurfaces::sampledSurfaces
PtrList<sampledSurface>(),
mesh_(refCast<const fvMesh>(obr_)),
loadFromFiles_(false),
outputPath_(fileName::null),
outputPath_
(
time_.globalPath()/functionObject::outputPrefix/name
),
fieldSelection_(),
sampleFaceScheme_(word::null),
sampleNodeScheme_(word::null),
sampleFaceScheme_(),
sampleNodeScheme_(),
mergedList_(),
changedGeom_(),
formatter_(nullptr)
{
const fileName relPath(functionObject::outputPrefix/name);
if (Pstream::parRun())
{
outputPath_ = mesh_.time().path()/".."/relPath;
}
else
{
outputPath_ = mesh_.time().path()/relPath;
}
outputPath_.clean(); // Remove unneeded ".."
read(dict);
@ -167,39 +154,23 @@ Foam::sampledSurfaces::sampledSurfaces
PtrList<sampledSurface>(),
mesh_(refCast<const fvMesh>(obr)),
loadFromFiles_(loadFromFiles),
outputPath_(fileName::null),
outputPath_
(
time_.globalPath()/functionObject::outputPrefix/name
),
fieldSelection_(),
sampleFaceScheme_(word::null),
sampleNodeScheme_(word::null),
sampleFaceScheme_(),
sampleNodeScheme_(),
mergedList_(),
changedGeom_(),
formatter_(nullptr)
{
read(dict);
const fileName relPath(functionObject::outputPrefix/name);
if (Pstream::parRun())
{
outputPath_ = time_.path()/".."/relPath;
}
else
{
outputPath_ = time_.path()/relPath;
}
outputPath_.clean(); // Remove unneeded ".."
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::sampledSurfaces::~sampledSurfaces()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::sampledSurfaces::verbose(const bool verbosity)
@ -388,13 +359,13 @@ bool Foam::sampledSurfaces::expire()
bool Foam::sampledSurfaces::update()
{
bool updated = false;
if (!needsUpdate())
{
return updated;
return false;
}
bool updated = false;
// Serial: quick and easy, no merging required
if (!Pstream::parRun())
{

View File

@ -178,6 +178,17 @@ class sampledSurfaces
// Private Member Functions
//- Return the surfaces
const PtrList<sampledSurface>& surfaces() const
{
return *this;
}
//- Return the surfaces
PtrList<sampledSurface>& surfaces()
{
return *this;
}
//- Return number of fields
label classifyFields();
@ -251,7 +262,7 @@ public:
//- Destructor
virtual ~sampledSurfaces();
virtual ~sampledSurfaces() = default;
// Member Functions

View File

@ -288,14 +288,14 @@ public:
}
//- If element ids/order of the original surface are kept
bool keepIds() const
virtual bool hasFaceIds() const
{
return keepIds_;
}
//- List of element ids/order of the original surface,
// when keepIds is active.
const labelList& originalIds() const
virtual const labelList& originalIds() const
{
return originalIds_;
}

View File

@ -180,14 +180,14 @@ public:
}
//- If element ids/order of the original surface are kept
bool keepIds() const
virtual bool hasFaceIds() const
{
return MeshStorage::keepIds();
return MeshStorage::hasFaceIds();
}
//- List of element ids/order of the original surface,
// when keepIds is active.
const labelList& originalIds() const
virtual const labelList& originalIds() const
{
return MeshStorage::originalIds();
}

View File

@ -651,8 +651,8 @@ Foam::discreteSurface::discreteSurface
keepIds_(false),
originalIds_(),
zoneIds_(),
sampleElements_(0),
samplePoints_(0)
sampleElements_(),
samplePoints_()
{}
@ -689,8 +689,8 @@ Foam::discreteSurface::discreteSurface
keepIds_(dict.lookupOrDefault("keepIds", false)),
originalIds_(),
zoneIds_(),
sampleElements_(0),
samplePoints_(0)
sampleElements_(),
samplePoints_()
{}
@ -726,8 +726,8 @@ Foam::discreteSurface::discreteSurface
keepIds_(false),
originalIds_(),
zoneIds_(),
sampleElements_(0),
samplePoints_(0)
sampleElements_(),
samplePoints_()
{}

View File

@ -275,26 +275,24 @@ public:
}
//- If element ids/order of the original surface are kept
bool keepIds() const
virtual bool hasFaceIds() const
{
return keepIds_;
}
//- List of element ids/order of the original surface,
// when keepIds is active.
const labelList& originalIds() const
virtual const labelList& originalIds() const
{
return originalIds_;
}
//- Sampling boundary values instead of cell values
bool onBoundary() const
{
return sampleSource_ == boundaryFaces;
}
//- From local surface face to mesh cell/face.
const labelList& sampleElements() const
{