Skip to content

Commit

Permalink
BUG: mapNearest: candidate selection
Browse files Browse the repository at this point in the history
  • Loading branch information
mattijs committed Oct 31, 2014
1 parent e9c5082 commit 6a4d8bb
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,17 @@ bool Foam::mapNearestMethod::findInitialSeeds
label& tgtSeedI
) const
{
const cellList& srcCells = src_.cells();
const faceList& srcFaces = src_.faces();
const pointField& srcPts = src_.points();
const vectorField& srcCcs = src_.cellCentres();

for (label i = startSeedI; i < srcCellIDs.size(); i++)
{
label srcI = srcCellIDs[i];

if (mapFlag[srcI])
{
const pointField
pts(srcCells[srcI].points(srcFaces, srcPts).xfer());

const point& pt = pts[0];
pointIndexHit hit = tgt_.cellTree().findNearest(pt, GREAT);
const point& srcCc = srcCcs[srcI];
pointIndexHit hit =
tgt_.cellTree().findNearest(srcCc, GREAT);

if (hit.hit())
{
Expand All @@ -86,8 +82,7 @@ bool Foam::mapNearestMethod::findInitialSeeds
)
<< "Unable to find nearest target cell"
<< " for source cell " << srcI
<< " with centre "
<< srcCells[srcI].centre(srcPts, srcFaces)
<< " with centre " << srcCc
<< abort(FatalError);
}

Expand Down Expand Up @@ -123,36 +118,37 @@ void Foam::mapNearestMethod::calculateAddressing
const scalarField& srcVc = src_.cellVolumes();
const scalarField& tgtVc = tgt_.cellVolumes();

label srcCellI = srcSeedI;
label tgtCellI = tgtSeedI;

do
{
// find nearest tgt cell
findNearestCell(src_, tgt_, srcCellI, tgtCellI);
label srcCellI = srcSeedI;
label tgtCellI = tgtSeedI;

// store src/tgt cell pair
srcToTgt[srcCellI].append(tgtCellI);
tgtToSrc[tgtCellI].append(srcCellI);

// mark source cell srcCellI and tgtCellI as matched
mapFlag[srcCellI] = false;
do
{
// find nearest tgt cell
findNearestCell(src_, tgt_, srcCellI, tgtCellI);

// accumulate intersection volume
V_ += srcVc[srcCellI];
// store src/tgt cell pair
srcToTgt[srcCellI].append(tgtCellI);
tgtToSrc[tgtCellI].append(srcCellI);

// find new source cell
setNextNearestCells
(
startSeedI,
srcCellI,
tgtCellI,
mapFlag,
srcCellIDs
);
// mark source cell srcCellI and tgtCellI as matched
mapFlag[srcCellI] = false;

// accumulate intersection volume
V_ += srcVc[srcCellI];

// find new source cell
setNextNearestCells
(
startSeedI,
srcCellI,
tgtCellI,
mapFlag,
srcCellIDs
);
}
while (srcCellI >= 0);
}
while (srcCellI >= 0);


// for the case of multiple source cells per target cell, select the
// nearest source cell only and discard the others
Expand All @@ -163,7 +159,7 @@ void Foam::mapNearestMethod::calculateAddressing
{
if (tgtToSrc[targetCellI].size() > 1)
{
const vector& tgtC = tgtCc[tgtCellI];
const vector& tgtC = tgtCc[targetCellI];

DynamicList<label>& srcCells = tgtToSrc[targetCellI];

Expand Down Expand Up @@ -203,16 +199,14 @@ void Foam::mapNearestMethod::calculateAddressing
// transfer addressing into persistent storage
forAll(srcToTgtCellAddr, i)
{
scalar v = srcVc[i];
srcToTgtCellWght[i] = scalarList(srcToTgt[i].size(), srcVc[i]);
srcToTgtCellAddr[i].transfer(srcToTgt[i]);
srcToTgtCellWght[i] = scalarList(1, v);
}

forAll(tgtToSrcCellAddr, i)
{
scalar v = tgtVc[i];
tgtToSrcCellWght[i] = scalarList(tgtToSrc[i].size(), tgtVc[i]);
tgtToSrcCellAddr[i].transfer(tgtToSrc[i]);
tgtToSrcCellWght[i] = scalarList(1, v);
}
}

Expand Down Expand Up @@ -272,12 +266,20 @@ void Foam::mapNearestMethod::setNextNearestCells
if (mapFlag[cellI])
{
srcCellI = cellI;
startSeedI = cellI + 1;

return;
}
}

for (label i = startSeedI; i < srcCellIDs.size(); i++)
{
label cellI = srcCellIDs[i];
if (mapFlag[cellI])
{
startSeedI = i;
break;
}
}

(void)findInitialSeeds
(
srcCellIDs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ Description
Map nearest mesh-to-mesh interpolation class
Not volume conservative.
- cells outside other meshes bounding box do not get mapped
(initial filtering)
- all remaining cells will be mapped (with weight 1!)
- so take care when mapping meshes with different bounding boxes!
SourceFiles
mapNearestMethod.C
Expand Down

0 comments on commit 6a4d8bb

Please sign in to comment.