From bb5a8daa093bc10211f35af1a5f7fb9991248610 Mon Sep 17 00:00:00 2001 From: mattijs <mattijs> Date: Mon, 18 Jun 2012 14:29:18 +0100 Subject: [PATCH] ENH: AMIinterpolation: store normalisation factors --- .../AMIInterpolation/AMIInterpolation.C | 80 +++++++++++++------ .../AMIInterpolation/AMIInterpolation.H | 19 ++++- .../AMIInterpolation/AMIInterpolationI.H | 16 ++++ 3 files changed, 87 insertions(+), 28 deletions(-) diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C index 3962697845a..5acc8dfa4c4 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C @@ -1164,50 +1164,36 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::normaliseWeights const word& patchName, const labelListList& addr, scalarListList& wght, + scalarField& wghtSum, const bool output ) { - scalar minBound = VGREAT; - scalar maxBound = -VGREAT; - - scalar tSum = 0.0; - // Normalise the weights + wghtSum.setSize(wght.size()); forAll(wght, faceI) { scalar s = sum(wght[faceI]); scalar t = s/patchAreas[faceI]; - tSum += t; - - if (t < minBound) - { - minBound = t; - } - - if (t > maxBound) - { - maxBound = t; - } - forAll(addr[faceI], i) { wght[faceI][i] /= s; } + + wghtSum[faceI] = t; } if (output) { - const label nFace = returnReduce(wght.size(), sumOp<scalar>()); - reduce(tSum, sumOp<scalar>()); + const label nFace = returnReduce(wght.size(), sumOp<label>()); if (nFace) { Info<< "AMI: Patch " << patchName << " weights min/max/average = " - << returnReduce(minBound, minOp<scalar>()) << ", " - << returnReduce(maxBound, maxOp<scalar>()) << ", " - << tSum/nFace << endl; + << gMin(wghtSum) << ", " + << gMax(wghtSum) << ", " + << gAverage(wghtSum) << endl; } } } @@ -1227,6 +1213,7 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::agglomerate scalarField& srcMagSf, labelListList& srcAddress, scalarListList& srcWeights, + scalarField& srcWeightsSum, autoPtr<mapDistribute>& tgtMap ) { @@ -1468,6 +1455,7 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::agglomerate "source", srcAddress, srcWeights, + srcWeightsSum, false ); } @@ -1488,9 +1476,11 @@ Foam::AMIInterpolation<SourcePatch, TargetPatch>::AMIInterpolation singlePatchProc_(-999), srcAddress_(), srcWeights_(), + srcWeightsSum_(), srcNonOverlap_(), tgtAddress_(), tgtWeights_(), + tgtWeightsSum_(), treePtr_(NULL), triMode_(triMode), srcMapPtr_(NULL), @@ -1521,9 +1511,11 @@ Foam::AMIInterpolation<SourcePatch, TargetPatch>::AMIInterpolation singlePatchProc_(-999), srcAddress_(), srcWeights_(), + srcWeightsSum_(), srcNonOverlap_(), tgtAddress_(), tgtWeights_(), + tgtWeightsSum_(), treePtr_(NULL), triMode_(triMode), srcMapPtr_(NULL), @@ -1609,9 +1601,11 @@ Foam::AMIInterpolation<SourcePatch, TargetPatch>::AMIInterpolation singlePatchProc_(fineAMI.singlePatchProc_), srcAddress_(), srcWeights_(), + srcWeightsSum_(), srcNonOverlap_(), tgtAddress_(), tgtWeights_(), + tgtWeightsSum_(), treePtr_(NULL), triMode_(fineAMI.triMode_), srcMapPtr_(NULL), @@ -1681,6 +1675,7 @@ Foam::AMIInterpolation<SourcePatch, TargetPatch>::AMIInterpolation srcMagSf_, srcAddress_, srcWeights_, + srcWeightsSum_, tgtMapPtr_ ); @@ -1706,6 +1701,7 @@ Foam::AMIInterpolation<SourcePatch, TargetPatch>::AMIInterpolation tgtMagSf_, tgtAddress_, tgtWeights_, + tgtWeightsSum_, srcMapPtr_ ); @@ -1857,8 +1853,24 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::update ); // weights normalisation - normaliseWeights(srcMagSf_, "source", srcAddress_, srcWeights_, true); - normaliseWeights(tgtMagSf_, "target", tgtAddress_, tgtWeights_, true); + normaliseWeights + ( + srcMagSf_, + "source", + srcAddress_, + srcWeights_, + srcWeightsSum_, + true + ); + normaliseWeights + ( + tgtMagSf_, + "target", + tgtAddress_, + tgtWeights_, + tgtWeightsSum_, + true + ); // cache maps and reset addresses List<Map<label> > cMap; @@ -1877,8 +1889,24 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::update calcAddressing(srcPatch, tgtPatch); - normaliseWeights(srcMagSf_, "source", srcAddress_, srcWeights_, true); - normaliseWeights(tgtMagSf_, "target", tgtAddress_, tgtWeights_, true); + normaliseWeights + ( + srcMagSf_, + "source", + srcAddress_, + srcWeights_, + srcWeightsSum_, + true + ); + normaliseWeights + ( + tgtMagSf_, + "target", + tgtAddress_, + tgtWeights_, + tgtWeightsSum_, + true + ); } if (debug) diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.H b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.H index d8cb82c07cf..b3930308235 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.H +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.H @@ -106,6 +106,9 @@ class AMIInterpolation //- Weights of target faces per source face scalarListList srcWeights_; + //- Sum of weights of target faces per source face + scalarField srcWeightsSum_; + //- Labels of faces that are not overlapped by any target faces // (should be empty for correct functioning) labelList srcNonOverlap_; @@ -122,6 +125,9 @@ class AMIInterpolation //- Weights of source faces per target face scalarListList tgtWeights_; + //- Sum of weights of source faces per target face + scalarField tgtWeightsSum_; + //- Octree used to find face seeds autoPtr<indexedOctree<treeType> > treePtr_; @@ -285,6 +291,7 @@ class AMIInterpolation const word& patchName, const labelListList& addr, scalarListList& wght, + scalarField& wghtSum, const bool output ); @@ -304,6 +311,7 @@ class AMIInterpolation scalarField& srcMagSf, labelListList& srcAddress, scalarListList& srcWeights, + scalarField& srcWeightsSum, autoPtr<mapDistribute>& tgtMap ); @@ -365,11 +373,14 @@ public: //- Return const access to source patch weights inline const scalarListList& srcWeights() const; + //- Return const access to normalisation factor of source + // patch weights (i.e. the sum before normalisation) + inline const scalarField& srcWeightsSum() const; + //- Labels of faces that are not overlapped by any target faces // (should be empty for correct functioning) inline const labelList& srcNonOverlap() const; - //- Source map pointer - valid only if singlePatchProc = -1 // This gets source data into a form to be consumed by // tgtAddress, tgtWeights @@ -387,7 +398,11 @@ public: //- Return const access to target patch weights inline const scalarListList& tgtWeights() const; - //- Target map pointer - valid only if singlePatchProc = -1 + //- Return const access to normalisation factor of target + // patch weights (i.e. the sum before normalisation) + inline const scalarField& tgtWeightsSum() const; + + //- Target map pointer - valid only if singlePatchProc=-1. // This gets target data into a form to be consumed by // srcAddress, srcWeights inline const mapDistribute& tgtMap() const; diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolationI.H b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolationI.H index 3dd21b5aa3a..f2782bad886 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolationI.H +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolationI.H @@ -63,6 +63,14 @@ Foam::AMIInterpolation<SourcePatch, TargetPatch>::srcNonOverlap() const } +template<class SourcePatch, class TargetPatch> +inline const Foam::scalarField& +Foam::AMIInterpolation<SourcePatch, TargetPatch>::srcWeightsSum() const +{ + return srcWeightsSum_; +} + + template<class SourcePatch, class TargetPatch> inline const Foam::mapDistribute& Foam::AMIInterpolation<SourcePatch, TargetPatch>::srcMap() const @@ -95,6 +103,14 @@ Foam::AMIInterpolation<SourcePatch, TargetPatch>::tgtWeights() const } +template<class SourcePatch, class TargetPatch> +inline const Foam::scalarField& +Foam::AMIInterpolation<SourcePatch, TargetPatch>::tgtWeightsSum() const +{ + return tgtWeightsSum_; +} + + template<class SourcePatch, class TargetPatch> inline const Foam::mapDistribute& Foam::AMIInterpolation<SourcePatch, TargetPatch>::tgtMap() const -- GitLab