Skip to content
Snippets Groups Projects
Commit d5b72002 authored by Kutalmış Berçin's avatar Kutalmış Berçin Committed by Mark OLESEN
Browse files

ENH: edgeInterpolation: make skewness-correction optimisation compile-time optional

parent 952d4251
Branches
Tags
1 merge request!585Misc. changes in finite-area methods
...@@ -174,6 +174,25 @@ bool Foam::edgeInterpolation::movePoints() const ...@@ -174,6 +174,25 @@ bool Foam::edgeInterpolation::movePoints() const
} }
const Foam::vector& Foam::edgeInterpolation::skewCorr(const label edgeI) const
{
#ifdef FA_SKEW_CORRECTION
return
(
skewCorrectionVectors_
? (*skewCorrectionVectors_)[edgeI]
: pTraits<vector>::zero
);
#else
return (*skewCorrectionVectors_)[edgeI];
#endif
}
void Foam::edgeInterpolation::makeLPN() const void Foam::edgeInterpolation::makeLPN() const
{ {
DebugInFunction DebugInFunction
...@@ -205,20 +224,18 @@ void Foam::edgeInterpolation::makeLPN() const ...@@ -205,20 +224,18 @@ void Foam::edgeInterpolation::makeLPN() const
scalarField& lPNIn = lPN.primitiveFieldRef(); scalarField& lPNIn = lPN.primitiveFieldRef();
// Calculate skewness correction vectors if necessary
(void) skew();
forAll(owner, edgeI) forAll(owner, edgeI)
{ {
vector curSkewCorrVec(Zero); const vector& skewCorrEdge = skewCorr(edgeI);
if (skew())
{
curSkewCorrVec = skewCorrectionVectors()[edgeI];
}
scalar lPE = scalar lPE =
mag mag
( (
edgeCentres[edgeI] edgeCentres[edgeI]
- curSkewCorrVec - skewCorrEdge
- faceCentres[owner[edgeI]] - faceCentres[owner[edgeI]]
); );
...@@ -227,7 +244,7 @@ void Foam::edgeInterpolation::makeLPN() const ...@@ -227,7 +244,7 @@ void Foam::edgeInterpolation::makeLPN() const
( (
faceCentres[neighbour[edgeI]] faceCentres[neighbour[edgeI]]
- edgeCentres[edgeI] - edgeCentres[edgeI]
+ curSkewCorrVec + skewCorrEdge
); );
lPNIn[edgeI] = (lPE + lEN); lPNIn[edgeI] = (lPE + lEN);
...@@ -283,20 +300,18 @@ void Foam::edgeInterpolation::makeWeights() const ...@@ -283,20 +300,18 @@ void Foam::edgeInterpolation::makeWeights() const
scalarField& weightingFactorsIn = weightingFactors.primitiveFieldRef(); scalarField& weightingFactorsIn = weightingFactors.primitiveFieldRef();
// Calculate skewness correction vectors if necessary
(void) skew();
forAll(owner, edgeI) forAll(owner, edgeI)
{ {
vector curSkewCorrVec(Zero); const vector& skewCorrEdge = skewCorr(edgeI);
if (skew())
{
curSkewCorrVec = skewCorrectionVectors()[edgeI];
}
scalar lPE = scalar lPE =
mag mag
( (
edgeCentres[edgeI] edgeCentres[edgeI]
- curSkewCorrVec - skewCorrEdge
- faceCentres[owner[edgeI]] - faceCentres[owner[edgeI]]
); );
...@@ -305,7 +320,7 @@ void Foam::edgeInterpolation::makeWeights() const ...@@ -305,7 +320,7 @@ void Foam::edgeInterpolation::makeWeights() const
( (
faceCentres[neighbour[edgeI]] faceCentres[neighbour[edgeI]]
- edgeCentres[edgeI] - edgeCentres[edgeI]
+ curSkewCorrVec + skewCorrEdge
); );
weightingFactorsIn[edgeI] = weightingFactorsIn[edgeI] =
...@@ -370,6 +385,8 @@ void Foam::edgeInterpolation::makeDeltaCoeffs() const ...@@ -370,6 +385,8 @@ void Foam::edgeInterpolation::makeDeltaCoeffs() const
const edgeList& edges = mesh().edges(); const edgeList& edges = mesh().edges();
const pointField& points = mesh().points(); const pointField& points = mesh().points();
// Calculate skewness correction vectors if necessary
(void) skew();
forAll(owner, edgeI) forAll(owner, edgeI)
{ {
...@@ -386,19 +403,13 @@ void Foam::edgeInterpolation::makeDeltaCoeffs() const ...@@ -386,19 +403,13 @@ void Foam::edgeInterpolation::makeDeltaCoeffs() const
unitDelta.normalise(); unitDelta.normalise();
// Calc PN arc length const vector& skewCorrEdge = skewCorr(edgeI);
vector curSkewCorrVec(Zero);
if (skew())
{
curSkewCorrVec = skewCorrectionVectors()[edgeI];
}
scalar lPE = scalar lPE =
mag mag
( (
edgeCentres[edgeI] edgeCentres[edgeI]
- curSkewCorrVec - skewCorrEdge
- faceCentres[owner[edgeI]] - faceCentres[owner[edgeI]]
); );
...@@ -407,7 +418,7 @@ void Foam::edgeInterpolation::makeDeltaCoeffs() const ...@@ -407,7 +418,7 @@ void Foam::edgeInterpolation::makeDeltaCoeffs() const
( (
faceCentres[neighbour[edgeI]] faceCentres[neighbour[edgeI]]
- edgeCentres[edgeI] - edgeCentres[edgeI]
+ curSkewCorrVec + skewCorrEdge
); );
scalar lPN = lPE + lEN; scalar lPN = lPE + lEN;
...@@ -643,46 +654,54 @@ void Foam::edgeInterpolation::makeSkewCorrectionVectors() const ...@@ -643,46 +654,54 @@ void Foam::edgeInterpolation::makeSkewCorrectionVectors() const
} }
} }
#ifdef FA_SKEW_CORRECTION
scalar skewCoeff = 0.0; constexpr scalar maxSkewRatio = 0.1;
scalar skewCoeff = 0;
// Calculating PN arc length
scalarField lPN(owner.size());
forAll(owner, edgeI) forAll(own, edgeI)
{ {
lPN[edgeI] = const scalar magSkew = mag(skewCorrVecs[edgeI]);
const scalar lPN =
mag mag
( (
Ce[edgeI] Ce[edgeI]
- SkewCorrVecs[edgeI] - skewCorrVecs[edgeI]
- C[owner[edgeI]] - C[owner[edgeI]]
) )
+ mag + mag
( (
C[neighbour[edgeI]] C[neighbour[edgeI]]
- Ce[edgeI] - Ce[edgeI]
+ SkewCorrVecs[edgeI] + skewCorrVecs[edgeI]
); );
}
if (lPN.size() > 0) const scalar ratio = magSkew/lPN;
{
skewCoeff = max(mag(SkewCorrVecs.internalField())/mag(lPN)); if (skewCoeff < ratio)
{
skewCoeff = ratio;
if (skewCoeff > maxSkewRatio)
{
break;
}
}
} }
DebugInFunction DebugInFunction
<< "skew coefficient = " << skewCoeff << endl; << "skew coefficient = " << skewCoeff << endl;
if (skewCoeff < 0.1) if (skewCoeff < maxSkewRatio)
{ {
skew_ = false;
deleteDemandDrivenData(skewCorrectionVectors_); deleteDemandDrivenData(skewCorrectionVectors_);
} }
else
{ #endif
skew_ = true;
} skew_ = bool(skewCorrectionVectors_);
DebugInFunction DebugInFunction
<< "Finished constructing skew correction vectors" << "Finished constructing skew correction vectors"
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2016-2017 Wikki Ltd Copyright (C) 2016-2017 Wikki Ltd
Copyright (C) 2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
...@@ -93,6 +94,9 @@ class edgeInterpolation ...@@ -93,6 +94,9 @@ class edgeInterpolation
// Private Member Functions // Private Member Functions
//- Return skewness correction per edge
const vector& skewCorr(const label edgeI) const;
//- Construct geodesic distance between P and N //- Construct geodesic distance between P and N
void makeLPN() const; void makeLPN() const;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment