nearWallDist, wallDist: Parallel consistentency and finer control

The near wall distances calculated for use in wall functions and the
corrections applied to near wall cells as part of the meshWave
wall/patch distance method have been made consistent across processor
and cyclic boundaries.

The extent to which these corrections are performed in the meshWave
method is now controllable by an nCorrectors entry. This defaults to 2,
which produces a result rougly equivalent to the previous correction
procedure. A higher level of correction could be specified as follows,
in system/fvSchemes:

   wallDist
   {
       method meshWave;
       nCorrectors 3;
   }

Corrections replace basic cell-centre-face-centre distances with more
accurate cell-centre-face-polygon calculations in which all the points
and edges of the wall face are taken into account. The number of
correctors represents the number of layers of cells that these
corrections propagate into the mesh from the wall faces in question.

Note that correctors are expensive, and returns diminish as the number
of corrections increase, as the error in the basic calculation reduces
with distance from the wall faces. It is unlikely that more than 2 or
3 correctors would ever be warranted. Indeed, this control is
potentially more useful in reducing the number of corrections to 1 or 0
in order to reduce the computational expense in dynamic mesh cases where
distances are being constantly recomputed.
This commit is contained in:
Will Bainbridge
2022-04-02 21:02:17 +01:00
parent 8408dcb821
commit 9d702d58b5
30 changed files with 1778 additions and 1947 deletions

View File

@ -1,134 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\/ 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 "patchDistFuncs.H"
#include "polyMesh.H"
#include "wallPolyPatch.H"
#include "polyBoundaryMesh.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
template<>
Foam::patchDistFuncs::NoMap<Foam::labelPair>
Foam::patchDistFuncs::NoMap<Foam::labelPair>::null =
Foam::patchDistFuncs::NoMap<Foam::labelPair>();
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
Foam::scalar Foam::patchDistFuncs::smallestDist
(
const point& p,
const polyPatch& patch,
const labelUList& wallFaces,
label& minPatchFacei
)
{
const pointField& points = patch.points();
scalar minDist = great;
minPatchFacei = -1;
forAll(wallFaces, wallFacei)
{
const label patchFacei = wallFaces[wallFacei];
pointHit curHit = patch[patchFacei].nearestPoint(p, points);
if (curHit.distance() < minDist)
{
minDist = curHit.distance();
minPatchFacei = patchFacei;
}
}
return minDist;
}
void Foam::patchDistFuncs::getPointNeighbours
(
const primitivePatch& patch,
const label patchFacei,
DynamicList<label>& neighbours
)
{
neighbours.clear();
// Add myself
neighbours.append(patchFacei);
// Add all face neighbours
const labelList& faceNeighbours = patch.faceFaces()[patchFacei];
forAll(faceNeighbours, faceNeighbourI)
{
neighbours.append(faceNeighbours[faceNeighbourI]);
}
// Remember part of neighbours that contains edge-connected faces.
const label nEdgeNbs = neighbours.size();
// Add all point-only neighbours by linear searching in edge neighbours.
// Assumes that point-only neighbours are not using multiple points on
// face.
const face& f = patch.localFaces()[patchFacei];
forAll(f, fp)
{
const label pointi = f[fp];
const labelList& pointNbs = patch.pointFaces()[pointi];
forAll(pointNbs, nbI)
{
const label facei = pointNbs[nbI];
// Check for facei in edge-neighbours part of neighbours
if (findIndex(SubList<label>(neighbours, nEdgeNbs), facei) == -1)
{
neighbours.append(facei);
}
}
}
}
Foam::label Foam::patchDistFuncs::maxPatchSize
(
const polyMesh& mesh,
const labelHashSet& patchIDs
)
{
label maxSize = 0;
forAllConstIter(labelHashSet, patchIDs, iter)
{
maxSize = Foam::max(maxSize, mesh.boundaryMesh()[iter.key()].size());
}
return maxSize;
}
// ************************************************************************* //

View File

@ -1,155 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\/ 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::patchDistFuncs
Description
Collection of functions used in patch distance calculation.
SourceFiles
patchDistFuncs.C
patchDistFuncsTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef patchDistFuncs_H
#define patchDistFuncs_H
#include "scalarField.H"
#include "HashSet.H"
#include "Map.H"
#include "wordReList.H"
#include "scalarField.H"
#include "FieldField.H"
#include "point.H"
#include "labelPair.H"
#include "primitivePatch.H"
#include "className.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class polyMesh;
class polyPatch;
class polyBoundaryMesh;
namespace patchDistFuncs
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
struct NoMap
{
inline bool insert(const label, const Type&)
{
return false;
}
inline bool found(const label)
{
return false;
}
static NoMap<Type> null;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//- Calculate smallest true distance (and face index) from pt to faces
// wallFaces.
scalar smallestDist
(
const point& p,
const polyPatch& patch,
const labelUList& wallFaces,
label& patchFacei
);
// Get point neighbours of patchFacei (including patchFacei). Note: Uses a
// linear search to determine uniqueness. For polygonal faces this might be
// quite inefficient.
void getPointNeighbours
(
const primitivePatch&,
const label patchFacei,
DynamicList<label>& neighbours
);
//- Size of largest patch (out of supplied subset of patches)
label maxPatchSize(const polyMesh& mesh, const labelHashSet& patchIDs);
//- Correct all cells connected to boundary (via face). Sets values in
// wallDistCorrected. Sets nearest wallFace in nearestPatchAndFace.
template<template<class> class MapType=NoMap>
void correctBoundaryFaceCells
(
const polyMesh& mesh,
const labelHashSet& patchIDs,
scalarField& wallDistCorrected,
MapType<labelPair>& nearestPatchAndFace = NoMap<labelPair>::null
);
//- Correct all face-cells connected to boundary. Sets values in
// wallDistCorrected. Sets nearest wallFace in nearestPatchAndFace.
template<template<class> class PatchField, template<class> class MapType=NoMap>
void correctBoundaryFaceFaceCells
(
const polyMesh& mesh,
const labelHashSet& patchIDs,
FieldField<PatchField, scalar>& wallDistCorrected,
MapType<labelPair>& nearestPatchAndFace = NoMap<labelPair>::null
);
//- Correct all cells connected to wall (via point). Sets values in
// wallDistCorrected. Uses/sets nearest wallFace in nearestPatchAndFace.
template<template<class> class MapType=NoMap>
void correctBoundaryPointCells
(
const polyMesh& mesh,
const labelHashSet& patchIDs,
scalarField& wallDistCorrected,
MapType<labelPair>& nearestPatchAndFace = NoMap<labelPair>::null
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace patchDistFuncs
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "patchDistFuncsTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -1,196 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\/ 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 "patchDistFuncs.H"
#include "polyMesh.H"
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
template<template<class> class MapType>
void Foam::patchDistFuncs::correctBoundaryFaceCells
(
const polyMesh& mesh,
const labelHashSet& patchIDs,
scalarField& wallDistCorrected,
MapType<labelPair>& nearestPatchAndFace
)
{
// Size neighbours array for maximum possible (= size of largest patch)
DynamicList<label> neighbours(maxPatchSize(mesh, patchIDs));
// Correct all cells with face on wall
const vectorField& cellCentres = mesh.cellCentres();
forAllConstIter(labelHashSet, patchIDs, iter)
{
const label patchi = iter.key();
const polyPatch& patch = mesh.boundaryMesh()[patchi];
// Check cells with face on wall
forAll(patch, patchFacei)
{
const label celli = patch.faceCells()[patchFacei];
getPointNeighbours
(
patch,
patchFacei,
neighbours
);
label minPatchFacei = -1;
wallDistCorrected[celli] =
smallestDist
(
cellCentres[celli],
patch,
neighbours,
minPatchFacei
);
// Store wallCell and its nearest neighbour
nearestPatchAndFace.insert
(
celli,
labelPair(patchi, minPatchFacei)
);
}
}
}
template<template<class> class PatchField, template<class> class MapType>
void Foam::patchDistFuncs::correctBoundaryFaceFaceCells
(
const polyMesh& mesh,
const labelHashSet& patchIDs,
FieldField<PatchField, scalar>& wallDistCorrected,
MapType<labelPair>& nearestPatchAndFace
)
{
// Size neighbours array for maximum possible (= size of largest patch)
DynamicList<label> neighbours(maxPatchSize(mesh, patchIDs));
// Correct all faces on a wall
const vectorField& cellCentres = mesh.cellCentres();
forAllConstIter(labelHashSet, patchIDs, iter)
{
const label patchi = iter.key();
const polyPatch& patch = mesh.boundaryMesh()[patchi];
// Check cells with face on wall
forAll(patch, patchFacei)
{
const label celli = patch.faceCells()[patchFacei];
getPointNeighbours
(
patch,
patchFacei,
neighbours
);
label minPatchFacei = -1;
wallDistCorrected[patchi][patchFacei] =
smallestDist
(
cellCentres[celli],
patch,
neighbours,
minPatchFacei
);
// Store wallCell and its nearest neighbour
nearestPatchAndFace.insert
(
celli,
labelPair(patchi, minPatchFacei)
);
}
}
}
template<template<class> class MapType>
void Foam::patchDistFuncs::correctBoundaryPointCells
(
const polyMesh& mesh,
const labelHashSet& patchIDs,
scalarField& wallDistCorrected,
MapType<labelPair>& nearestPatchAndFace
)
{
// Correct all (non-visited) cells with point on wall
const vectorField& cellCentres = mesh.cellCentres();
forAllConstIter(labelHashSet, patchIDs, iter)
{
const label patchi = iter.key();
const polyPatch& patch = mesh.boundaryMesh()[patchi];
const labelList& meshPoints = patch.meshPoints();
const labelListList& pointFaces = patch.pointFaces();
forAll(meshPoints, meshPointi)
{
const labelList& neighbours =
mesh.pointCells(meshPoints[meshPointi]);
forAll(neighbours, neighbourI)
{
const label celli = neighbours[neighbourI];
if (!nearestPatchAndFace.found(celli))
{
const labelList& wallFaces = pointFaces[meshPointi];
label minPatchFacei = -1;
wallDistCorrected[celli] =
smallestDist
(
cellCentres[celli],
patch,
wallFaces,
minPatchFacei
);
// Store wallCell and its nearest neighbour
nearestPatchAndFace.insert
(
celli,
labelPair(patchi, minPatchFacei)
);
}
}
}
}
}
// ************************************************************************* //

View File

@ -24,18 +24,15 @@ License
\*---------------------------------------------------------------------------*/
#include "patchDistWave.H"
#include "patchDistFuncs.H"
#include "FaceCellWave.H"
#include "wallPoint.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class PatchPointType, class ... InitialPatchData>
void Foam::patchDistWave::setChangedFaces
Foam::labelList Foam::patchDistWave::getChangedFaces
(
const polyMesh& mesh,
const labelHashSet& patchIDs,
labelList& changedFaces,
List<PatchPointType>& changedFacesInfo,
const InitialPatchData& ... initialPatchData
const labelHashSet& patchIDs
)
{
label nChangedFaces = 0;
@ -44,9 +41,7 @@ void Foam::patchDistWave::setChangedFaces
nChangedFaces += mesh.boundaryMesh()[iter.key()].size();
}
changedFaces.resize(nChangedFaces);
changedFacesInfo.resize(nChangedFaces);
labelList changedFaces(nChangedFaces);
label changedFacei = 0;
forAllConstIter(labelHashSet, patchIDs, iter)
@ -61,117 +56,65 @@ void Foam::patchDistWave::setChangedFaces
changedFaces[changedFacei] = meshFacei;
changedFacesInfo[changedFacei] =
PatchPointType
(
patch.faceCentres()[patchFacei],
initialPatchData[patchi][patchFacei] ...,
scalar(0)
);
changedFacei++;
}
}
return changedFaces;
}
template
<
class PatchPointType,
class TrackingData,
class DataType,
class DataMethod
>
Foam::label Foam::patchDistWave::getCellValues
(
FaceCellWave<PatchPointType, TrackingData>& waveInfo,
Field<DataType>& cellValues,
DataMethod method,
const DataType& stabiliseValue
)
{
const List<PatchPointType>& cellInfo = waveInfo.allCellInfo();
label nInvalid = 0;
forAll(cellInfo, celli)
{
cellValues[celli] =
(cellInfo[celli].*method)(waveInfo.data())
+ stabiliseValue;
nInvalid += !cellInfo[celli].valid(waveInfo.data());
}
return nInvalid;
}
template<class PatchPointType, class TrackingData>
Foam::label Foam::patchDistWave::wave
(
const polyMesh& mesh,
const labelHashSet& patchIDs,
scalarField& cellDistance,
const bool correct,
TrackingData& td
const labelList& changedFaces,
scalarField& cellDistance
)
{
// Initialise changedFacesInfo to face centres on patches
List<PatchPointType> changedFacesInfo;
labelList changedFaces;
setChangedFaces
(
mesh,
patchIDs,
changedFaces,
changedFacesInfo
);
List<wallPoint> changedFacesInfo;
forAll(changedFaces, changedFacei)
{
const label facei = changedFaces[changedFacei];
changedFacesInfo[changedFacei] =
wallPoint(mesh.faceCentres()[facei], scalar(0));
}
// Do calculate patch distance by 'growing' from faces.
List<PatchPointType> faceInfo(mesh.nFaces()), cellInfo(mesh.nCells());
FaceCellWave<PatchPointType, TrackingData> wave
List<wallPoint> faceInfo(mesh.nFaces()), cellInfo(mesh.nCells());
FaceCellWave<wallPoint> wave
(
mesh,
changedFaces,
changedFacesInfo,
faceInfo,
cellInfo,
mesh.globalData().nTotalCells() + 1, // max iterations
td
mesh.globalData().nTotalCells() + 1 // max iterations
);
// Copy distance into return field
const label nUnset =
getCellValues
(
wave,
cellDistance,
&PatchPointType::template dist<TrackingData>
);
// Correct patch cells for true distance
if (correct)
// Copy distances into field
label nUnset = 0;
forAll(cellInfo, celli)
{
Map<labelPair> nearestFace(2*changedFacesInfo.size());
patchDistFuncs::correctBoundaryFaceCells
(
mesh,
patchIDs,
cellDistance,
nearestFace
);
patchDistFuncs::correctBoundaryPointCells
(
mesh,
patchIDs,
cellDistance,
nearestFace
);
nUnset += !cellInfo[celli].valid(wave.data());
cellDistance[celli] = cellInfo[celli].dist(wave.data());
}
return nUnset;
}
Foam::label Foam::patchDistWave::calculate
(
const polyMesh& mesh,
const labelHashSet& patchIDs,
scalarField& cellDistance
)
{
return wave(mesh, getChangedFaces(mesh, patchIDs), cellDistance);
}
// ************************************************************************* //

View File

@ -37,10 +37,6 @@ SourceFiles
#define patchDistWave_H
#include "polyMesh.H"
#include "FaceCellWave.H"
#include "Field.H"
#include "FieldField.H"
#include "UPtrList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -51,42 +47,27 @@ namespace patchDistWave
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//- Set initial set of changed faces
template<class PatchPointType, class ... InitialPatchData>
void setChangedFaces
//- Get initial set of changed faces
labelList getChangedFaces
(
const polyMesh& mesh,
const labelHashSet& patchIDs,
labelList& changedFaces,
List<PatchPointType>& faceDist,
const InitialPatchData& ... initialPatchData
const labelHashSet& patchIDs
);
//- Copy FaceCellWave values into the cell fields
template
<
class PatchPointType,
class TrackingData,
class DataType,
class DataMethod
>
label getCellValues
(
FaceCellWave<PatchPointType, TrackingData>& waveInfo,
Field<DataType>& cellValues,
DataMethod method,
const DataType& stabiliseValue = pTraits<DataType>::zero
);
//- Wave distance data from the patches to the cells
template<class PatchPointType, class TrackingData = int>
//- Wave distance data from faces
label wave
(
const polyMesh& mesh,
const labelList& changedFaces,
scalarField& cellDistance
);
//- Calculate distance data from patches
label calculate
(
const polyMesh& mesh,
const labelHashSet& patchIDs,
scalarField& cellDistance,
bool correct = true,
TrackingData& td = FaceCellWave<PatchPointType>::defaultTrackingData_
scalarField& cellDistance
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -96,12 +77,6 @@ label wave
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "patchDistWaveTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,253 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\/ 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::wallFace
Description
Holds information regarding nearest wall point. Used in wall distance
calculation.
SourceFiles
wallFaceI.H
\*---------------------------------------------------------------------------*/
#ifndef wallFace_H
#define wallFace_H
#include "pointField.H"
#include "face.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class polyPatch;
class polyMesh;
class transformer;
// Forward declaration of friend functions and operators
template<class Derived>
class WallFaceBase;
template<class Derived>
Ostream& operator<<(Ostream&, const WallFaceBase<Derived>&);
template<class Derived>
Istream& operator>>(Istream&, WallFaceBase<Derived>&);
/*---------------------------------------------------------------------------*\
Class WallFaceBase Declaration
\*---------------------------------------------------------------------------*/
template<class Derived>
class WallFaceBase
{
// Private Data
//- Face points
pointField points_;
//- Normal distance (squared) from cell center to face
scalar distSqr_;
protected:
// Protected Member Functions
//- ...
template<class TrackingData>
inline bool update
(
const point& pt,
const WallFaceBase<Derived>& w2,
const scalar tol,
TrackingData& td
);
public:
// Constructors
//- Construct null
inline WallFaceBase();
//- Construct from face, distance
inline WallFaceBase
(
const face& f,
const pointField& points,
const scalar distSqr
);
//- Construct from face, distance
inline WallFaceBase
(
const face& f,
const pointField& points,
const point& centre,
const scalar distSqr
);
// Member Functions
// Access
inline const pointField& points() const;
inline pointField& points();
inline scalar distSqr() const;
inline scalar& distSqr();
template<class TrackingData>
inline scalar dist(TrackingData& td) const;
// Needed by FaceCellWave
//- Check whether the WallFaceBase has been changed at all or still
// contains original (invalid) value.
template<class TrackingData>
inline bool valid(TrackingData& td) const;
//- Check for identical geometrical data. Used for checking
// consistency across cyclics.
template<class TrackingData>
inline bool sameGeometry
(
const polyMesh&,
const WallFaceBase<Derived>&,
const scalar,
TrackingData& td
) const;
//- Transform across an interface
template<class TrackingData>
inline void transform
(
const polyPatch& patch,
const label patchFacei,
const transformer& transform,
TrackingData& td
);
//- Influence of neighbouring face
template<class TrackingData>
inline bool updateCell
(
const polyMesh&,
const label thisCelli,
const label neighbourFacei,
const WallFaceBase<Derived>& neighbourInfo,
const scalar tol,
TrackingData& td
);
//- Influence of neighbouring cell
template<class TrackingData>
inline bool updateFace
(
const polyMesh&,
const label thisFacei,
const label neighbourCelli,
const WallFaceBase<Derived>& neighbourInfo,
const scalar tol,
TrackingData& td
);
//- Influence of different value on same face
template<class TrackingData>
inline bool updateFace
(
const polyMesh&,
const label thisFacei,
const WallFaceBase<Derived>& neighbourInfo,
const scalar tol,
TrackingData& td
);
//- Test equality
template<class TrackingData>
inline bool equal
(
const WallFaceBase<Derived>&,
TrackingData& td
) const;
// Member Operators
inline bool operator==(const WallFaceBase<Derived>&) const;
inline bool operator!=(const WallFaceBase<Derived>&) const;
// IOstream Operators
friend Ostream& operator<< <Derived>
(
Ostream&,
const WallFaceBase<Derived>&
);
friend Istream& operator>> <Derived>
(
Istream&,
WallFaceBase<Derived>&
);
};
/*---------------------------------------------------------------------------*\
Class wallFace Declaration
\*---------------------------------------------------------------------------*/
class wallFace
:
public WallFaceBase<wallFace>
{
public:
using WallFaceBase<wallFace>::WallFaceBase;
template<class Derived> using type = WallFaceBase<Derived>;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "wallFaceI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,320 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\/ 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 "wallFace.H"
#include "polyMesh.H"
#include "transformer.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
template<class Derived>
template<class TrackingData>
inline bool Foam::WallFaceBase<Derived>::update
(
const point& pt,
const WallFaceBase<Derived>& w2,
const scalar tol,
TrackingData& td
)
{
const scalar dist2 =
sqr
(
face(identity(w2.points().size()))
.nearestPoint(pt, w2.points())
.distance()
);
if (valid(td))
{
scalar diff = distSqr() - dist2;
if (diff < 0)
{
// already nearer to pt
return false;
}
if ((diff < small) || ((distSqr() > small) && (diff/distSqr() < tol)))
{
// don't propagate small changes
return false;
}
}
// Either *this is not yet valid or w2 is closer
distSqr() = dist2;
points() = w2.points();
return true;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Derived>
inline Foam::WallFaceBase<Derived>::WallFaceBase()
:
points_(0),
distSqr_(-great)
{}
template<class Derived>
inline Foam::WallFaceBase<Derived>::WallFaceBase
(
const face& f,
const pointField& points,
const scalar distSqr
)
:
points_(f.points(points)),
distSqr_(distSqr)
{}
template<class Derived>
inline Foam::WallFaceBase<Derived>::WallFaceBase
(
const face& f,
const pointField& points,
const point& centre,
const scalar distSqr
)
:
points_(f.points(points)),
distSqr_(distSqr)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Derived>
inline const Foam::pointField& Foam::WallFaceBase<Derived>::points() const
{
return points_;
}
template<class Derived>
inline Foam::pointField& Foam::WallFaceBase<Derived>::points()
{
return points_;
}
template<class Derived>
inline Foam::scalar Foam::WallFaceBase<Derived>::distSqr() const
{
return distSqr_;
}
template<class Derived>
inline Foam::scalar& Foam::WallFaceBase<Derived>::distSqr()
{
return distSqr_;
}
template<class Derived>
template<class TrackingData>
inline Foam::scalar Foam::WallFaceBase<Derived>::dist(TrackingData& td) const
{
return valid(td) ? sqrt(distSqr_) : great;
}
template<class Derived>
template<class TrackingData>
inline bool Foam::WallFaceBase<Derived>::valid(TrackingData& td) const
{
return distSqr_ > -small;
}
template<class Derived>
template<class TrackingData>
inline bool Foam::WallFaceBase<Derived>::sameGeometry
(
const polyMesh&,
const WallFaceBase<Derived>& w2,
const scalar tol,
TrackingData& td
) const
{
scalar diff = mag(distSqr() - w2.distSqr());
if (diff < small)
{
return true;
}
else
{
if ((distSqr() > small) && ((diff/distSqr()) < tol))
{
return true;
}
else
{
return false;
}
}
}
template<class Derived>
template<class TrackingData>
inline void Foam::WallFaceBase<Derived>::transform
(
const polyPatch& patch,
const label patchFacei,
const transformer& transform,
TrackingData& td
)
{
transform.transformPosition(points_, points_);
}
template<class Derived>
template<class TrackingData>
inline bool Foam::WallFaceBase<Derived>::updateCell
(
const polyMesh& mesh,
const label thisCelli,
const label neighbourFacei,
const WallFaceBase<Derived>& neighbourWallInfo,
const scalar tol,
TrackingData& td
)
{
return
static_cast<Derived&>(*this).update
(
mesh.cellCentres()[thisCelli],
neighbourWallInfo,
tol,
td
);
}
template<class Derived>
template<class TrackingData>
inline bool Foam::WallFaceBase<Derived>::updateFace
(
const polyMesh& mesh,
const label thisFacei,
const label neighbourCelli,
const WallFaceBase<Derived>& neighbourWallInfo,
const scalar tol,
TrackingData& td
)
{
return
static_cast<Derived&>(*this).update
(
mesh.faceCentres()[thisFacei],
neighbourWallInfo,
tol,
td
);
}
template<class Derived>
template<class TrackingData>
inline bool Foam::WallFaceBase<Derived>::updateFace
(
const polyMesh& mesh,
const label thisFacei,
const WallFaceBase<Derived>& neighbourWallInfo,
const scalar tol,
TrackingData& td
)
{
return
static_cast<Derived&>(*this).update
(
mesh.faceCentres()[thisFacei],
neighbourWallInfo,
tol,
td
);
}
template<class Derived>
template<class TrackingData>
inline bool Foam::WallFaceBase<Derived>::equal
(
const WallFaceBase<Derived>& rhs,
TrackingData& td
) const
{
return operator==(rhs);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class Derived>
inline bool Foam::WallFaceBase<Derived>::operator==
(
const Foam::WallFaceBase<Derived>& rhs
) const
{
return points() == rhs.points();
}
template<class Derived>
inline bool Foam::WallFaceBase<Derived>::operator!=
(
const Foam::WallFaceBase<Derived>& rhs
) const
{
return !(*this == rhs);
}
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
template<class Derived>
Foam::Ostream& Foam::operator<<(Ostream& os, const WallFaceBase<Derived>& w)
{
return os << w.points() << token::SPACE << w.distSqr();
}
template<class Derived>
Foam::Istream& Foam::operator>>(Istream& is, WallFaceBase<Derived>& w)
{
return is >> w.points() >> w.distSqr();
}
// ************************************************************************* //

View File

@ -1,40 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\/ 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 "wallPoint.H"
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
Foam::Ostream& Foam::operator<<(Foam::Ostream& os, const Foam::wallPoint& wDist)
{
return os << wDist.origin() << token::SPACE << wDist.distSqr();
}
Foam::Istream& Foam::operator>>(Foam::Istream& is, Foam::wallPoint& wDist)
{
return is >> wDist.origin() >> wDist.distSqr();
}
// ************************************************************************* //

View File

@ -30,17 +30,14 @@ Description
SourceFiles
wallPointI.H
wallPoint.C
\*---------------------------------------------------------------------------*/
#ifndef wallPoint_H
#define wallPoint_H
#include "point.H"
#include "label.H"
#include "scalar.H"
#include "tensor.H"
#include "pointField.H"
#include "face.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -52,20 +49,20 @@ class polyPatch;
class polyMesh;
class transformer;
// Forward declaration of friend functions and operators
class wallPoint;
Ostream& operator<<(Ostream&, const wallPoint&);
Istream& operator>>(Istream&, wallPoint&);
template<class Derived>
class WallPointBase;
template<class Derived>
Ostream& operator<<(Ostream&, const WallPointBase<Derived>&);
template<class Derived>
Istream& operator>>(Istream&, WallPointBase<Derived>&);
/*---------------------------------------------------------------------------*\
Class wallPoint Declaration
Class WallPointBase Declaration
\*---------------------------------------------------------------------------*/
class wallPoint
template<class Derived>
class WallPointBase
{
// Private Data
@ -87,7 +84,7 @@ protected:
inline bool update
(
const point&,
const wallPoint& w2,
const WallPointBase<Derived>& w2,
const scalar tol,
TrackingData& td
);
@ -98,10 +95,19 @@ public:
// Constructors
//- Construct null
inline wallPoint();
inline WallPointBase();
//- Construct from origin, distance
inline wallPoint(const point& origin, const scalar distSqr);
inline WallPointBase(const point& origin, const scalar distSqr);
//- Construct from face, distance
inline WallPointBase
(
const face& f,
const pointField& ps,
const point& centre,
const scalar distSqr
);
// Member Functions
@ -132,7 +138,7 @@ public:
inline bool sameGeometry
(
const polyMesh&,
const wallPoint&,
const WallPointBase<Derived>&,
const scalar,
TrackingData& td
) const;
@ -154,7 +160,7 @@ public:
const polyMesh&,
const label thisCelli,
const label neighbourFacei,
const wallPoint& neighbourInfo,
const WallPointBase<Derived>& neighbourInfo,
const scalar tol,
TrackingData& td
);
@ -166,7 +172,7 @@ public:
const polyMesh&,
const label thisFacei,
const label neighbourCelli,
const wallPoint& neighbourInfo,
const WallPointBase<Derived>& neighbourInfo,
const scalar tol,
TrackingData& td
);
@ -177,27 +183,55 @@ public:
(
const polyMesh&,
const label thisFacei,
const wallPoint& neighbourInfo,
const WallPointBase<Derived>& neighbourInfo,
const scalar tol,
TrackingData& td
);
//- Same (like operator==)
template<class TrackingData>
inline bool equal(const wallPoint&, TrackingData& td) const;
inline bool equal
(
const WallPointBase<Derived>&,
TrackingData& td
) const;
// Member Operators
// Needed for List IO
inline bool operator==(const wallPoint&) const;
inline bool operator!=(const wallPoint&) const;
inline bool operator==(const WallPointBase<Derived>&) const;
inline bool operator!=(const WallPointBase<Derived>&) const;
// IOstream Operators
friend Ostream& operator<<(Ostream&, const wallPoint&);
friend Istream& operator>>(Istream&, wallPoint&);
friend Ostream& operator<< <Derived>
(
Ostream&,
const WallPointBase<Derived>&
);
friend Istream& operator>> <Derived>
(
Istream&,
WallPointBase<Derived>&
);
};
/*---------------------------------------------------------------------------*\
Class wallPoint Declaration
\*---------------------------------------------------------------------------*/
class wallPoint
:
public WallPointBase<wallPoint>
{
public:
using WallPointBase<wallPoint>::WallPointBase;
template<class Derived> using type = WallPointBase<Derived>;
};

View File

@ -23,126 +23,138 @@ License
\*---------------------------------------------------------------------------*/
#include "wallPoint.H"
#include "polyMesh.H"
#include "transformer.H"
#include "SubField.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
// Update this with w2 if w2 nearer to pt.
template<class Derived>
template<class TrackingData>
inline bool Foam::wallPoint::update
inline bool Foam::WallPointBase<Derived>::update
(
const point& pt,
const wallPoint& w2,
const WallPointBase<Derived>& w2,
const scalar tol,
TrackingData& td
)
{
// Already done in calling algorithm
// if (w2.origin() == origin_)
//{
// // Shortcut. Same input so same distance.
// return false;
//}
const scalar dist2 = magSqr(pt - w2.origin());
scalar dist2 = magSqr(pt - w2.origin());
if (!valid(td))
if (valid(td))
{
// current not yet set so use any value
distSqr_ = dist2;
origin_ = w2.origin();
const scalar diff = distSqr() - dist2;
return true;
if (diff < 0)
{
// already nearer to pt
return false;
}
if ((diff < small) || ((distSqr() > small) && (diff/distSqr() < tol)))
{
// don't propagate small changes
return false;
}
}
scalar diff = distSqr_ - dist2;
// Either *this is not yet valid or w2 is closer
distSqr() = dist2;
origin() = w2.origin();
if (diff < 0)
{
// already nearer to pt
return false;
}
if ((diff < small) || ((distSqr_ > small) && (diff/distSqr_ < tol)))
{
// don't propagate small changes
return false;
}
else
{
// update with new values
distSqr_ = dist2;
origin_ = w2.origin();
return true;
}
return true;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
inline Foam::wallPoint::wallPoint()
template<class Derived>
inline Foam::WallPointBase<Derived>::WallPointBase()
:
origin_(point::max),
distSqr_(-great)
{}
inline Foam::wallPoint::wallPoint(const point& origin, const scalar distSqr)
template<class Derived>
inline Foam::WallPointBase<Derived>::WallPointBase
(
const point& origin,
const scalar distSqr
)
:
origin_(origin),
distSqr_(distSqr)
{}
template<class Derived>
inline Foam::WallPointBase<Derived>::WallPointBase
(
const face& f,
const pointField& points,
const point& centre,
const scalar distSqr
)
:
origin_(centre),
distSqr_(distSqr)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline const Foam::point& Foam::wallPoint::origin() const
template<class Derived>
inline const Foam::point& Foam::WallPointBase<Derived>::origin() const
{
return origin_;
}
inline Foam::point& Foam::wallPoint::origin()
template<class Derived>
inline Foam::point& Foam::WallPointBase<Derived>::origin()
{
return origin_;
}
inline Foam::scalar Foam::wallPoint::distSqr() const
template<class Derived>
inline Foam::scalar Foam::WallPointBase<Derived>::distSqr() const
{
return distSqr_;
}
inline Foam::scalar& Foam::wallPoint::distSqr()
template<class Derived>
inline Foam::scalar& Foam::WallPointBase<Derived>::distSqr()
{
return distSqr_;
}
template<class Derived>
template<class TrackingData>
inline Foam::scalar Foam::wallPoint::dist(TrackingData& td) const
inline Foam::scalar Foam::WallPointBase<Derived>::dist(TrackingData& td) const
{
return valid(td) ? sqrt(distSqr_) : great;
}
template<class Derived>
template<class TrackingData>
inline bool Foam::wallPoint::valid(TrackingData& td) const
inline bool Foam::WallPointBase<Derived>::valid(TrackingData& td) const
{
return distSqr_ > -small;
}
// Checks for cyclic faces
template<class Derived>
template<class TrackingData>
inline bool Foam::wallPoint::sameGeometry
inline bool Foam::WallPointBase<Derived>::sameGeometry
(
const polyMesh&,
const wallPoint& w2,
const WallPointBase<Derived>& w2,
const scalar tol,
TrackingData& td
) const
@ -167,8 +179,9 @@ inline bool Foam::wallPoint::sameGeometry
}
template<class Derived>
template<class TrackingData>
inline void Foam::wallPoint::transform
inline void Foam::WallPointBase<Derived>::transform
(
const polyPatch& patch,
const label patchFacei,
@ -181,43 +194,43 @@ inline void Foam::wallPoint::transform
}
// Update this with w2 if w2 nearer to pt.
template<class Derived>
template<class TrackingData>
inline bool Foam::wallPoint::updateCell
inline bool Foam::WallPointBase<Derived>::updateCell
(
const polyMesh& mesh,
const label thisCelli,
const label neighbourFacei,
const wallPoint& neighbourWallInfo,
const WallPointBase<Derived>& neighbourWallInfo,
const scalar tol,
TrackingData& td
)
{
return
update
static_cast<Derived&>(*this).update
(
mesh.cellCentres()[thisCelli],
neighbourWallInfo,
tol,
td
);
}
}
// Update this with w2 if w2 nearer to pt.
template<class Derived>
template<class TrackingData>
inline bool Foam::wallPoint::updateFace
inline bool Foam::WallPointBase<Derived>::updateFace
(
const polyMesh& mesh,
const label thisFacei,
const label neighbourCelli,
const wallPoint& neighbourWallInfo,
const WallPointBase<Derived>& neighbourWallInfo,
const scalar tol,
TrackingData& td
)
{
return
update
static_cast<Derived&>(*this).update
(
mesh.faceCentres()[thisFacei],
neighbourWallInfo,
@ -226,19 +239,20 @@ inline bool Foam::wallPoint::updateFace
);
}
// Update this with w2 if w2 nearer to pt.
template<class Derived>
template<class TrackingData>
inline bool Foam::wallPoint::updateFace
inline bool Foam::WallPointBase<Derived>::updateFace
(
const polyMesh& mesh,
const label thisFacei,
const wallPoint& neighbourWallInfo,
const WallPointBase<Derived>& neighbourWallInfo,
const scalar tol,
TrackingData& td
)
{
return
update
static_cast<Derived&>(*this).update
(
mesh.faceCentres()[thisFacei],
neighbourWallInfo,
@ -248,10 +262,11 @@ inline bool Foam::wallPoint::updateFace
}
template<class Derived>
template<class TrackingData>
inline bool Foam::wallPoint::equal
inline bool Foam::WallPointBase<Derived>::equal
(
const wallPoint& rhs,
const WallPointBase<Derived>& rhs,
TrackingData& td
) const
{
@ -261,16 +276,40 @@ inline bool Foam::wallPoint::equal
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
inline bool Foam::wallPoint::operator==(const Foam::wallPoint& rhs) const
template<class Derived>
inline bool Foam::WallPointBase<Derived>::operator==
(
const Foam::WallPointBase<Derived>& rhs
) const
{
return origin() == rhs.origin();
}
inline bool Foam::wallPoint::operator!=(const Foam::wallPoint& rhs) const
template<class Derived>
inline bool Foam::WallPointBase<Derived>::operator!=
(
const Foam::WallPointBase<Derived>& rhs
) const
{
return !(*this == rhs);
}
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
template<class Derived>
Foam::Ostream& Foam::operator<<(Ostream& os, const WallPointBase<Derived>& w)
{
return os << w.origin() << token::SPACE << w.distSqr();
}
template<class Derived>
Foam::Istream& Foam::operator>>(Istream& is, WallPointBase<Derived>& w)
{
return is >> w.origin() >> w.distSqr();
}
// ************************************************************************* //