diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C index e5dcad0c8d..801877daac 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-2015 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 67205b69a7..02bdf413e2 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-2015 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -372,16 +372,29 @@ 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; + //- Return access to source patch weights + inline scalarListList& srcWeights(); + //- Return const access to normalisation factor of source // patch weights (i.e. the sum before normalisation) inline const scalarField& srcWeightsSum() const; + //- Return access to normalisation factor of source + // patch weights (i.e. the sum before normalisation) + inline scalarField& srcWeightsSum(); + //- Source map pointer - valid only if singlePatchProc = -1 // This gets source data into a form to be consumed by // tgtAddress, tgtWeights @@ -393,16 +406,29 @@ 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; + //- Return access to target patch weights + inline scalarListList& tgtWeights(); + //- Return const access to normalisation factor of target // patch weights (i.e. the sum before normalisation) inline const scalarField& tgtWeightsSum() const; + //- Return access to normalisation factor of target + // patch weights (i.e. the sum before normalisation) + inline scalarField& tgtWeightsSum(); + //- Target map pointer - valid only if singlePatchProc=-1. // This gets target data into a form to be consumed by // srcAddress, srcWeights diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolationI.H b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolationI.H index 9c59cb6865..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 @@ -72,6 +88,14 @@ Foam::AMIInterpolation::srcWeights() const } +template +inline Foam::scalarListList& +Foam::AMIInterpolation::srcWeights() +{ + return srcWeights_; +} + + template inline const Foam::scalarField& Foam::AMIInterpolation::srcWeightsSum() const @@ -80,6 +104,14 @@ Foam::AMIInterpolation::srcWeightsSum() const } +template +inline Foam::scalarField& +Foam::AMIInterpolation::srcWeightsSum() +{ + return srcWeightsSum_; +} + + template inline const Foam::mapDistribute& Foam::AMIInterpolation::srcMap() const @@ -96,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 @@ -104,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 @@ -112,6 +160,14 @@ Foam::AMIInterpolation::tgtWeights() const } +template +inline Foam::scalarListList& +Foam::AMIInterpolation::tgtWeights() +{ + return tgtWeights_; +} + + template inline const Foam::scalarField& Foam::AMIInterpolation::tgtWeightsSum() const @@ -120,6 +176,14 @@ Foam::AMIInterpolation::tgtWeightsSum() const } +template +inline Foam::scalarField& +Foam::AMIInterpolation::tgtWeightsSum() +{ + return tgtWeightsSum_; +} + + template inline const Foam::mapDistribute& Foam::AMIInterpolation::tgtMap() const diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/AMIMethod/AMIMethod.H b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIMethod/AMIMethod/AMIMethod.H index 2e9417782d..7d76657fe9 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-2015 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 a0a14f8258..e263dbdfd2 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 d74094d0b5..9159f629ed 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 da5c84ac97..3d89330198 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 2d1b552018..0a7f497407 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-2014 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 0efaf241f4..211a81cdba 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-2015 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 86d8c615f2..0b5eb1657a 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-2014 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 de8afcf0ef..9212258019 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-2014 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM.