Skip to content
Snippets Groups Projects
Commit bf589e0f authored by andy's avatar andy
Browse files

ENH: Caching octree for AMI target face search

parent 84ad94a4
Branches
Tags
No related merge requests found
......@@ -24,8 +24,6 @@ License
\*---------------------------------------------------------------------------*/
#include "AMIInterpolation.H"
#include "treeDataPrimitivePatch.H"
#include "indexedOctree.H"
#include "meshTools.H"
#include "mergePoints.H"
#include "mapDistribute.H"
......@@ -155,6 +153,36 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::checkPatches
}
template<class SourcePatch, class TargetPatch>
void Foam::AMIInterpolation<SourcePatch, TargetPatch>::resetTree
(
const primitivePatch& tgtPatch
)
{
// Clear the old octree
treePtr_.clear();
treeBoundBox bb(tgtPatch.points());
bb.inflate(0.01);
if (!treePtr_.valid())
{
treePtr_.reset
(
new indexedOctree<treeType>
(
treeType(false, tgtPatch),
bb, // overall search domain
8, // maxLevel
10, // leaf size
3.0 // duplicity
)
);
}
}
template<class SourcePatch, class TargetPatch>
Foam::label Foam::AMIInterpolation<SourcePatch, TargetPatch>::calcDistribution
(
......@@ -644,33 +672,18 @@ template<class SourcePatch, class TargetPatch>
Foam::label Foam::AMIInterpolation<SourcePatch, TargetPatch>::findTargetFace
(
const label srcFaceI,
const primitivePatch& srcPatch,
const primitivePatch& tgtPatch
const primitivePatch& srcPatch
) const
{
label targetFaceI = -1;
treeBoundBox bb(tgtPatch.points());
bb.inflate(0.01);
typedef treeDataPrimitivePatch<face, SubList, const pointField&> treeType;
indexedOctree<treeType> tree
(
treeType(false, tgtPatch),
bb, // overall search domain
8, // maxLevel
10, // leaf size
3.0 // duplicity
);
const pointField& srcPts = srcPatch.points();
const face& srcFace = srcPatch[srcFaceI];
const point& srcPt = srcFace.centre(srcPts);
const scalar srcFaceArea = srcFace.mag(srcPts);
// pointIndexHit sample = tree.findNearest(srcPt, sqr(0.1*bb.mag()));
pointIndexHit sample = tree.findNearest(srcPt, 10.0*srcFaceArea);
// pointIndexHit sample = treePtr_->findNearest(srcPt, sqr(0.1*bb.mag()));
pointIndexHit sample = treePtr_->findNearest(srcPt, 10.0*srcFaceArea);
if (debug)
......@@ -828,7 +841,7 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::setNextFaces
}
srcFaceI = faceI;
tgtFaceI = findTargetFace(srcFaceI, srcPatch0, tgtPatch0);
tgtFaceI = findTargetFace(srcFaceI, srcPatch0);
if (tgtFaceI >= 0)
{
......@@ -932,6 +945,8 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::calcAddressing
return;
}
resetTree(tgtPatch);
// temporary storage for addressing and weights
List<DynamicList<label> > srcAddr(srcPatch.size());
List<DynamicList<scalar> > srcWght(srcPatch.size());
......@@ -948,7 +963,7 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::calcAddressing
bool foundFace = false;
forAll(srcPatch, faceI)
{
tgtFaceI = findTargetFace(faceI, srcPatch, tgtPatch);
tgtFaceI = findTargetFace(faceI, srcPatch);
if (tgtFaceI >= 0)
{
srcFaceI = faceI;
......
......@@ -50,7 +50,8 @@ SourceFiles
#include "boolList.H"
#include "primitivePatch.H"
#include "faceAreaIntersect.H"
#include "treeBoundBox.H"
#include "indexedOctree.H"
#include "treeDataPrimitivePatch.H"
#include "treeBoundBoxList.H"
#include "globalIndex.H"
#include "ops.H"
......@@ -76,6 +77,8 @@ class AMIInterpolation
:
public AMIInterpolationName
{
//- local typedef to octree tree-type
typedef treeDataPrimitivePatch<face, SubList, const pointField&> treeType;
//- Helper class for list
template<class T>
......@@ -135,6 +138,9 @@ class AMIInterpolation
scalarListList tgtWeights_;
//- Octree used to find face seeds
autoPtr<indexedOctree<treeType> > treePtr_;
//- Starting face seed index
label startSeedI_;
......@@ -176,6 +182,10 @@ class AMIInterpolation
const primitivePatch& tgtPatch
);
//- Reset the octree for the traget patch face search
void resetTree(const primitivePatch& tgtPatch);
// Parallel functionality
......@@ -236,8 +246,7 @@ class AMIInterpolation
label findTargetFace
(
const label srcFaceI,
const primitivePatch& srcPatch,
const primitivePatch& tgtPatch
const primitivePatch& srcPatch
) const;
//- Add faces neighbouring faceI to the ID list
......
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