Commit b0648f2b authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: improvements in the surface sampling infrastructure

- improvement documentation for surface sampling.

- can now specify alternative sampling scheme for obtaining the
  face values instead of just using the "cell" value. For example,

      sampleScheme    cellPoint;

  This can be useful for cases when the surface is close to a boundary
  cell and there are large gradients in the sampled field.

- distanceSurface now handles non-closed surfaces more robustly.
  Unknown regions (not inside or outside) are marked internally and
  excluded from consideration. This allows use of 'signed' surfaces
  where not previously possible.
parent 5268b5e6
......@@ -35,9 +35,7 @@ License
namespace Foam
{
defineTypeNameAndDebug(pointMesh, 0);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
......@@ -88,18 +86,6 @@ Foam::pointMesh::pointMesh(const polyMesh& pMesh)
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::pointMesh::~pointMesh()
{
if (debug)
{
Pout<< "~pointMesh::pointMesh()"
<< endl;
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::pointMesh::movePoints()
......@@ -121,8 +107,7 @@ void Foam::pointMesh::updateMesh(const mapPolyMesh& mpm)
if (debug)
{
Pout<< "pointMesh::updateMesh(const mapPolyMesh&): "
<< "Updating for topology changes." << endl;
Pout<< endl;
<< "Updating for topology changes." << nl << endl;
}
boundary_.updateMesh();
......
......@@ -60,13 +60,13 @@ class pointMesh
// Private Member Functions
//- Map all fields
void mapFields(const mapPolyMesh&);
void mapFields(const mapPolyMesh& mpm);
//- Disallow default bitwise copy construct
pointMesh(const pointMesh&);
//- No copy construct
pointMesh(const pointMesh&) = delete;
//- Disallow default bitwise assignment
void operator=(const pointMesh&);
//- No copy assignment
void operator=(const pointMesh&) = delete;
public:
......@@ -86,7 +86,7 @@ public:
//- Destructor
~pointMesh();
~pointMesh() = default;
// Member Functions
......@@ -122,13 +122,13 @@ public:
}
// Mesh motion
// Mesh motion
//- Move points
bool movePoints();
//- Move points
bool movePoints();
//- Update the mesh corresponding to given map
void updateMesh(const mapPolyMesh& mpm);
//- Update the mesh corresponding to given map
void updateMesh(const mapPolyMesh& mpm);
// Member Operators
......
......@@ -34,25 +34,19 @@ void Foam::plane::calcPntAndVec(const scalarList& C)
{
point_ = vector((-C[3]/C[0]), 0, 0);
}
else if (mag(C[1]) > VSMALL)
{
point_ = vector(0, (-C[3]/C[1]), 0);
}
else if (mag(C[2]) > VSMALL)
{
point_ = vector(0, 0, (-C[3]/C[2]));
}
else
{
if (mag(C[1]) > VSMALL)
{
point_ = vector(0, (-C[3]/C[1]), 0);
}
else
{
if (mag(C[2]) > VSMALL)
{
point_ = vector(0, 0, (-C[3]/C[2]));
}
else
{
FatalErrorInFunction
<< "At least one plane coefficient must have a value"
<< abort(FatalError);
}
}
FatalErrorInFunction
<< "At least one plane coefficient must have a value"
<< abort(FatalError);
}
normal_ = vector(C[0], C[1], C[2]);
......@@ -127,7 +121,7 @@ Foam::plane::plane(const vector& normalVector)
else
{
FatalErrorInFunction
<< "plane normal has zero length. basePoint:" << point_
<< "plane normal has zero length. base point:" << point_
<< abort(FatalError);
}
}
......@@ -148,7 +142,7 @@ Foam::plane::plane
if (magSqrNormalVector < VSMALL)
{
FatalErrorInFunction
<< "plane normal has zero length. basePoint:" << point_
<< "plane normal has zero length. base point:" << point_
<< abort(FatalError);
}
......@@ -247,7 +241,7 @@ Foam::plane::plane(Istream& is)
else
{
FatalErrorInFunction
<< "plane normal has zero length. basePoint:" << point_
<< "plane normal has zero length. base point:" << point_
<< abort(FatalError);
}
}
......
......@@ -28,6 +28,40 @@ Description
Geometric class that creates a 3D plane and can return the intersection
point between a line and the plane.
Construction from a dictionary is driven by the \c planeType
For \c planeType as \c pointAndNormal :
\verbatim
pointAndNormalDict
{
point <point>; // or basePoint
normal <vector>; // or normalVector
}
\endverbatim
For \c planeType as \c embeddedPoints :
\verbatim
embeddedPointsDict
{
point1 <point>;
point2 <point>;
point3 <point>;
}
\endverbatim
For \c planeType with \c planeEquation coefficients
\f$ ax + by + cz + d = 0 \f$ :
\verbatim
planeEquationDict
{
a <scalar>;
b <scalar>;
c <scalar>;
d <scalar>;
}
\endverbatim
SourceFiles
plane.C
......@@ -63,10 +97,11 @@ public:
//- Side of the plane
enum side
{
NORMAL,
FLIP
NORMAL = 1, //!< The front (or normal) side of the plane
FLIP = -1 //!< The back (or flip) side of the plane
};
//- A direction and a reference point
class ray
{
......@@ -126,10 +161,12 @@ public:
//- Construct null. Does not set normal and point.
plane();
//- Construct from normal vector through the origin
//- Construct from normal vector through the origin.
// The vector is normalised to a unit vector on input.
explicit plane(const vector& normalVector);
//- Construct from normal vector and point in plane
//- Construct from normal vector and point in plane.
// By default, the vector is normalised to a unit vector on input.
explicit plane
(
const point& basePoint,
......@@ -150,7 +187,7 @@ public:
explicit plane(const scalarList& C);
//- Construct from dictionary
explicit plane(const dictionary& planeDict);
explicit plane(const dictionary& dict);
//- Construct from Istream. Assumes the base + normal notation.
explicit plane(Istream& is);
......
......@@ -45,7 +45,7 @@ Description
\endtable
The values are assigned according to the phase-fraction field:
- 1: apply \$fp_{hyd}\$f
- 1: apply \f$p_{hyd}\f$
- 0: apply a zero-gradient condition
Usage
......
......@@ -42,7 +42,7 @@ namespace Foam
class fvMesh;
/*---------------------------------------------------------------------------*\
Class interpolationCell Declaration
Class interpolationCell Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
......
......@@ -64,20 +64,20 @@ class volPointInterpolation
scalarListList pointWeights_;
// Boundary handling
// Boundary handling
//- Boundary addressing
autoPtr<primitivePatch> boundaryPtr_;
//- Boundary addressing
autoPtr<primitivePatch> boundaryPtr_;
//- Per boundary face whether is on non-coupled patch
boolList boundaryIsPatchFace_;
//- Per boundary face whether is on non-coupled patch
boolList boundaryIsPatchFace_;
//- Per mesh(!) point whether is on non-coupled patch (on any
// processor)
boolList isPatchPoint_;
//- Per mesh(!) point whether is on non-coupled patch (on any
// processor)
boolList isPatchPoint_;
//- Per boundary point the weights per pointFaces.
scalarListList boundaryPointWeights_;
//- Per boundary point the weights per pointFaces.
scalarListList boundaryPointWeights_;
// Private Member Functions
......@@ -113,11 +113,11 @@ class volPointInterpolation
GeometricField<Type, pointPatchField, pointMesh>&
) const;
//- Disallow default bitwise copy construct
volPointInterpolation(const volPointInterpolation&);
//- No copy construct
volPointInterpolation(const volPointInterpolation&) = delete;
//- Disallow default bitwise assignment
void operator=(const volPointInterpolation&);
//- No copy assignment
void operator=(const volPointInterpolation&) = delete;
public:
......@@ -138,19 +138,19 @@ public:
// Member functions
// Edit
// Edit
//- Update mesh topology using the morph engine
void updateMesh(const mapPolyMesh&);
//- Update mesh topology using the morph engine
void updateMesh(const mapPolyMesh&);
//- Correct weighting factors for moving mesh.
bool movePoints();
//- Correct weighting factors for moving mesh.
bool movePoints();
// Interpolation functions
// Interpolation Functions
//- Interpolate volField using inverse distance weighting
// returning pointField
// \return pointField
template<class Type>
tmp<GeometricField<Type, pointPatchField, pointMesh>> interpolate
(
......@@ -158,7 +158,7 @@ public:
) const;
//- Interpolate tmp<volField> using inverse distance weighting
// returning pointField
// \return pointField
template<class Type>
tmp<GeometricField<Type, pointPatchField, pointMesh>> interpolate
(
......@@ -188,7 +188,7 @@ public:
) const;
//- Interpolate dimensionedField using inverse distance weighting
// returning pointField
// \return pointField
template<class Type>
tmp<DimensionedField<Type, pointMesh>> interpolate
(
......@@ -204,82 +204,82 @@ public:
) const;
// Low level
//- Interpolate internal field from volField to pointField
// using inverse distance weighting
template<class Type>
void interpolateInternalField
(
const GeometricField<Type, fvPatchField, volMesh>&,
GeometricField<Type, pointPatchField, pointMesh>&
) const;
//- Interpolate boundary field without applying constraints/boundary
// conditions
template<class Type>
void interpolateBoundaryField
(
const GeometricField<Type, fvPatchField, volMesh>& vf,
GeometricField<Type, pointPatchField, pointMesh>& pf
) const;
//- Interpolate boundary with constraints/boundary conditions
template<class Type>
void interpolateBoundaryField
(
const GeometricField<Type, fvPatchField, volMesh>& vf,
GeometricField<Type, pointPatchField, pointMesh>& pf,
const bool overrideFixedValue
) const;
//- Interpolate from volField to pointField
// using inverse distance weighting
template<class Type>
void interpolate
(
const GeometricField<Type, fvPatchField, volMesh>&,
GeometricField<Type, pointPatchField, pointMesh>&
) const;
//- Interpolate volField using inverse distance weighting
// returning pointField with name. Optionally caches
template<class Type>
tmp<GeometricField<Type, pointPatchField, pointMesh>> interpolate
(
const GeometricField<Type, fvPatchField, volMesh>&,
const word& name,
const bool cache
) const;
//- Interpolate dimensioned internal field from cells to points
// using inverse distance weighting
template<class Type>
void interpolateDimensionedInternalField
(
const DimensionedField<Type, volMesh>& vf,
DimensionedField<Type, pointMesh>& pf
) const;
//- Interpolate dimensionedField using inverse distance weighting
// returning pointField with name. Optionally caches
template<class Type>
tmp<DimensionedField<Type, pointMesh>> interpolate
(
const DimensionedField<Type, volMesh>&,
const word& name,
const bool cache
) const;
// Interpolation for displacement (applies 2D correction)
//- Interpolate from volField to pointField
// using inverse distance weighting
void interpolateDisplacement
(
const volVectorField&,
pointVectorField&
) const;
// Low level
//- Interpolate internal field from volField to pointField
// using inverse distance weighting
template<class Type>
void interpolateInternalField
(
const GeometricField<Type, fvPatchField, volMesh>&,
GeometricField<Type, pointPatchField, pointMesh>&
) const;
//- Interpolate boundary field without applying constraints/boundary
// conditions
template<class Type>
void interpolateBoundaryField
(
const GeometricField<Type, fvPatchField, volMesh>& vf,
GeometricField<Type, pointPatchField, pointMesh>& pf
) const;
//- Interpolate boundary with constraints/boundary conditions
template<class Type>
void interpolateBoundaryField
(
const GeometricField<Type, fvPatchField, volMesh>& vf,
GeometricField<Type, pointPatchField, pointMesh>& pf,
const bool overrideFixedValue
) const;
//- Interpolate from volField to pointField
// using inverse distance weighting
template<class Type>
void interpolate
(
const GeometricField<Type, fvPatchField, volMesh>&,
GeometricField<Type, pointPatchField, pointMesh>&
) const;
//- Interpolate volField using inverse distance weighting
// returning pointField with name. Optionally caches
template<class Type>
tmp<GeometricField<Type, pointPatchField, pointMesh>> interpolate
(
const GeometricField<Type, fvPatchField, volMesh>&,
const word& name,
const bool cache
) const;
//- Interpolate dimensioned internal field from cells to points
// using inverse distance weighting
template<class Type>
void interpolateDimensionedInternalField
(
const DimensionedField<Type, volMesh>& vf,
DimensionedField<Type, pointMesh>& pf
) const;
//- Interpolate dimensionedField using inverse distance weighting
// returning pointField with name. Optionally caches
template<class Type>
tmp<DimensionedField<Type, pointMesh>> interpolate
(
const DimensionedField<Type, volMesh>&,
const word& name,
const bool cache
) const;
// Interpolation for displacement (applies 2D correction)
//- Interpolate from volField to pointField
// using inverse distance weighting
void interpolateDisplacement
(
const volVectorField&,
pointVectorField&
) const;
};
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -29,6 +29,7 @@ License
#include "volFields.H"
#include "sampledSurface.H"
#include "surfaceWriter.H"
#include "interpolationCell.H"
#include "interpolationCellPoint.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
......@@ -100,18 +101,15 @@ Foam::functionObjects::fieldValues::surfaceFieldValue::getFieldValues
// Average
const faceList& faces = surfacePtr_().faces();
tmp<Field<Type>> tavg
(
new Field<Type>(faces.size(), Zero)
);
Field<Type>& avg = tavg.ref();
auto tavg = tmp<Field<Type>>::New(faces.size(), Zero);
auto& avg = tavg.ref();
forAll(faces, facei)
{
const face& f = faces[facei];
forAll(f, fp)
for (const label labi : f)
{
avg[facei] += intFld[f[fp]];
avg[facei] += intFld[labi];
}
avg[facei] /= f.size();
}
......@@ -120,7 +118,9 @@ Foam::functionObjects::fieldValues::surfaceFieldValue::getFieldValues
}
else
{
return surfacePtr_().sample(fld);
const interpolationCell<Type> interp(fld);
return surfacePtr_().sample(interp);
}
}
else
......
......@@ -19,22 +19,24 @@ sampledSet/array/arraySet.C
sampledSet/shortestPath/shortestPathSet.C
surface/cuttingPlane/cuttingPlane.C
surface/distanceSurface/distanceSurface.C
surface/isoSurface/isoSurface.C
surface/isoSurface/isoSurfaceCell.C
surface/thresholdCellFaces/thresholdCellFaces.C
surface/triSurfaceMesh/discreteSurface.C
surfMeshSampler/surfMeshSampler/surfMeshSampler.C
surfMeshSampler/surfMeshSamplers/surfMeshSamplers.C
surfMeshSampler/plane/surfMeshPlaneSampler.C
surfMeshSampler/triSurfaceMesh/surfMeshDiscreteSampler.C
surfMeshSample/surfMeshSample/surfMeshSample.C
surfMeshSample/surfMeshSamplers/surfMeshSamplers.C
surfMeshSample/distanceSurface/surfMeshSampleDistanceSurface.C
surfMeshSample/plane/surfMeshSamplePlane.C
surfMeshSample/triSurfaceMesh/surfMeshSampleDiscrete.C
sampledSurface/sampledPatch/sampledPatch.C
sampledSurface/sampledPatchInternalField/sampledPatchInternalField.C
sampledSurface/sampledPlane/sampledPlane.C
sampledSurface/isoSurface/sampledIsoSurface.C
sampledSurface/isoSurface/sampledIsoSurfaceCell.C
sampledSurface/distanceSurface/distanceSurface.C
sampledSurface/distanceSurface/sampledDistanceSurface.C
sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C
sampledSurface/sampledSurface/sampledSurface.C
sampledSurface/sampledSurfaces/sampledSurfaces.C
......
......@@ -214,8 +214,7 @@ Foam::label Foam::probes::prepare()
{
probeDir = mesh_.time().path()/probeSubDir;
}
// Remove ".."
probeDir.clean();
probeDir.clean(); // Remove unneeded ".."
// ignore known fields, close streams for fields that no longer exist
forAllIter(HashPtrTable<OFstream>, probeFilePtrs_, iter)
......
......@@ -109,8 +109,7 @@ Foam::sampledSets::sampledSets
{
outputPath_ = outputPath_/mesh_.name();