Commit c6e18e75 authored by Andrew Heather's avatar Andrew Heather Committed by Andrew Heather
Browse files

ENH: AMI code refactoring

parent 2a955ad9
......@@ -226,10 +226,9 @@ void Foam::cyclicACMIFvPatchField<Type>::updateInterfaceMatrix
{
const cyclicACMIPolyPatch& cpp = cyclicACMIPatch_.cyclicACMIPatch();
// note: only applying coupled contribution
// Note: only applying coupled contribution
const labelUList& nbrFaceCellsCoupled =
cpp.neighbPatch().faceCells();
const labelUList& nbrFaceCellsCoupled = cpp.neighbPatch().faceCells();
solveScalarField pnf(psiInternal, nbrFaceCellsCoupled);
......@@ -254,7 +253,7 @@ void Foam::cyclicACMIFvPatchField<Type>::updateInterfaceMatrix
{
const cyclicACMIPolyPatch& cpp = cyclicACMIPatch_.cyclicACMIPatch();
// note: only applying coupled contribution
// Note: only applying coupled contribution
const labelUList& nbrFaceCellsCoupled = cpp.neighbPatch().faceCells();
......@@ -277,7 +276,7 @@ void Foam::cyclicACMIFvPatchField<Type>::manipulateMatrix
{
const scalarField& mask = cyclicACMIPatch_.cyclicACMIPatch().mask();
// nothing to be done by the AMI, but re-direct to non-overlap patch
// Nothing to be done by the AMI, but re-direct to non-overlap patch
// with non-overlap patch weights
const fvPatchField<Type>& npf = nonOverlapPatchField();
......
......@@ -46,6 +46,7 @@ namespace Foam
void Foam::cyclicACMIFvPatch::resetPatchAreas(const fvPatch& fvp) const
{
const_cast<vectorField&>(fvp.Sf()) = fvp.patch().faceAreas();
const_cast<vectorField&>(fvp.Cf()) = fvp.patch().faceCentres();
const_cast<scalarField&>(fvp.magSf()) = mag(fvp.patch().faceAreas());
DebugPout
......@@ -117,7 +118,7 @@ Foam::tmp<Foam::vectorField> Foam::cyclicACMIFvPatch::delta() const
vectorField nbrPatchD(interpolate(nbrPatch.coupledFvPatch::delta()));
tmp<vectorField> tpdv(new vectorField(patchD.size()));
auto tpdv = tmp<vectorField>::New(patchD.size());
vectorField& pdv = tpdv.ref();
// do the transformation if necessary
......@@ -204,6 +205,9 @@ void Foam::cyclicACMIFvPatch::movePoints()
scalarField& phiNonOverlapp =
meshPhiBf[nonOverlapPatch.patch().index()];
const auto& localFaces = cyclicACMIPolyPatch_.localFaces();
const auto& localPoints = cyclicACMIPolyPatch_.localPoints();
forAll(phip, facei)
{
if (newSrcAddr[facei].empty())
......@@ -214,12 +218,12 @@ void Foam::cyclicACMIFvPatch::movePoints()
else
{
// Scale the mesh flux according to the area fraction
const face& fAMI = cyclicACMIPolyPatch_.localFaces()[facei];
const face& fAMI = localFaces[facei];
// Note: using raw point locations to calculate the geometric
// area - faces areas are currently scaled (decoupled from
// mesh points)
const scalar geomArea = fAMI.mag(cyclicACMIPolyPatch_.localPoints());
const scalar geomArea = fAMI.mag(localPoints);
phip[facei] *= magSf()[facei]/geomArea;
}
}
......@@ -234,6 +238,9 @@ void Foam::cyclicACMIFvPatch::movePoints()
scalarField& nbrPhiNonOverlapp =
meshPhiBf[nbrNonOverlapPatch.patch().index()];
const auto& nbrLocalFaces = nbrACMI.patch().localFaces();
const auto& nbrLocalPoints = nbrACMI.patch().localPoints();
forAll(nbrPhip, facei)
{
if (newTgtAddr[facei].empty())
......@@ -242,12 +249,12 @@ void Foam::cyclicACMIFvPatch::movePoints()
}
else
{
const face& fAMI = nbrACMI.patch().localFaces()[facei];
const face& fAMI = nbrLocalFaces[facei];
// Note: using raw point locations to calculate the geometric
// area - faces areas are currently scaled (decoupled from
// mesh points)
const scalar geomArea = fAMI.mag(nbrACMI.patch().localPoints());
const scalar geomArea = fAMI.mag(nbrLocalPoints);
nbrPhip[facei] *= nbrACMI.magSf()[facei]/geomArea;
}
}
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -123,7 +124,7 @@ Foam::tmp<Foam::vectorField> Foam::cyclicAMIFvPatch::delta() const
const vectorField& nbrPatchD = tnbrPatchD();
tmp<vectorField> tpdv(new vectorField(patchD.size()));
auto tpdv = tmp<vectorField>::New(patchD.size());
vectorField& pdv = tpdv.ref();
// do the transformation if necessary
......
......@@ -159,8 +159,8 @@ public:
}
//- Return true if this patch is coupled. This is equivalent
// to the coupledPolyPatch::coupled() if parallel running or
// both sides present, false otherwise
//- to the coupledPolyPatch::coupled() if parallel running or
//- both sides present, false otherwise
virtual bool coupled() const;
//- Return delta (P to N) vectors across coupled patch
......@@ -190,7 +190,7 @@ public:
// Interface transfer functions
//- Return the values of the given internal data adjacent to
// the interface as a field
//- the interface as a field
virtual tmp<labelField> interfaceInternalField
(
const labelUList& internalData
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2016-2018 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -62,75 +62,52 @@ SourceFiles
#include "ops.H"
#include "Enum.H"
#include "pointList.H"
#include "indexedOctree.H"
#include "treeDataPrimitivePatch.H"
#include "runTimeSelectionTables.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class AMIInterpolationName Declaration
\*---------------------------------------------------------------------------*/
TemplateName(AMIInterpolation);
/*---------------------------------------------------------------------------*\
Class AMIInterpolation Declaration
\*---------------------------------------------------------------------------*/
template<class SourcePatch, class TargetPatch>
class AMIInterpolation
:
public AMIInterpolationName
{
public:
// Public data types
//- Enumeration specifying interpolation method
enum interpolationMethod
{
imNearestFace,
imFaceAreaWeight,
imPartialFaceAreaWeight
};
static const Enum<interpolationMethod> interpolationMethodNames_;
static bool cacheIntersections_;
//- Calculate the patch face magnitudes for the given tri-mode
template<class Patch>
static tmp<scalarField> patchMagSf
(
const Patch& patch,
const faceAreaIntersect::triangulationMode triMode
);
protected:
private:
//- Local typedef to octree tree-type
typedef treeDataPrimitivePatch<primitivePatch> treeType;
// Private data
// Protected data
//- Interpolation method
const word methodName_;
//- Flag to indicate that the two patches must be matched/an overlap
//- exists between them
bool requireMatch_;
//- Flag to indicate that the two patches are co-directional and
//- that the orientation of the target patch should be reversed
const bool reverseTarget_;
//- Flag to indicate that the two patches must be matched/an overlap
//- exists between them
const bool requireMatch_;
//- Threshold weight below which interpolation is deactivated
scalar lowWeightCorrection_;
//- Index of processor that holds all of both sides. -1 in all other
//- cases
label singlePatchProc_;
//- Threshold weight below which interpolation is deactivated
scalar lowWeightCorrection_;
// Source patch
......@@ -149,6 +126,16 @@ private:
//- Centroid of target faces per source face
pointListList srcCentroids_;
//- Source patch points if input points are manipulated, e.g.
//- projected
pointField srcPatchPts_;
//- Source patch using manipulated input points
tmpNrc<primitivePatch> tsrcPatch0_;
//- Source map pointer - parallel running only
autoPtr<mapDistribute> srcMapPtr_;
// Target patch
......@@ -167,21 +154,21 @@ private:
//- Centroid of source faces per target face
pointListList tgtCentroids_;
//- Target patch points if input points are manipulated, e.g.
//- projected
pointField tgtPatchPts_;
//- Face triangulation mode
const faceAreaIntersect::triangulationMode triMode_;
//- Target patch using manipulated input points
tmpNrc<primitivePatch> ttgtPatch0_;
//- Source map pointer - parallel running only
autoPtr<mapDistribute> srcMapPtr_;
//- Target map pointer - parallel running only
autoPtr<mapDistribute> tgtMapPtr_;
//- Target map pointer - parallel running only
autoPtr<mapDistribute> tgtMapPtr_;
//- Up-to-date flag
bool upToDate_;
// Private Member Functions
//- No copy construct
AMIInterpolation(const AMIInterpolation&) = delete;
// Protected Member Functions
//- No copy assignment
void operator=(const AMIInterpolation&) = delete;
......@@ -189,6 +176,19 @@ private:
// Initialisation
//- Reset the octree for the patch face search
autoPtr<indexedOctree<treeType>> createTree
(
const primitivePatch& patch
) const;
//- Calculate if patches are on multiple processors
label calcDistribution
(
const primitivePatch& srcPatch,
const primitivePatch& tgtPatch
) const;
//- Project points to surface
void projectPointsToSurface
(
......@@ -197,6 +197,15 @@ private:
) const;
// Access
//- Return the orginal src patch with optionally updated points
inline const primitivePatch& srcPatch0() const;
//- Return the orginal tgt patch with optionally updated points
inline const primitivePatch& tgtPatch0() const;
// Evaluation
//- Normalise the (area) weights - suppresses numerical error in
......@@ -236,96 +245,127 @@ private:
autoPtr<mapDistribute>& tgtMap
);
void constructFromSurface
(
const SourcePatch& srcPatch,
const TargetPatch& tgtPatch,
const autoPtr<searchableSurface>& surfPtr
);
public:
// Constructors
//- Runtime type information
TypeName("AMIInterpolation");
//- Construct from components
AMIInterpolation
// Selection tables
//- Selection table for dictionary construction
declareRunTimeSelectionTable
(
const SourcePatch& srcPatch,
const TargetPatch& tgtPatch,
const faceAreaIntersect::triangulationMode& triMode,
const bool requireMatch = true,
const interpolationMethod& method = imFaceAreaWeight,
const scalar lowWeightCorrection = -1,
autoPtr,
AMIInterpolation,
dict,
(
const dictionary& dict,
const bool reverseTarget
),
(
dict,
reverseTarget
)
);
//- Selection table for component-wise construction
declareRunTimeSelectionTable
(
autoPtr,
AMIInterpolation,
component,
(
const bool requireMatch,
const bool reverseTarget,
const scalar lowWeightCorrection
),
(
requireMatch,
reverseTarget,
lowWeightCorrection
)
);
//- Selector for dictionary
static autoPtr<AMIInterpolation> New
(
const word& modelName,
const dictionary& dict,
const bool reverseTarget = false
);
//- Construct from components
AMIInterpolation
//- Selector for components
static autoPtr<AMIInterpolation> New
(
const SourcePatch& srcPatch,
const TargetPatch& tgtPatch,
const faceAreaIntersect::triangulationMode& triMode,
const word& modelName,
const bool requireMatch = true,
const word& methodName =
interpolationMethodNames_[imFaceAreaWeight],
const scalar lowWeightCorrection = -1,
const bool reverseTarget = false
const bool reverseTarget = false,
const scalar lowWeightCorrection = -1
);
//- Construct from components, with projection surface
// Constructors
//- Construct from dictionary
AMIInterpolation
(
const SourcePatch& srcPatch,
const TargetPatch& tgtPatch,
const autoPtr<searchableSurface>& surf,
const faceAreaIntersect::triangulationMode& triMode,
const bool requireMatch = true,
const interpolationMethod& method = imFaceAreaWeight,
const scalar lowWeightCorrection = -1,
const dictionary& dict,
const bool reverseTarget = false
);
//- Construct from components, with projection surface
//- Construct from components
AMIInterpolation
(
const SourcePatch& srcPatch,
const TargetPatch& tgtPatch,
const autoPtr<searchableSurface>& surf,
const faceAreaIntersect::triangulationMode& triMode,
const bool requireMatch = true,
const word& methodName =
interpolationMethodNames_[imFaceAreaWeight],
const scalar lowWeightCorrection = -1,
const bool reverseTarget = false
const bool reverseTarget = false,
const scalar lowWeightCorrection = -1
);
//- Construct from agglomeration of AMIInterpolation. Agglomeration
// passed in as new coarse size and addressing from fine from coarse
//- passed in as new coarse size and addressing from fine from coarse
AMIInterpolation
(
const AMIInterpolation<SourcePatch, TargetPatch>& fineAMI,
const AMIInterpolation& fineAMI,
const labelList& sourceRestrictAddressing,
const labelList& neighbourRestrictAddressing
);
//- Construct as copy
AMIInterpolation(const AMIInterpolation& ami);
//- Destructor
~AMIInterpolation() = default;
//- Construct and return a clone
virtual autoPtr<AMIInterpolation> clone() const
{
return autoPtr<AMIInterpolation>::New(*this);
}
// Typedef to SourcePatch type this AMIInterpolation is instantiated on
typedef SourcePatch sourcePatchType;
// Typedef to TargetPatch type this AMIInterpolation is instantiated on
typedef TargetPatch targetPatchType;
//- Destructor
virtual ~AMIInterpolation() = default;
// Member Functions
// Access
//- Set to -1, or the processor holding all faces (both sides) of
//- the AMI
inline label singlePatchProc() const;
//- Access to the up-to-date flag
inline bool upToDate() const;
//- Access to the up-to-date flag
inline bool& upToDate();
//- Access to the distributed flag
inline bool distributed() const;
//- Access to the requireMatch flag
inline bool requireMatch() const;
//- Access to the requireMatch flag
inline bool setRequireMatch(const bool flag);
//- Access to the reverseTarget flag
inline bool reverseTarget() const;
//- Threshold weight below which interpolation is deactivated
inline scalar lowWeightCorrection() const;
......@@ -333,6 +373,10 @@ public:
//- Return true if employing a 'lowWeightCorrection'
inline bool applyLowWeightCorrection() const;
//- Set to -1, or the processor holding all faces (both sides) of
//- the AMI
inline label singlePatchProc() const;
// Source patch
......@@ -410,14 +454,16 @@ public:
// Manipulation
//- Update addressing and weights
void update
//- Update addressing, weights and (optional) centroids
virtual bool calculate
(
const SourcePatch& srcPatch,
const TargetPatch& tgtPatch
const primitivePatch& srcPatch,
const primitivePatch& tgtPatch,
const autoPtr<searchableSurface>& surfPtr = nullptr
);
void update
//- Set the maps, addresses and weights from an external source
void reset
(
autoPtr<mapDistribute>&& srcToTgtMap,
autoPtr<mapDistribute>&& tgtToSrcMap,
......@@ -427,17 +473,11 @@ public:
scalarListList&& tgtWeights
);
void setAreas(const scalarList& srcMagSf, const scalarList& tgtMagSf)
{
srcMagSf_ = srcMagSf;
tgtMagSf_ = tgtMagSf;
}
//- Append additional addressing and weights
void append
(
const SourcePatch& srcPatch,
const TargetPatch& tgtPatch
const primitivePatch& srcPatch,
const primitivePatch& tgtPatch
);
//- Normalise the weights
......@@ -545,8 +585,8 @@ public:
//- Return source patch face index of point on target patch face
label srcPointFace
(
const SourcePatch& srcPatch,
const TargetPatch& tgtPatch,
const primitivePatch& srcPatch,
const primitivePatch& tgtPatch,
const vector& n,
const label tgtFacei,
point& tgtPoint
......@@ -556,8 +596,8 @@ public:
//- Return target patch face index of point on source patch face
label tgtPointFace
(
const SourcePatch& srcPatch,
const TargetPatch& tgtPatch,
const primitivePatch& srcPatch,
const primitivePatch& tgtPatch,
const vector& n,
const label srcFacei,
point& srcPoint
......@@ -574,10 +614,16 @@ public:
//- Write face connectivity as OBJ file
void writeFaceConnectivity
(
const SourcePatch& srcPatch,
const TargetPatch& tgtPatch,
const primitivePatch& srcPatch,
const primitivePatch& tgtPatch,
const labelListList& srcAddress
) const;
// I-O
//- Write
virtual void write(Ostream& os) const;
};
......@@ -592,7 +638,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "AMIInterpolation.C"
#include "AMIInterpolationTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation