diff --git a/src/sampling/meshToMeshInterpolation/meshToMeshNew/calcMapNearest.C b/src/sampling/meshToMeshInterpolation/meshToMeshNew/calcMapNearest.C index 110979532f..0276ee5604 100644 --- a/src/sampling/meshToMeshInterpolation/meshToMeshNew/calcMapNearest.C +++ b/src/sampling/meshToMeshInterpolation/meshToMeshNew/calcMapNearest.C @@ -48,8 +48,6 @@ void Foam::meshToMeshNew::calcMapNearest label srcCellI = srcSeedI; label tgtCellI = tgtSeedI; - boolList tgtMapFlag(tgt.nCells(), true); - do { // find nearest tgt cell @@ -61,7 +59,6 @@ void Foam::meshToMeshNew::calcMapNearest // mark source cell srcCellI and tgtCellI as matched mapFlag[srcCellI] = false; - tgtMapFlag[tgtCellI] = false; // accumulate intersection volume V_ += srcVc[srcCellI]; @@ -80,11 +77,44 @@ void Foam::meshToMeshNew::calcMapNearest } while (srcCellI >= 0); - // If there are more target cells than source cells, some target cells - // will not yet be mapped - forAll(tgtMapFlag, tgtCellI) + + // for the case of multiple source cells per target cell, select the + // nearest source cell only and discard the others + const vectorField& srcCc = src.cellCentres(); + const vectorField& tgtCc = tgt.cellCentres(); + + forAll(tgtToSrc, targetCellI) { - if (tgtMapFlag[tgtCellI]) + if (tgtToSrc[targetCellI].size() > 1) + { + const vector& tgtC = tgtCc[tgtCellI]; + + DynamicList