ENH: AMIInterpolation - added base for caching of triangulation

This commit is contained in:
Andrew Heather
2017-08-17 11:12:21 +01:00
parent 80ffdfb149
commit 2be17edc1d
7 changed files with 78 additions and 32 deletions

View File

@ -57,7 +57,7 @@ void Foam::faceAreaWeightAMI<SourcePatch, TargetPatch>::calcAddressing
boolList mapFlag(nFacesRemaining, true); boolList mapFlag(nFacesRemaining, true);
// reset starting seed // reset starting seed
label startSeedI = 0; label startSeedi = 0;
DynamicList<label> nonOverlapFaces; DynamicList<label> nonOverlapFaces;
do do
@ -91,7 +91,7 @@ void Foam::faceAreaWeightAMI<SourcePatch, TargetPatch>::calcAddressing
{ {
setNextFaces setNextFaces
( (
startSeedI, startSeedi,
srcFacei, srcFacei,
tgtFacei, tgtFacei,
mapFlag, mapFlag,
@ -179,7 +179,7 @@ bool Foam::faceAreaWeightAMI<SourcePatch, TargetPatch>::processSourceFace
template<class SourcePatch, class TargetPatch> template<class SourcePatch, class TargetPatch>
void Foam::faceAreaWeightAMI<SourcePatch, TargetPatch>::setNextFaces void Foam::faceAreaWeightAMI<SourcePatch, TargetPatch>::setNextFaces
( (
label& startSeedI, label& startSeedi,
label& srcFacei, label& srcFacei,
label& tgtFacei, label& tgtFacei,
const boolList& mapFlag, const boolList& mapFlag,
@ -195,15 +195,12 @@ void Foam::faceAreaWeightAMI<SourcePatch, TargetPatch>::setNextFaces
// set possible seeds for later use // set possible seeds for later use
bool valuesSet = false; bool valuesSet = false;
forAll(srcNbrFaces, i) for (label faceS: srcNbrFaces)
{ {
label faceS = srcNbrFaces[i];
if (mapFlag[faceS] && seedFaces[faceS] == -1) if (mapFlag[faceS] && seedFaces[faceS] == -1)
{ {
forAll(visitedFaces, j) for (label faceT : visitedFaces)
{ {
label faceT = visitedFaces[j];
scalar area = interArea(faceS, faceT); scalar area = interArea(faceS, faceT);
scalar areaTotal = this->srcMagSf_[srcFacei]; scalar areaTotal = this->srcMagSf_[srcFacei];
@ -234,13 +231,13 @@ void Foam::faceAreaWeightAMI<SourcePatch, TargetPatch>::setNextFaces
{ {
// try to use existing seed // try to use existing seed
bool foundNextSeed = false; bool foundNextSeed = false;
for (label facei = startSeedI; facei < mapFlag.size(); facei++) for (label facei = startSeedi; facei < mapFlag.size(); facei++)
{ {
if (mapFlag[facei]) if (mapFlag[facei])
{ {
if (!foundNextSeed) if (!foundNextSeed)
{ {
startSeedI = facei; startSeedi = facei;
foundNextSeed = true; foundNextSeed = true;
} }
@ -262,13 +259,13 @@ void Foam::faceAreaWeightAMI<SourcePatch, TargetPatch>::setNextFaces
} }
foundNextSeed = false; foundNextSeed = false;
for (label facei = startSeedI; facei < mapFlag.size(); facei++) for (label facei = startSeedi; facei < mapFlag.size(); facei++)
{ {
if (mapFlag[facei]) if (mapFlag[facei])
{ {
if (!foundNextSeed) if (!foundNextSeed)
{ {
startSeedI = facei + 1; startSeedi = facei + 1;
foundNextSeed = true; foundNextSeed = true;
} }
@ -316,7 +313,8 @@ Foam::scalar Foam::faceAreaWeightAMI<SourcePatch, TargetPatch>::interArea
} }
// create intersection object // create intersection object
faceAreaIntersect inter(srcPoints, tgtPoints, this->reverseTarget_); bool cache = true;
faceAreaIntersect inter(srcPoints, tgtPoints, this->reverseTarget_, cache);
// crude resultant norm // crude resultant norm
vector n(-this->srcPatch_.faceNormals()[srcFacei]); vector n(-this->srcPatch_.faceNormals()[srcFacei]);
@ -333,6 +331,8 @@ Foam::scalar Foam::faceAreaWeightAMI<SourcePatch, TargetPatch>::interArea
if (magN > ROOTVSMALL) if (magN > ROOTVSMALL)
{ {
area = inter.calc(src, tgt, n/magN, this->triMode_); area = inter.calc(src, tgt, n/magN, this->triMode_);
DebugVar(inter.triangles());
DebugVar(inter.triangles().size());
} }
else else
{ {

View File

@ -107,7 +107,7 @@ protected:
//- Set the source and target seed faces //- Set the source and target seed faces
virtual void setNextFaces virtual void setNextFaces
( (
label& startSeedI, label& startSeedi,
label& srcFacei, label& srcFacei,
label& tgtFacei, label& tgtFacei,
const boolList& mapFlag, const boolList& mapFlag,

View File

@ -30,7 +30,7 @@ License
template<class SourcePatch, class TargetPatch> template<class SourcePatch, class TargetPatch>
void Foam::partialFaceAreaWeightAMI<SourcePatch, TargetPatch>::setNextFaces void Foam::partialFaceAreaWeightAMI<SourcePatch, TargetPatch>::setNextFaces
( (
label& startSeedI, label& startSeedi,
label& srcFacei, label& srcFacei,
label& tgtFacei, label& tgtFacei,
const boolList& mapFlag, const boolList& mapFlag,
@ -41,7 +41,7 @@ void Foam::partialFaceAreaWeightAMI<SourcePatch, TargetPatch>::setNextFaces
{ {
faceAreaWeightAMI<SourcePatch, TargetPatch>::setNextFaces faceAreaWeightAMI<SourcePatch, TargetPatch>::setNextFaces
( (
startSeedI, startSeedi,
srcFacei, srcFacei,
tgtFacei, tgtFacei,
mapFlag, mapFlag,

View File

@ -67,7 +67,7 @@ private:
//- Set the source and target seed faces //- Set the source and target seed faces
virtual void setNextFaces virtual void setNextFaces
( (
label& startSeedI, label& startSeedi,
label& srcFacei, label& srcFacei,
label& tgtFacei, label& tgtFacei,
const boolList& mapFlag, const boolList& mapFlag,

View File

@ -231,14 +231,14 @@ Foam::scalar Foam::faceAreaIntersect::triangleIntersect
FixedList<triPoints, 10> workTris2; FixedList<triPoints, 10> workTris2;
label nWorkTris2 = 0; label nWorkTris2 = 0;
// cut source triangle with all inwards pointing faces of target triangle // Cut source triangle with all inward pointing faces of target triangle
// - triangles in workTris1 are inside target triangle // - triangles in workTris1 are inside target triangle
scalar t = sqrt(triArea(src)); const scalar t = sqrt(triArea(src));
// edge 0 // Edge 0
{ {
// cut triangle src with plane and put resulting sub-triangles in // Cut triangle src with plane and put resulting sub-triangles in
// workTris1 list // workTris1 list
scalar s = mag(tgt[1] - tgt[0]); scalar s = mag(tgt[1] - tgt[0]);
@ -251,9 +251,9 @@ Foam::scalar Foam::faceAreaIntersect::triangleIntersect
return 0.0; return 0.0;
} }
// edge1 // Edge 1
{ {
// cut workTris1 with plane and put resulting sub-triangles in // Cut workTris1 with plane and put resulting sub-triangles in
// workTris2 list (re-use tris storage) // workTris2 list (re-use tris storage)
scalar s = mag(tgt[2] - tgt[1]); scalar s = mag(tgt[2] - tgt[1]);
@ -272,9 +272,9 @@ Foam::scalar Foam::faceAreaIntersect::triangleIntersect
} }
} }
// edge2 // Edge 2
{ {
// cut workTris2 with plane and put resulting sub-triangles in // Cut workTris2 with plane and put resulting sub-triangles in
// workTris1 list (re-use workTris1 storage) // workTris1 list (re-use workTris1 storage)
scalar s = mag(tgt[2] - tgt[0]); scalar s = mag(tgt[2] - tgt[0]);
@ -293,11 +293,16 @@ Foam::scalar Foam::faceAreaIntersect::triangleIntersect
} }
else else
{ {
// calculate area of sub-triangles // Calculate area of sub-triangles
scalar area = 0.0; scalar area = 0.0;
for (label i = 0; i < nWorkTris1; i++) for (label i = 0; i < nWorkTris1; i++)
{ {
area += triArea(workTris1[i]); area += triArea(workTris1[i]);
if (cacheTriangulation_)
{
triangles_.append(workTris1[i]);
}
} }
return area; return area;
@ -312,12 +317,15 @@ Foam::faceAreaIntersect::faceAreaIntersect
( (
const pointField& pointsA, const pointField& pointsA,
const pointField& pointsB, const pointField& pointsB,
const bool reverseB const bool reverseB,
const bool cacheTriangulation
) )
: :
pointsA_(pointsA), pointsA_(pointsA),
pointsB_(pointsB), pointsB_(pointsB),
reverseB_(reverseB) reverseB_(reverseB),
cacheTriangulation_(cacheTriangulation),
triangles_(cacheTriangulation ? 10 : 0)
{} {}
@ -379,8 +387,10 @@ Foam::scalar Foam::faceAreaIntersect::calc
triangulate(faceA, pointsA_, triMode, trisA); triangulate(faceA, pointsA_, triMode, trisA);
triangulate(faceB, pointsB_, triMode, trisB); triangulate(faceB, pointsB_, triMode, trisB);
// intersect triangles // Intersect triangles
scalar totalArea = 0.0; scalar totalArea = 0.0;
triangles_.clear();
forAll(trisA, tA) forAll(trisA, tA)
{ {
triPoints tpA = getTriPoints(pointsA_, trisA[tA], false); triPoints tpA = getTriPoints(pointsA_, trisA[tA], false);

View File

@ -79,6 +79,12 @@ private:
//- Flag to reverse B faces //- Flag to reverse B faces
const bool reverseB_; const bool reverseB_;
//- Flag to cache the final triangulation
bool cacheTriangulation_;
//- Final triangulation
DynamicList<triPoints> triangles_;
// Static data members // Static data members
@ -146,7 +152,8 @@ public:
( (
const pointField& pointsA, const pointField& pointsA,
const pointField& pointsB, const pointField& pointsB,
const bool reverseB = false const bool reverseB = false,
const bool cacheTriangulation = false
); );
@ -164,6 +171,15 @@ public:
faceList& faceTris faceList& faceTris
); );
//- Const access to the cacheTriangulation flag
inline bool cacheTriangulation() const;
//- Const access to the triangulation
inline const DynamicList<triPoints> triangles() const;
//- Non-const access to the triangulation
inline DynamicList<triPoints>& triangles();
//- Return area of intersection of faceA with faceB //- Return area of intersection of faceA with faceB
scalar calc scalar calc
( (

View File

@ -75,7 +75,9 @@ inline Foam::point Foam::faceAreaIntersect::planeIntersection
const label posI const label posI
) const ) const
{ {
return (d[posI]*t[negI] - d[negI]*t[posI])/(-d[negI] + d[posI]); scalar dp = d[posI];
scalar dn = d[negI];
return (dp*t[negI] - dn*t[posI])/(-dn + dp);
} }
@ -93,4 +95,22 @@ Foam::scalar& Foam::faceAreaIntersect::tolerance()
} }
bool Foam::faceAreaIntersect::cacheTriangulation() const
{
return cacheTriangulation_;
}
const Foam::DynamicList<Foam::triPoints>
Foam::faceAreaIntersect::triangles() const
{
return triangles_;
}
Foam::DynamicList<Foam::triPoints>& Foam::faceAreaIntersect::triangles()
{
return triangles_;
}
// ************************************************************************* // // ************************************************************************* //