diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C index b6b133b68e..5d9153c65b 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -1062,7 +1062,7 @@ void Foam::AMIInterpolation::update ); // weights normalisation - normaliseWeights(AMIPtr->conformal(), true); + AMIPtr->normaliseWeights(true, *this); // cache maps and reset addresses List> cMap; @@ -1095,7 +1095,7 @@ void Foam::AMIInterpolation::update tgtWeights_ ); - normaliseWeights(AMIPtr->conformal(), true); + AMIPtr->normaliseWeights(true, *this); } if (debug) diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.H b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.H index e0dc1c9ca4..ab0e8fe2e4 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.H +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -372,9 +372,15 @@ public: //- Return const access to source patch face areas inline const scalarField& srcMagSf() const; + //- Return access to source patch face areas + inline scalarField& srcMagSf(); + //- Return const access to source patch addressing inline const labelListList& srcAddress() const; + //- Return access to source patch addressing + inline labelListList& srcAddress(); + //- Return const access to source patch weights inline const scalarListList& srcWeights() const; @@ -400,9 +406,15 @@ public: //- Return const access to target patch face areas inline const scalarField& tgtMagSf() const; + //- Return access to target patch face areas + inline scalarField& tgtMagSf(); + //- Return const access to target patch addressing inline const labelListList& tgtAddress() const; + //- Return access to target patch addressing + inline labelListList& tgtAddress(); + //- Return const access to target patch weights inline const scalarListList& tgtWeights() const; diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolationI.H b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolationI.H index 5e74e7b4c6..5e6acaa64a 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolationI.H +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolationI.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -56,6 +56,14 @@ Foam::AMIInterpolation::srcMagSf() const } +template +inline Foam::scalarField& +Foam::AMIInterpolation::srcMagSf() +{ + return srcMagSf_; +} + + template inline const Foam::labelListList& Foam::AMIInterpolation::srcAddress() const @@ -64,6 +72,14 @@ Foam::AMIInterpolation::srcAddress() const } +template +inline Foam::labelListList& +Foam::AMIInterpolation::srcAddress() +{ + return srcAddress_; +} + + template inline const Foam::scalarListList& Foam::AMIInterpolation::srcWeights() const @@ -112,6 +128,14 @@ Foam::AMIInterpolation::tgtMagSf() const } +template +inline Foam::scalarField& +Foam::AMIInterpolation::tgtMagSf() +{ + return tgtMagSf_; +} + + template inline const Foam::labelListList& Foam::AMIInterpolation::tgtAddress() const @@ -120,6 +144,14 @@ Foam::AMIInterpolation::tgtAddress() const } +template +inline Foam::labelListList& +Foam::AMIInterpolation::tgtAddress() +{ + return tgtAddress_; +} + + template inline const Foam::scalarListList& Foam::AMIInterpolation::tgtWeights() const diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/AMIMethod/AMIMethod.H b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/AMIMethod/AMIMethod.H index 706d19b0b5..71406ad7eb 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/AMIMethod/AMIMethod.H +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/AMIMethod/AMIMethod.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpcnCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -48,6 +48,8 @@ SourceFiles namespace Foam { +template class AMIInterpolation; + /*---------------------------------------------------------------------------*\ Class AMIMethod Declaration \*---------------------------------------------------------------------------*/ @@ -238,6 +240,14 @@ public: label srcFaceI = -1, label tgtFaceI = -1 ) = 0; + + //- Normalise the weight. Can optionally subset addressing + // (e.g. for mapNearest) + virtual void normaliseWeights + ( + const bool verbose, + AMIInterpolation& inter + ) = 0; }; diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/directAMI/directAMI.C b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/directAMI/directAMI.C index 3884848bad..acc8876f71 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/directAMI/directAMI.C +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/directAMI/directAMI.C @@ -322,4 +322,15 @@ void Foam::directAMI::calculate } +template +void Foam::directAMI::normaliseWeights +( + const bool verbose, + AMIInterpolation& inter +) +{ + inter.normaliseWeights(this->conformal(), verbose); +} + + // ************************************************************************* // diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/directAMI/directAMI.H b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/directAMI/directAMI.H index 19abca727a..55f252c3ea 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/directAMI/directAMI.H +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/directAMI/directAMI.H @@ -135,6 +135,14 @@ public: label srcFaceI = -1, label tgtFaceI = -1 ); + + //- Normalise the weight. Can optionally subset addressing + // (e.g. for mapNearest) + virtual void normaliseWeights + ( + const bool verbose, + AMIInterpolation& inter + ); }; diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/faceAreaWeightAMI/faceAreaWeightAMI.C b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/faceAreaWeightAMI/faceAreaWeightAMI.C index 976430e930..b238cfc84e 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/faceAreaWeightAMI/faceAreaWeightAMI.C +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/faceAreaWeightAMI/faceAreaWeightAMI.C @@ -568,4 +568,15 @@ void Foam::faceAreaWeightAMI::calculate } +template +void Foam::faceAreaWeightAMI::normaliseWeights +( + const bool verbose, + AMIInterpolation& inter +) +{ + inter.normaliseWeights(this->conformal(), verbose); +} + + // ************************************************************************* // diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/faceAreaWeightAMI/faceAreaWeightAMI.H b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/faceAreaWeightAMI/faceAreaWeightAMI.H index 7162d602d9..b9081a8fb1 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/faceAreaWeightAMI/faceAreaWeightAMI.H +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/faceAreaWeightAMI/faceAreaWeightAMI.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -167,6 +167,14 @@ public: label srcFaceI = -1, label tgtFaceI = -1 ); + + //- Normalise the weight. Can optionally subset addressing + // (e.g. for mapNearest) + virtual void normaliseWeights + ( + const bool verbose, + AMIInterpolation& inter + ); }; diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/mapNearestAMI/mapNearestAMI.C b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/mapNearestAMI/mapNearestAMI.C index 030434a7d3..42b9985e70 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/mapNearestAMI/mapNearestAMI.C +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/mapNearestAMI/mapNearestAMI.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -322,19 +322,111 @@ void Foam::mapNearestAMI::calculate // transfer data to persistent storage - forAll(srcAddr, i) + const pointField& srcFc = this->srcPatch_.faceCentres(); + const pointField& tgtFc = this->tgtPatch_.faceCentres(); + + forAll(srcAddr, srcI) { - scalar magSf = this->srcMagSf_[i]; - srcAddress[i].transfer(srcAddr[i]); - srcWeights[i] = scalarList(1, magSf); + srcAddress[srcI].transfer(srcAddr[srcI]); + + const labelList& addr = srcAddress[srcI]; + srcWeights[srcI].setSize(addr.size()); + const point& srcPt = srcFc[srcI]; + forAll(addr, i) + { + srcWeights[srcI][i] = magSqr(srcPt-tgtFc[addr[i]]); + } } - forAll(tgtAddr, i) + forAll(tgtAddr, tgtI) { - scalar magSf = this->tgtMagSf_[i]; - tgtAddress[i].transfer(tgtAddr[i]); - tgtWeights[i] = scalarList(1, magSf); + tgtAddress[tgtI].transfer(tgtAddr[tgtI]); + + const labelList& addr = tgtAddress[tgtI]; + tgtWeights[tgtI].setSize(addr.size()); + const point& tgtPt = tgtFc[tgtI]; + forAll(addr, i) + { + tgtWeights[tgtI][i] = magSqr(tgtPt-srcFc[addr[i]]); + } } } +template +void Foam::mapNearestAMI::normaliseWeights +( + const bool verbose, + AMIInterpolation& inter +) +{ + { + labelListList& srcAddress = inter.srcAddress(); + scalarListList& srcWeights = inter.srcWeights(); + + forAll(srcAddress, srcI) + { + labelList& addr = srcAddress[srcI]; + scalarList& wghts = srcWeights[srcI]; + + // Choose one with smallest weight (since calculate above returns + // distance) + if (addr.size()) + { + label minFaceI = addr[0]; + scalar minWeight = wghts[0]; + + for (label i = 0; i < addr.size(); i++) + { + if (wghts[i] < minWeight) + { + minWeight = wghts[i]; + minFaceI = addr[i]; + } + } + + wghts.setSize(1); + wghts[0] = this->srcMagSf_[srcI]; + addr.setSize(1); + addr[0] = minFaceI; + } + } + } + + { + labelListList& tgtAddress = inter.tgtAddress(); + scalarListList& tgtWeights = inter.tgtWeights(); + + forAll(tgtAddress, tgtI) + { + labelList& addr = tgtAddress[tgtI]; + scalarList& wghts = tgtWeights[tgtI]; + + // Choose one with smallest weight (since calculate above returns + // distance) + if (addr.size()) + { + label minFaceI = addr[0]; + scalar minWeight = wghts[0]; + + for (label i = 0; i < addr.size(); i++) + { + if (wghts[i] < minWeight) + { + minWeight = wghts[i]; + minFaceI = addr[i]; + } + } + + wghts.setSize(1); + wghts[0] = inter.tgtMagSf()[tgtI]; + addr.setSize(1); + addr[0] = minFaceI; + } + } + } + + inter.normaliseWeights(this->conformal(), verbose); +} + + // ************************************************************************* // diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/mapNearestAMI/mapNearestAMI.H b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/mapNearestAMI/mapNearestAMI.H index 8e8634705b..04c5e6768e 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/mapNearestAMI/mapNearestAMI.H +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/mapNearestAMI/mapNearestAMI.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -139,6 +139,14 @@ public: label srcFaceI = -1, label tgtFaceI = -1 ); + + //- Normalise the weight. Can optionally subset addressing + // (e.g. for mapNearest) + virtual void normaliseWeights + ( + const bool verbose, + AMIInterpolation& inter + ); }; diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/partialFaceAreaWeightAMI/partialFaceAreaWeightAMI.H b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/partialFaceAreaWeightAMI/partialFaceAreaWeightAMI.H index 2e3855270b..f44371ac12 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/partialFaceAreaWeightAMI/partialFaceAreaWeightAMI.H +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/partialFaceAreaWeightAMI/partialFaceAreaWeightAMI.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM.