Commit 2be17edc authored by Andrew Heather's avatar Andrew Heather
Browse files

ENH: AMIInterpolation - added base for caching of triangulation

parent 80ffdfb1
......@@ -57,7 +57,7 @@ void Foam::faceAreaWeightAMI<SourcePatch, TargetPatch>::calcAddressing
boolList mapFlag(nFacesRemaining, true);
// reset starting seed
label startSeedI = 0;
label startSeedi = 0;
DynamicList<label> nonOverlapFaces;
do
......@@ -91,7 +91,7 @@ void Foam::faceAreaWeightAMI<SourcePatch, TargetPatch>::calcAddressing
{
setNextFaces
(
startSeedI,
startSeedi,
srcFacei,
tgtFacei,
mapFlag,
......@@ -179,7 +179,7 @@ bool Foam::faceAreaWeightAMI<SourcePatch, TargetPatch>::processSourceFace
template<class SourcePatch, class TargetPatch>
void Foam::faceAreaWeightAMI<SourcePatch, TargetPatch>::setNextFaces
(
label& startSeedI,
label& startSeedi,
label& srcFacei,
label& tgtFacei,
const boolList& mapFlag,
......@@ -195,15 +195,12 @@ void Foam::faceAreaWeightAMI<SourcePatch, TargetPatch>::setNextFaces
// set possible seeds for later use
bool valuesSet = false;
forAll(srcNbrFaces, i)
for (label faceS: srcNbrFaces)
{
label faceS = srcNbrFaces[i];
if (mapFlag[faceS] && seedFaces[faceS] == -1)
{
forAll(visitedFaces, j)
for (label faceT : visitedFaces)
{
label faceT = visitedFaces[j];
scalar area = interArea(faceS, faceT);
scalar areaTotal = this->srcMagSf_[srcFacei];
......@@ -234,13 +231,13 @@ void Foam::faceAreaWeightAMI<SourcePatch, TargetPatch>::setNextFaces
{
// try to use existing seed
bool foundNextSeed = false;
for (label facei = startSeedI; facei < mapFlag.size(); facei++)
for (label facei = startSeedi; facei < mapFlag.size(); facei++)
{
if (mapFlag[facei])
{
if (!foundNextSeed)
{
startSeedI = facei;
startSeedi = facei;
foundNextSeed = true;
}
......@@ -262,13 +259,13 @@ void Foam::faceAreaWeightAMI<SourcePatch, TargetPatch>::setNextFaces
}
foundNextSeed = false;
for (label facei = startSeedI; facei < mapFlag.size(); facei++)
for (label facei = startSeedi; facei < mapFlag.size(); facei++)
{
if (mapFlag[facei])
{
if (!foundNextSeed)
{
startSeedI = facei + 1;
startSeedi = facei + 1;
foundNextSeed = true;
}
......@@ -316,7 +313,8 @@ Foam::scalar Foam::faceAreaWeightAMI<SourcePatch, TargetPatch>::interArea
}
// create intersection object
faceAreaIntersect inter(srcPoints, tgtPoints, this->reverseTarget_);
bool cache = true;
faceAreaIntersect inter(srcPoints, tgtPoints, this->reverseTarget_, cache);
// crude resultant norm
vector n(-this->srcPatch_.faceNormals()[srcFacei]);
......@@ -333,6 +331,8 @@ Foam::scalar Foam::faceAreaWeightAMI<SourcePatch, TargetPatch>::interArea
if (magN > ROOTVSMALL)
{
area = inter.calc(src, tgt, n/magN, this->triMode_);
DebugVar(inter.triangles());
DebugVar(inter.triangles().size());
}
else
{
......
......@@ -107,7 +107,7 @@ protected:
//- Set the source and target seed faces
virtual void setNextFaces
(
label& startSeedI,
label& startSeedi,
label& srcFacei,
label& tgtFacei,
const boolList& mapFlag,
......
......@@ -30,7 +30,7 @@ License
template<class SourcePatch, class TargetPatch>
void Foam::partialFaceAreaWeightAMI<SourcePatch, TargetPatch>::setNextFaces
(
label& startSeedI,
label& startSeedi,
label& srcFacei,
label& tgtFacei,
const boolList& mapFlag,
......@@ -41,7 +41,7 @@ void Foam::partialFaceAreaWeightAMI<SourcePatch, TargetPatch>::setNextFaces
{
faceAreaWeightAMI<SourcePatch, TargetPatch>::setNextFaces
(
startSeedI,
startSeedi,
srcFacei,
tgtFacei,
mapFlag,
......
......@@ -67,7 +67,7 @@ private:
//- Set the source and target seed faces
virtual void setNextFaces
(
label& startSeedI,
label& startSeedi,
label& srcFacei,
label& tgtFacei,
const boolList& mapFlag,
......
......@@ -231,14 +231,14 @@ Foam::scalar Foam::faceAreaIntersect::triangleIntersect
FixedList<triPoints, 10> workTris2;
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
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
scalar s = mag(tgt[1] - tgt[0]);
......@@ -251,9 +251,9 @@ Foam::scalar Foam::faceAreaIntersect::triangleIntersect
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)
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)
scalar s = mag(tgt[2] - tgt[0]);
......@@ -293,11 +293,16 @@ Foam::scalar Foam::faceAreaIntersect::triangleIntersect
}
else
{
// calculate area of sub-triangles
// Calculate area of sub-triangles
scalar area = 0.0;
for (label i = 0; i < nWorkTris1; i++)
{
area += triArea(workTris1[i]);
if (cacheTriangulation_)
{
triangles_.append(workTris1[i]);
}
}
return area;
......@@ -312,12 +317,15 @@ Foam::faceAreaIntersect::faceAreaIntersect
(
const pointField& pointsA,
const pointField& pointsB,
const bool reverseB
const bool reverseB,
const bool cacheTriangulation
)
:
pointsA_(pointsA),
pointsB_(pointsB),
reverseB_(reverseB)
reverseB_(reverseB),
cacheTriangulation_(cacheTriangulation),
triangles_(cacheTriangulation ? 10 : 0)
{}
......@@ -337,7 +345,7 @@ void Foam::faceAreaIntersect::triangulate
{
case tmFan:
{
for (label i = 0; i < f.nTriangles(); ++ i)
for (label i = 0; i < f.nTriangles(); ++i)
{
faceTris[i] = face(3);
faceTris[i][0] = f[0];
......@@ -379,8 +387,10 @@ Foam::scalar Foam::faceAreaIntersect::calc
triangulate(faceA, pointsA_, triMode, trisA);
triangulate(faceB, pointsB_, triMode, trisB);
// intersect triangles
// Intersect triangles
scalar totalArea = 0.0;
triangles_.clear();
forAll(trisA, tA)
{
triPoints tpA = getTriPoints(pointsA_, trisA[tA], false);
......
......@@ -79,6 +79,12 @@ private:
//- Flag to reverse B faces
const bool reverseB_;
//- Flag to cache the final triangulation
bool cacheTriangulation_;
//- Final triangulation
DynamicList<triPoints> triangles_;
// Static data members
......@@ -146,7 +152,8 @@ public:
(
const pointField& pointsA,
const pointField& pointsB,
const bool reverseB = false
const bool reverseB = false,
const bool cacheTriangulation = false
);
......@@ -164,6 +171,15 @@ public:
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
scalar calc
(
......
......@@ -75,7 +75,9 @@ inline Foam::point Foam::faceAreaIntersect::planeIntersection
const label posI
) 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_;
}
// ************************************************************************* //
Markdown is supported
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