Commit d016590b authored by Andrew Heather's avatar Andrew Heather
Browse files

ENH: AMIInterpolation - updated to perform face triangulation once only; code clean-up

parent 2be17edc
......@@ -233,10 +233,10 @@ int main(int argc, char *argv[])
meshToMesh::interpolationMethod method =
meshToMesh::interpolationMethodNames_[mapMethod];
patchMapMethod = AMIPatchToPatchInterpolation::interpolationMethodToWord
(
patchMapMethod = AMIPatchToPatchInterpolation::interpolationMethodNames_
[
meshToMesh::interpolationMethodAMI(method)
);
];
}
// Optionally override
......
......@@ -89,10 +89,10 @@ void Foam::functionObjects::mapFields::createInterpolation
// Lookup corresponding AMI method
word patchMapMethodName =
AMIPatchToPatchInterpolation::interpolationMethodToWord
(
AMIPatchToPatchInterpolation::interpolationMethodNames_
[
meshToMesh::interpolationMethodAMI(mapMethod)
);
];
// Optionally override
if (dict.readIfPresent("patchMapMethod", patchMapMethodName))
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -46,26 +46,8 @@ Foam::AMIInterpolation<SourcePatch, TargetPatch>::interpolationMethodNames_
};
template<class SourcePatch, class TargetPatch>
Foam::word
Foam::AMIInterpolation<SourcePatch, TargetPatch>::interpolationMethodToWord
(
const interpolationMethod& im
)
{
return interpolationMethodNames_[im];
}
template<class SourcePatch, class TargetPatch>
typename Foam::AMIInterpolation<SourcePatch, TargetPatch>::interpolationMethod
Foam::AMIInterpolation<SourcePatch, TargetPatch>::wordTointerpolationMethod
(
const word& im
)
{
return interpolationMethodNames_[im];
}
bool Foam::AMIInterpolation<SourcePatch, TargetPatch>::cacheIntersections_ =
false;
template<class SourcePatch, class TargetPatch>
template<class Patch>
......@@ -156,7 +138,7 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::projectPointsToSurface
template<class SourcePatch, class TargetPatch>
void Foam::AMIInterpolation<SourcePatch, TargetPatch>::normaliseWeights
(
const scalarField& patchAreas,
const scalarList& patchAreas,
const word& patchName,
const labelListList& addr,
scalarListList& wght,
......@@ -237,14 +219,14 @@ template<class SourcePatch, class TargetPatch>
void Foam::AMIInterpolation<SourcePatch, TargetPatch>::agglomerate
(
const autoPtr<mapDistribute>& targetMapPtr,
const scalarField& fineSrcMagSf,
const scalarList& fineSrcMagSf,
const labelListList& fineSrcAddress,
const scalarListList& fineSrcWeights,
const labelList& sourceRestrictAddressing,
const labelList& targetRestrictAddressing,
scalarField& srcMagSf,
scalarList& srcMagSf,
labelListList& srcAddress,
scalarListList& srcWeights,
scalarField& srcWeightsSum,
......@@ -339,9 +321,9 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::agglomerate
labelList oldToNew(targetCoarseSize, -1);
label newi = 0;
forAll(elems, i)
for (const label elemi : elems)
{
label fineElem = elemsMap[elems[i]];
label fineElem = elemsMap[elemi];
label coarseElem = allRestrict[fineElem];
if (oldToNew[coarseElem] == -1)
{
......@@ -375,9 +357,8 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::agglomerate
// reachable elements (using the local constructMap)
const labelList& elemsMap = map.constructMap()[Pstream::myProcNo()];
forAll(elemsMap, i)
for (const label fineElem : elemsMap)
{
label fineElem = elemsMap[i];
label coarseElem = allRestrict[fineElem];
tgtCompactMap[fineElem] = coarseElem;
}
......@@ -403,12 +384,12 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::agglomerate
// Get the maximum target coarse size for this set of
// received data.
label remoteTargetCoarseSize = labelMin;
forAll(elems, i)
for (const label elemi : elems)
{
remoteTargetCoarseSize = max
(
remoteTargetCoarseSize,
allRestrict[elems[i]]
allRestrict[elemi]
);
}
remoteTargetCoarseSize += 1;
......@@ -417,9 +398,8 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::agglomerate
labelList oldToNew(remoteTargetCoarseSize, -1);
label newi = 0;
forAll(elems, i)
for (const label fineElem : elems)
{
label fineElem = elems[i];
// fineElem now points to section from proci
label coarseElem = allRestrict[fineElem];
if (oldToNew[coarseElem] == -1)
......@@ -563,9 +543,9 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::constructFromSurface
if (debug)
{
OFstream os("amiSrcPoints.obj");
forAll(srcPoints, i)
for (const point& pt : srcPoints)
{
meshTools::writeOBJ(os, srcPoints[i]);
meshTools::writeOBJ(os, pt);
}
}
......@@ -584,9 +564,9 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::constructFromSurface
if (debug)
{
OFstream os("amiTgtPoints.obj");
forAll(tgtPoints, i)
for (const point& pt : tgtPoints)
{
meshTools::writeOBJ(os, tgtPoints[i]);
meshTools::writeOBJ(os, pt);
}
}
......@@ -620,7 +600,7 @@ Foam::AMIInterpolation<SourcePatch, TargetPatch>::AMIInterpolation
const bool reverseTarget
)
:
methodName_(interpolationMethodToWord(method)),
methodName_(interpolationMethodNames_[method]),
reverseTarget_(reverseTarget),
requireMatch_(requireMatch),
singlePatchProc_(-999),
......@@ -683,7 +663,7 @@ Foam::AMIInterpolation<SourcePatch, TargetPatch>::AMIInterpolation
const bool reverseTarget
)
:
methodName_(interpolationMethodToWord(method)),
methodName_(interpolationMethodNames_[method]),
reverseTarget_(reverseTarget),
requireMatch_(requireMatch),
singlePatchProc_(-999),
......@@ -870,10 +850,6 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::update
<< tgtTotalSize << " target faces"
<< endl;
// Calculate face areas
srcMagSf_ = patchMagSf(srcPatch, triMode_);
tgtMagSf_ = patchMagSf(tgtPatch, triMode_);
// Calculate if patches present on multiple processors
singlePatchProc_ = calcDistribution(srcPatch, tgtPatch);
......@@ -919,13 +895,6 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::update
newTgtPoints
);
scalarField newTgtMagSf(newTgtPatch.size());
forAll(newTgtPatch, facei)
{
newTgtMagSf[facei] = newTgtPatch[facei].mag(newTgtPatch.points());
}
// Calculate AMI interpolation
autoPtr<AMIMethod<SourcePatch, TargetPatch>> AMIPtr
(
......@@ -934,8 +903,6 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::update
methodName_,
srcPatch,
newTgtPatch,
srcMagSf_,
newTgtMagSf,
triMode_,
reverseTarget_,
requireMatch_ && (lowWeightCorrection_ < 0)
......@@ -950,6 +917,12 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::update
tgtWeights_
);
// Note: using patch face areas calculated by the AMI method
// - TODO: should move into the calculate method
srcMagSf_.transfer(AMIPtr->srcMagSf());
tgtMagSf_.transfer(AMIPtr->tgtMagSf());
map.reverseDistribute(tgtPatch.size(), tgtMagSf_);
// Now
// ~~~
// srcAddress_ : per srcPatch face a list of the newTgtPatch (not
......@@ -967,21 +940,19 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::update
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
forAll(srcAddress_, i)
for (labelList& addressing : srcAddress_)
{
labelList& addressing = srcAddress_[i];
forAll(addressing, addri)
for (label& addr : addressing)
{
addressing[addri] = tgtFaceIDs[addressing[addri]];
addr = tgtFaceIDs[addr];
}
}
forAll(tgtAddress_, i)
for (labelList& addressing : tgtAddress_)
{
labelList& addressing = tgtAddress_[i];
forAll(addressing, addri)
for (label& addr : addressing)
{
addressing[addri] = globalSrcFaces.toGlobal(addressing[addri]);
addr = globalSrcFaces.toGlobal(addr);
}
}
......@@ -1036,8 +1007,6 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::update
methodName_,
srcPatch,
tgtPatch,
srcMagSf_,
tgtMagSf_,
triMode_,
reverseTarget_,
requireMatch_ && (lowWeightCorrection_ < 0)
......@@ -1052,6 +1021,9 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::update
tgtWeights_
);
srcMagSf_.transfer(AMIPtr->srcMagSf());
tgtMagSf_.transfer(AMIPtr->tgtMagSf());
AMIPtr->normaliseWeights(true, *this);
}
......@@ -1623,9 +1595,8 @@ const
nearest.setDistance(GREAT);
label nearestFacei = -1;
forAll(addr, i)
for (const label srcFacei : addr)
{
const label srcFacei = addr[i];
const face& f = srcPatch[srcFacei];
pointHit ray = f.ray(tgtPoint, n, srcPoints);
......@@ -1672,9 +1643,8 @@ const
// Target face addresses that intersect source face srcFacei
const labelList& addr = srcAddress_[srcFacei];
forAll(addr, i)
for (const label tgtFacei : addr)
{
const label tgtFacei = addr[i];
const face& f = tgtPatch[tgtFacei];
pointHit ray = f.ray(srcPoint, n, tgtPoints);
......@@ -1719,9 +1689,8 @@ const
const labelList& addr = srcAddress[i];
const point& srcPt = srcPatch.faceCentres()[i];
forAll(addr, j)
for (const label tgtPti : addr)
{
label tgtPti = addr[j];
const point& tgtPt = tgtPatch.faceCentres()[tgtPti];
meshTools::writeOBJ(os, srcPt);
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -95,17 +95,7 @@ public:
static const Enum<interpolationMethod> interpolationMethodNames_;
//- Convert interpolationMethod to word representation
static word interpolationMethodToWord
(
const interpolationMethod& method
);
//- Convert word to interpolationMethod
static interpolationMethod wordTointerpolationMethod
(
const word& method
);
static bool cacheIntersections_;
//- Calculate the patch face magnitudes for the given tri-mode
template<class Patch>
......@@ -142,7 +132,7 @@ private:
// Source patch
//- Source face areas
scalarField srcMagSf_;
scalarList srcMagSf_;
//- Addresses of target faces per source face
labelListList srcAddress_;
......@@ -157,7 +147,7 @@ private:
// Target patch
//- Target face areas
scalarField tgtMagSf_;
scalarList tgtMagSf_;
//- Addresses of source faces per target face
labelListList tgtAddress_;
......@@ -250,7 +240,7 @@ private:
// numerical error!
static void normaliseWeights
(
const scalarField& patchAreas,
const scalarList& patchAreas,
const word& patchName,
const labelListList& addr,
scalarListList& wght,
......@@ -266,14 +256,14 @@ private:
static void agglomerate
(
const autoPtr<mapDistribute>& targetMap,
const scalarField& fineSrcMagSf,
const scalarList& fineSrcMagSf,
const labelListList& fineSrcAddress,
const scalarListList& fineSrcWeights,
const labelList& sourceRestrictAddressing,
const labelList& targetRestrictAddressing,
scalarField& srcMagSf,
scalarList& srcMagSf,
labelListList& srcAddress,
scalarListList& srcWeights,
scalarField& srcWeightsSum,
......@@ -311,7 +301,7 @@ public:
const faceAreaIntersect::triangulationMode& triMode,
const bool requireMatch = true,
const word& methodName =
interpolationMethodToWord(imFaceAreaWeight),
interpolationMethodNames_[imFaceAreaWeight],
const scalar lowWeightCorrection = -1,
const bool reverseTarget = false
);
......@@ -338,7 +328,7 @@ public:
const faceAreaIntersect::triangulationMode& triMode,
const bool requireMatch = true,
const word& methodName =
interpolationMethodToWord(imFaceAreaWeight),
interpolationMethodNames_[imFaceAreaWeight],
const scalar lowWeightCorrection = -1,
const bool reverseTarget = false
);
......@@ -381,10 +371,10 @@ public:
// Source patch
//- Return const access to source patch face areas
inline const scalarField& srcMagSf() const;
inline const List<scalar>& srcMagSf() const;
//- Return access to source patch face areas
inline scalarField& srcMagSf();
inline List<scalar>& srcMagSf();
//- Return const access to source patch addressing
inline const labelListList& srcAddress() const;
......@@ -415,10 +405,10 @@ public:
// Target patch
//- Return const access to target patch face areas
inline const scalarField& tgtMagSf() const;
inline const List<scalar>& tgtMagSf() const;
//- Return access to target patch face areas
inline scalarField& tgtMagSf();
inline List<scalar>& tgtMagSf();
//- Return const access to target patch addressing
inline const labelListList& tgtAddress() const;
......
......@@ -49,7 +49,7 @@ applyLowWeightCorrection() const
template<class SourcePatch, class TargetPatch>
inline const Foam::scalarField&
inline const Foam::List<Foam::scalar>&
Foam::AMIInterpolation<SourcePatch, TargetPatch>::srcMagSf() const
{
return srcMagSf_;
......@@ -57,7 +57,7 @@ Foam::AMIInterpolation<SourcePatch, TargetPatch>::srcMagSf() const
template<class SourcePatch, class TargetPatch>
inline Foam::scalarField&
inline Foam::List<Foam::scalar>&
Foam::AMIInterpolation<SourcePatch, TargetPatch>::srcMagSf()
{
return srcMagSf_;
......@@ -121,7 +121,7 @@ Foam::AMIInterpolation<SourcePatch, TargetPatch>::srcMap() const
template<class SourcePatch, class TargetPatch>
inline const Foam::scalarField&
inline const Foam::List<Foam::scalar>&
Foam::AMIInterpolation<SourcePatch, TargetPatch>::tgtMagSf() const
{
return tgtMagSf_;
......@@ -129,7 +129,7 @@ Foam::AMIInterpolation<SourcePatch, TargetPatch>::tgtMagSf() const
template<class SourcePatch, class TargetPatch>
inline Foam::scalarField&
inline Foam::List<Foam::scalar>&
Foam::AMIInterpolation<SourcePatch, TargetPatch>::tgtMagSf()
{
return tgtMagSf_;
......
......@@ -100,9 +100,9 @@ Foam::AMIInterpolation<SourcePatch, TargetPatch>::calcOverlappingProcs
{
const treeBoundBoxList& bbp = procBb[proci];
forAll(bbp, bbi)
for (const treeBoundBox& tbb: bbp)
{
if (bbp[bbi].overlaps(bb))
if (tbb.overlaps(bb))
{
overlaps[proci] = true;
nOverlaps++;
......@@ -128,7 +128,7 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::distributePatches
{
PstreamBuffers pBufs(Pstream::commsTypes::nonBlocking);
for (label domain = 0; domain < Pstream::nProcs(); domain++)
for (label domain = 0; domain < Pstream::nProcs(); ++domain)
{
const labelList& sendElems = map.subMap()[domain];
......@@ -195,7 +195,7 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::distributePatches
}
// Consume
for (label domain = 0; domain < Pstream::nProcs(); domain++)
for (label domain = 0; domain < Pstream::nProcs(); ++domain)
{
const labelList& recvElems = map.constructMap()[domain];
......@@ -251,9 +251,8 @@ distributeAndMergePatches
SubList<label>(tgtFaceIDs, faceIDs.size()) = faceIDs;
const faceList& fcs = allFaces[Pstream::myProcNo()];
forAll(fcs, i)
for (const face& f : fcs)
{
const face& f = fcs[i];
face& newF = tgtFaces[nFaces++];
newF.setSize(f.size());
forAll(f, fp)
......@@ -263,9 +262,9 @@ distributeAndMergePatches
}
const pointField& pts = allPoints[Pstream::myProcNo()];
forAll(pts, i)
for (const point& pt: pts)
{
tgtPoints[nPoints++] = pts[i];
tgtPoints[nPoints++] = pt;
}
}
......@@ -279,9 +278,8 @@ distributeAndMergePatches
SubList<label>(tgtFaceIDs, faceIDs.size(), nFaces) = faceIDs;
const faceList& fcs = allFaces[proci];
forAll(fcs, i)
for (const face& f : fcs)
{
const face& f = fcs[i];
face& newF = tgtFaces[nFaces++];
newF.setSize(f.size());
forAll(f, fp)
......@@ -291,9 +289,9 @@ distributeAndMergePatches
}
const pointField& pts = allPoints[proci];
forAll(pts, i)
for (const point& pt: pts)
{
tgtPoints[nPoints++] = pts[i];
tgtPoints[nPoints++] = pt;
}
}
}
......@@ -319,9 +317,9 @@ distributeAndMergePatches
}
tgtPoints.transfer(newTgtPoints);
forAll(tgtFaces, i)
for (face& f : tgtFaces)
{
inplaceRenumber(oldToNew, tgtFaces[i]);
inplaceRenumber(oldToNew, f);
}
}
}
......@@ -447,7 +445,7 @@ Foam::AMIInterpolation<SourcePatch, TargetPatch>::calcProcMap
label nRecv = sendSizes[proci][Pstream::myProcNo()];
constructMap[proci].setSize(nRecv);
for (label i = 0; i < nRecv; i++)
for (label i = 0; i < nRecv; ++i)
{
constructMap[proci][i] = segmentI++;
}
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -167,9 +167,9 @@ void Foam::AMIMethod<SourcePatch, TargetPatch>::writeIntersectionOBJ
OFstream os("areas" + name(count) + ".obj");
forAll(f1pts, i)
for (const point& pt : f1pts)
{
meshTools::writeOBJ(os, f1pts[i]);
meshTools::writeOBJ(os, pt);
}
os<< "l";
forAll(f1pts, i)
......@@ -178,19 +178,19 @@ void Foam::AMIMethod<SourcePatch, TargetPatch>::writeIntersectionOBJ
}
os<< " 1" << endl;
forAll(f2pts, i)
for (const point& pt : f2pts)
{
meshTools::writeOBJ(os, f2pts[i]);
meshTools::writeOBJ(os, pt);
}
os<< "l";
const label n = f1pts.size();
forAll(f2pts, i)
{
os<< " " << f1pts.size() + i + 1;
os<< " " << n + i + 1;
}
os<< " " << f1pts.size() + 1 << endl;
os<< " " << n + 1 << endl;
count++;
++count;
}