diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/faceAreaWeightAMI/faceAreaWeightAMI.C b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/faceAreaWeightAMI/faceAreaWeightAMI.C index 266489c717d2852e7b1d64cf721f3f37148fba0a..f7fed218975a05c58d2925822169a1724ce58b31 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/faceAreaWeightAMI/faceAreaWeightAMI.C +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/faceAreaWeightAMI/faceAreaWeightAMI.C @@ -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 { diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/faceAreaWeightAMI/faceAreaWeightAMI.H b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/faceAreaWeightAMI/faceAreaWeightAMI.H index 7ab28ea61e3104a4a6973bab753bd9ce8ffd874c..43280f49c9ec828af1794f3e44d9cb4150efa00e 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/faceAreaWeightAMI/faceAreaWeightAMI.H +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/faceAreaWeightAMI/faceAreaWeightAMI.H @@ -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, diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/partialFaceAreaWeightAMI/partialFaceAreaWeightAMI.C b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/partialFaceAreaWeightAMI/partialFaceAreaWeightAMI.C index b6914215aa426831db8dab331a2ada4e3e67f90b..efd654d07bfae90b56bc3eb17a6cfdb417bf62f0 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/partialFaceAreaWeightAMI/partialFaceAreaWeightAMI.C +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/partialFaceAreaWeightAMI/partialFaceAreaWeightAMI.C @@ -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, diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/partialFaceAreaWeightAMI/partialFaceAreaWeightAMI.H b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/partialFaceAreaWeightAMI/partialFaceAreaWeightAMI.H index 89bef39e0b00db964510e369e574d4a11bea605f..f0088b8926c193cc2dc097aa17ca1cbb4e4a4f7c 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/partialFaceAreaWeightAMI/partialFaceAreaWeightAMI.H +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/partialFaceAreaWeightAMI/partialFaceAreaWeightAMI.H @@ -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, diff --git a/src/meshTools/AMIInterpolation/faceAreaIntersect/faceAreaIntersect.C b/src/meshTools/AMIInterpolation/faceAreaIntersect/faceAreaIntersect.C index d52d19cedc8fadd5dbd28e7f05f6d87918dbd104..fbd63925d87c7a9416b95ae7b8a5694c2382c0de 100644 --- a/src/meshTools/AMIInterpolation/faceAreaIntersect/faceAreaIntersect.C +++ b/src/meshTools/AMIInterpolation/faceAreaIntersect/faceAreaIntersect.C @@ -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); diff --git a/src/meshTools/AMIInterpolation/faceAreaIntersect/faceAreaIntersect.H b/src/meshTools/AMIInterpolation/faceAreaIntersect/faceAreaIntersect.H index b2fe05b23f6976b5e199233018bf13202f97f960..2c1946c4a30165d5ebda198435de6a7d068c3f94 100644 --- a/src/meshTools/AMIInterpolation/faceAreaIntersect/faceAreaIntersect.H +++ b/src/meshTools/AMIInterpolation/faceAreaIntersect/faceAreaIntersect.H @@ -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 ( diff --git a/src/meshTools/AMIInterpolation/faceAreaIntersect/faceAreaIntersectI.H b/src/meshTools/AMIInterpolation/faceAreaIntersect/faceAreaIntersectI.H index 329c75d821f39782e00a7787cd241db1911eec7a..e53a78fa5b6c38f4d3727b95c3690db1e55c5f64 100644 --- a/src/meshTools/AMIInterpolation/faceAreaIntersect/faceAreaIntersectI.H +++ b/src/meshTools/AMIInterpolation/faceAreaIntersect/faceAreaIntersectI.H @@ -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_; +} + // ************************************************************************* //