BUG: mapNearestAMI: move normalisation to AMIMethod.

Avoids cells shared among processors to be counted multiple times and having
weights > 1.
This commit is contained in:
mattijs
2016-05-11 10:40:51 +01:00
parent 4f50e3030a
commit a2be9acca4
11 changed files with 256 additions and 18 deletions

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -1062,7 +1062,7 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::update
); );
// weights normalisation // weights normalisation
normaliseWeights(AMIPtr->conformal(), true); AMIPtr->normaliseWeights(true, *this);
// cache maps and reset addresses // cache maps and reset addresses
List<Map<label> > cMap; List<Map<label> > cMap;
@ -1095,7 +1095,7 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::update
tgtWeights_ tgtWeights_
); );
normaliseWeights(AMIPtr->conformal(), true); AMIPtr->normaliseWeights(true, *this);
} }
if (debug) if (debug)

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -372,16 +372,29 @@ public:
//- Return const access to source patch face areas //- Return const access to source patch face areas
inline const scalarField& srcMagSf() const; inline const scalarField& srcMagSf() const;
//- Return access to source patch face areas
inline scalarField& srcMagSf();
//- Return const access to source patch addressing //- Return const access to source patch addressing
inline const labelListList& srcAddress() const; inline const labelListList& srcAddress() const;
//- Return access to source patch addressing
inline labelListList& srcAddress();
//- Return const access to source patch weights //- Return const access to source patch weights
inline const scalarListList& srcWeights() const; inline const scalarListList& srcWeights() const;
//- Return access to source patch weights
inline scalarListList& srcWeights();
//- Return const access to normalisation factor of source //- Return const access to normalisation factor of source
// patch weights (i.e. the sum before normalisation) // patch weights (i.e. the sum before normalisation)
inline const scalarField& srcWeightsSum() const; 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 //- Source map pointer - valid only if singlePatchProc = -1
// This gets source data into a form to be consumed by // This gets source data into a form to be consumed by
// tgtAddress, tgtWeights // tgtAddress, tgtWeights
@ -393,16 +406,29 @@ public:
//- Return const access to target patch face areas //- Return const access to target patch face areas
inline const scalarField& tgtMagSf() const; inline const scalarField& tgtMagSf() const;
//- Return access to target patch face areas
inline scalarField& tgtMagSf();
//- Return const access to target patch addressing //- Return const access to target patch addressing
inline const labelListList& tgtAddress() const; inline const labelListList& tgtAddress() const;
//- Return access to target patch addressing
inline labelListList& tgtAddress();
//- Return const access to target patch weights //- Return const access to target patch weights
inline const scalarListList& tgtWeights() const; inline const scalarListList& tgtWeights() const;
//- Return access to target patch weights
inline scalarListList& tgtWeights();
//- Return const access to normalisation factor of target //- Return const access to normalisation factor of target
// patch weights (i.e. the sum before normalisation) // patch weights (i.e. the sum before normalisation)
inline const scalarField& tgtWeightsSum() const; 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. //- Target map pointer - valid only if singlePatchProc=-1.
// This gets target data into a form to be consumed by // This gets target data into a form to be consumed by
// srcAddress, srcWeights // srcAddress, srcWeights

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. 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> template<class SourcePatch, class TargetPatch>
inline const Foam::labelListList& inline const Foam::labelListList&
Foam::AMIInterpolation<SourcePatch, TargetPatch>::srcAddress() const 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> template<class SourcePatch, class TargetPatch>
inline const Foam::scalarListList& inline const Foam::scalarListList&
Foam::AMIInterpolation<SourcePatch, TargetPatch>::srcWeights() const 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> template<class SourcePatch, class TargetPatch>
inline const Foam::scalarField& inline const Foam::scalarField&
Foam::AMIInterpolation<SourcePatch, TargetPatch>::srcWeightsSum() const 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> template<class SourcePatch, class TargetPatch>
inline const Foam::mapDistribute& inline const Foam::mapDistribute&
Foam::AMIInterpolation<SourcePatch, TargetPatch>::srcMap() const 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> template<class SourcePatch, class TargetPatch>
inline const Foam::labelListList& inline const Foam::labelListList&
Foam::AMIInterpolation<SourcePatch, TargetPatch>::tgtAddress() const 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> template<class SourcePatch, class TargetPatch>
inline const Foam::scalarListList& inline const Foam::scalarListList&
Foam::AMIInterpolation<SourcePatch, TargetPatch>::tgtWeights() const 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> template<class SourcePatch, class TargetPatch>
inline const Foam::scalarField& inline const Foam::scalarField&
Foam::AMIInterpolation<SourcePatch, TargetPatch>::tgtWeightsSum() const 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> template<class SourcePatch, class TargetPatch>
inline const Foam::mapDistribute& inline const Foam::mapDistribute&
Foam::AMIInterpolation<SourcePatch, TargetPatch>::tgtMap() const Foam::AMIInterpolation<SourcePatch, TargetPatch>::tgtMap() const

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2013-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2015 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2016 OpcnCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -48,6 +48,8 @@ SourceFiles
namespace Foam namespace Foam
{ {
template<class SourcePatch, class TargetPatch> class AMIInterpolation;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class AMIMethod Declaration Class AMIMethod Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -238,6 +240,14 @@ public:
label srcFaceI = -1, label srcFaceI = -1,
label tgtFaceI = -1 label tgtFaceI = -1
) = 0; ) = 0;
//- Normalise the weight. Can optionally subset addressing
// (e.g. for mapNearest)
virtual void normaliseWeights
(
const bool verbose,
AMIInterpolation<SourcePatch, TargetPatch>& inter
) = 0;
}; };

View File

@ -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);
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -135,6 +135,14 @@ public:
label srcFaceI = -1, label srcFaceI = -1,
label tgtFaceI = -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
);
}; };

View File

@ -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);
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2013-2014 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2014 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -167,6 +167,14 @@ public:
label srcFaceI = -1, label srcFaceI = -1,
label tgtFaceI = -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
);
}; };

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2013-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2015 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -322,19 +322,111 @@ void Foam::mapNearestAMI<SourcePatch, TargetPatch>::calculate
// transfer data to persistent storage // 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[srcI].transfer(srcAddr[srcI]);
srcAddress[i].transfer(srcAddr[i]);
srcWeights[i] = scalarList(1, magSf); const labelList& addr = srcAddress[srcI];
} srcWeights[srcI].setSize(addr.size());
forAll(tgtAddr, i) const point& srcPt = srcFc[srcI];
forAll(addr, i)
{ {
scalar magSf = this->tgtMagSf_[i]; srcWeights[srcI][i] = magSqr(srcPt-tgtFc[addr[i]]);
tgtAddress[i].transfer(tgtAddr[i]);
tgtWeights[i] = scalarList(1, magSf);
} }
} }
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
)
{
{
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);
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2013-2014 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2014 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -139,6 +139,14 @@ public:
label srcFaceI = -1, label srcFaceI = -1,
label tgtFaceI = -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
);
}; };

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2013-2014 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2014 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.