BUG: mapNearest: candidate selection

This commit is contained in:
mattijs
2014-10-31 16:41:00 +00:00
committed by Andrew Heather
parent 5cdaf0fdab
commit 7816177cba
2 changed files with 47 additions and 41 deletions

View File

@ -48,9 +48,7 @@ bool Foam::mapNearestMethod::findInitialSeeds
label& tgtSeedI label& tgtSeedI
) const ) const
{ {
const cellList& srcCells = src_.cells(); const vectorField& srcCcs = src_.cellCentres();
const faceList& srcFaces = src_.faces();
const pointField& srcPts = src_.points();
for (label i = startSeedI; i < srcCellIDs.size(); i++) for (label i = startSeedI; i < srcCellIDs.size(); i++)
{ {
@ -58,11 +56,9 @@ bool Foam::mapNearestMethod::findInitialSeeds
if (mapFlag[srcI]) if (mapFlag[srcI])
{ {
const pointField const point& srcCc = srcCcs[srcI];
pts(srcCells[srcI].points(srcFaces, srcPts).xfer()); pointIndexHit hit =
tgt_.cellTree().findNearest(srcCc, GREAT);
const point& pt = pts[0];
pointIndexHit hit = tgt_.cellTree().findNearest(pt, GREAT);
if (hit.hit()) if (hit.hit())
{ {
@ -86,8 +82,7 @@ bool Foam::mapNearestMethod::findInitialSeeds
) )
<< "Unable to find nearest target cell" << "Unable to find nearest target cell"
<< " for source cell " << srcI << " for source cell " << srcI
<< " with centre " << " with centre " << srcCc
<< srcCells[srcI].centre(srcPts, srcFaces)
<< abort(FatalError); << abort(FatalError);
} }
@ -123,36 +118,37 @@ void Foam::mapNearestMethod::calculateAddressing
const scalarField& srcVc = src_.cellVolumes(); const scalarField& srcVc = src_.cellVolumes();
const scalarField& tgtVc = tgt_.cellVolumes(); const scalarField& tgtVc = tgt_.cellVolumes();
label srcCellI = srcSeedI;
label tgtCellI = tgtSeedI;
do
{ {
// find nearest tgt cell label srcCellI = srcSeedI;
findNearestCell(src_, tgt_, srcCellI, tgtCellI); label tgtCellI = tgtSeedI;
// store src/tgt cell pair do
srcToTgt[srcCellI].append(tgtCellI); {
tgtToSrc[tgtCellI].append(srcCellI); // find nearest tgt cell
findNearestCell(src_, tgt_, srcCellI, tgtCellI);
// mark source cell srcCellI and tgtCellI as matched // store src/tgt cell pair
mapFlag[srcCellI] = false; srcToTgt[srcCellI].append(tgtCellI);
tgtToSrc[tgtCellI].append(srcCellI);
// accumulate intersection volume // mark source cell srcCellI and tgtCellI as matched
V_ += srcVc[srcCellI]; mapFlag[srcCellI] = false;
// find new source cell // accumulate intersection volume
setNextNearestCells V_ += srcVc[srcCellI];
(
startSeedI, // find new source cell
srcCellI, setNextNearestCells
tgtCellI, (
mapFlag, startSeedI,
srcCellIDs srcCellI,
); tgtCellI,
mapFlag,
srcCellIDs
);
}
while (srcCellI >= 0);
} }
while (srcCellI >= 0);
// for the case of multiple source cells per target cell, select the // for the case of multiple source cells per target cell, select the
// nearest source cell only and discard the others // nearest source cell only and discard the others
@ -163,7 +159,7 @@ void Foam::mapNearestMethod::calculateAddressing
{ {
if (tgtToSrc[targetCellI].size() > 1) if (tgtToSrc[targetCellI].size() > 1)
{ {
const vector& tgtC = tgtCc[tgtCellI]; const vector& tgtC = tgtCc[targetCellI];
DynamicList<label>& srcCells = tgtToSrc[targetCellI]; DynamicList<label>& srcCells = tgtToSrc[targetCellI];
@ -203,16 +199,14 @@ void Foam::mapNearestMethod::calculateAddressing
// transfer addressing into persistent storage // transfer addressing into persistent storage
forAll(srcToTgtCellAddr, i) forAll(srcToTgtCellAddr, i)
{ {
scalar v = srcVc[i]; srcToTgtCellWght[i] = scalarList(srcToTgt[i].size(), srcVc[i]);
srcToTgtCellAddr[i].transfer(srcToTgt[i]); srcToTgtCellAddr[i].transfer(srcToTgt[i]);
srcToTgtCellWght[i] = scalarList(1, v);
} }
forAll(tgtToSrcCellAddr, i) forAll(tgtToSrcCellAddr, i)
{ {
scalar v = tgtVc[i]; tgtToSrcCellWght[i] = scalarList(tgtToSrc[i].size(), tgtVc[i]);
tgtToSrcCellAddr[i].transfer(tgtToSrc[i]); tgtToSrcCellAddr[i].transfer(tgtToSrc[i]);
tgtToSrcCellWght[i] = scalarList(1, v);
} }
} }
@ -272,12 +266,20 @@ void Foam::mapNearestMethod::setNextNearestCells
if (mapFlag[cellI]) if (mapFlag[cellI])
{ {
srcCellI = cellI; srcCellI = cellI;
startSeedI = cellI + 1;
return; return;
} }
} }
for (label i = startSeedI; i < srcCellIDs.size(); i++)
{
label cellI = srcCellIDs[i];
if (mapFlag[cellI])
{
startSeedI = i;
break;
}
}
(void)findInitialSeeds (void)findInitialSeeds
( (
srcCellIDs, srcCellIDs,

View File

@ -28,6 +28,10 @@ Description
Map nearest mesh-to-mesh interpolation class Map nearest mesh-to-mesh interpolation class
Not volume conservative. 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 SourceFiles
mapNearestMethod.C mapNearestMethod.C