Commit a2be9acc authored by mattijs's avatar mattijs
Browse files

BUG: mapNearestAMI: move normalisation to AMIMethod.

Avoids cells shared among processors to be counted multiple times and having
weights > 1.
parent 4f50e303
......@@ -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<SourcePatch, TargetPatch>::update
);
// weights normalisation
normaliseWeights(AMIPtr->conformal(), true);
AMIPtr->normaliseWeights(true, *this);
// cache maps and reset addresses
List<Map<label> > cMap;
......@@ -1095,7 +1095,7 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::update
tgtWeights_
);
normaliseWeights(AMIPtr->conformal(), true);
AMIPtr->normaliseWeights(true, *this);
}
if (debug)
......
......@@ -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
......
......@@ -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<SourcePatch, TargetPatch>::srcMagSf() const
}
template<class SourcePatch, class TargetPatch>
inline Foam::scalarField&
Foam::AMIInterpolation<SourcePatch, TargetPatch>::srcMagSf()
{
return srcMagSf_;
}
template<class SourcePatch, class TargetPatch>
inline const Foam::labelListList&
Foam::AMIInterpolation<SourcePatch, TargetPatch>::srcAddress() const
......@@ -64,6 +72,14 @@ Foam::AMIInterpolation<SourcePatch, TargetPatch>::srcAddress() const
}
template<class SourcePatch, class TargetPatch>
inline Foam::labelListList&
Foam::AMIInterpolation<SourcePatch, TargetPatch>::srcAddress()
{
return srcAddress_;
}
template<class SourcePatch, class TargetPatch>
inline const Foam::scalarListList&
Foam::AMIInterpolation<SourcePatch, TargetPatch>::srcWeights() const
......@@ -72,6 +88,14 @@ Foam::AMIInterpolation<SourcePatch, TargetPatch>::srcWeights() const
}
template<class SourcePatch, class TargetPatch>
inline Foam::scalarListList&
Foam::AMIInterpolation<SourcePatch, TargetPatch>::srcWeights()
{
return srcWeights_;
}
template<class SourcePatch, class TargetPatch>
inline const Foam::scalarField&
Foam::AMIInterpolation<SourcePatch, TargetPatch>::srcWeightsSum() const
......@@ -80,6 +104,14 @@ Foam::AMIInterpolation<SourcePatch, TargetPatch>::srcWeightsSum() const
}
template<class SourcePatch, class TargetPatch>
inline Foam::scalarField&
Foam::AMIInterpolation<SourcePatch, TargetPatch>::srcWeightsSum()
{
return srcWeightsSum_;
}
template<class SourcePatch, class TargetPatch>
inline const Foam::mapDistribute&
Foam::AMIInterpolation<SourcePatch, TargetPatch>::srcMap() const
......@@ -96,6 +128,14 @@ Foam::AMIInterpolation<SourcePatch, TargetPatch>::tgtMagSf() const
}
template<class SourcePatch, class TargetPatch>
inline Foam::scalarField&
Foam::AMIInterpolation<SourcePatch, TargetPatch>::tgtMagSf()
{
return tgtMagSf_;
}
template<class SourcePatch, class TargetPatch>
inline const Foam::labelListList&
Foam::AMIInterpolation<SourcePatch, TargetPatch>::tgtAddress() const
......@@ -104,6 +144,14 @@ Foam::AMIInterpolation<SourcePatch, TargetPatch>::tgtAddress() const
}
template<class SourcePatch, class TargetPatch>
inline Foam::labelListList&
Foam::AMIInterpolation<SourcePatch, TargetPatch>::tgtAddress()
{
return tgtAddress_;
}
template<class SourcePatch, class TargetPatch>
inline const Foam::scalarListList&
Foam::AMIInterpolation<SourcePatch, TargetPatch>::tgtWeights() const
......@@ -112,6 +160,14 @@ Foam::AMIInterpolation<SourcePatch, TargetPatch>::tgtWeights() const
}
template<class SourcePatch, class TargetPatch>
inline Foam::scalarListList&
Foam::AMIInterpolation<SourcePatch, TargetPatch>::tgtWeights()
{
return tgtWeights_;
}
template<class SourcePatch, class TargetPatch>
inline const Foam::scalarField&
Foam::AMIInterpolation<SourcePatch, TargetPatch>::tgtWeightsSum() const
......@@ -120,6 +176,14 @@ Foam::AMIInterpolation<SourcePatch, TargetPatch>::tgtWeightsSum() const
}
template<class SourcePatch, class TargetPatch>
inline Foam::scalarField&
Foam::AMIInterpolation<SourcePatch, TargetPatch>::tgtWeightsSum()
{
return tgtWeightsSum_;
}
template<class SourcePatch, class TargetPatch>
inline const Foam::mapDistribute&
Foam::AMIInterpolation<SourcePatch, TargetPatch>::tgtMap() const
......
......@@ -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 SourcePatch, class TargetPatch> 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<SourcePatch, TargetPatch>& inter
) = 0;
};
......
......@@ -322,4 +322,15 @@ void Foam::directAMI<SourcePatch, TargetPatch>::calculate
}
template<class SourcePatch, class TargetPatch>
void Foam::directAMI<SourcePatch, TargetPatch>::normaliseWeights
(
const bool verbose,
AMIInterpolation<SourcePatch, TargetPatch>& inter
)
{
inter.normaliseWeights(this->conformal(), verbose);
}
// ************************************************************************* //
......@@ -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<SourcePatch, TargetPatch>& inter
);
};
......
......@@ -568,4 +568,15 @@ void Foam::faceAreaWeightAMI<SourcePatch, TargetPatch>::calculate
}
template<class SourcePatch, class TargetPatch>
void Foam::faceAreaWeightAMI<SourcePatch, TargetPatch>::normaliseWeights
(
const bool verbose,
AMIInterpolation<SourcePatch, TargetPatch>& inter
)
{
inter.normaliseWeights(this->conformal(), verbose);
}
// ************************************************************************* //
......@@ -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<SourcePatch, TargetPatch>& inter
);
};
......
......@@ -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,18 +322,110 @@ void Foam::mapNearestAMI<SourcePatch, TargetPatch>::calculate
// transfer data to persistent storage
forAll(srcAddr, i)
const pointField& srcFc = this->srcPatch_.faceCentres();
const pointField& tgtFc = this->tgtPatch_.faceCentres();
forAll(srcAddr, srcI)
{
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, tgtI)
{
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<class SourcePatch, class TargetPatch>
void Foam::mapNearestAMI<SourcePatch, TargetPatch>::normaliseWeights
(
const bool verbose,
AMIInterpolation<SourcePatch, TargetPatch>& inter
)
{
{
scalar magSf = this->srcMagSf_[i];
srcAddress[i].transfer(srcAddr[i]);
srcWeights[i] = scalarList(1, magSf);
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;
}
}
}
forAll(tgtAddr, i)
{
scalar magSf = this->tgtMagSf_[i];
tgtAddress[i].transfer(tgtAddr[i]);
tgtWeights[i] = scalarList(1, magSf);
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);
}
......
......@@ -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<SourcePatch, TargetPatch>& inter
);
};
......
......@@ -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.
......
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