AMIInterpolation: Make tracking across AMI more robust

If a suitable face an the receiving side of the AMI cannot be found the
particle is marked for deletion.
This commit is contained in:
Henry Weller
2016-08-16 11:33:27 +01:00
parent bc71a7d208
commit e44cc9697b

View File

@ -302,8 +302,8 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::agglomerate
// So now we have agglomeration of the target side in // So now we have agglomeration of the target side in
// allRestrict: // allRestrict:
// 0..size-1 : local agglomeration (= targetRestrictAddressing) // 0..size-1 : local agglomeration (= targetRestrictAddressing)
// size.. : agglomeration data from other processors // size.. : agglomeration data from other processors
labelListList tgtSubMap(Pstream::nProcs()); labelListList tgtSubMap(Pstream::nProcs());
@ -497,7 +497,7 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::agglomerate
} }
} }
// weights normalisation // Weights normalisation
normaliseWeights normaliseWeights
( (
srcMagSf, srcMagSf,
@ -522,7 +522,7 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::constructFromSurface
{ {
if (surfPtr.valid()) if (surfPtr.valid())
{ {
// create new patches for source and target // Create new patches for source and target
pointField srcPoints = srcPatch.points(); pointField srcPoints = srcPatch.points();
SourcePatch srcPatch0 SourcePatch srcPatch0
( (
@ -566,12 +566,12 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::constructFromSurface
} }
// map source and target patches onto projection surface // Map source and target patches onto projection surface
projectPointsToSurface(surfPtr(), srcPoints); projectPointsToSurface(surfPtr(), srcPoints);
projectPointsToSurface(surfPtr(), tgtPoints); projectPointsToSurface(surfPtr(), tgtPoints);
// calculate AMI interpolation // Calculate AMI interpolation
update(srcPatch0, tgtPatch0); update(srcPatch0, tgtPatch0);
} }
else else
@ -793,15 +793,6 @@ Foam::AMIInterpolation<SourcePatch, TargetPatch>::AMIInterpolation
tgtMapPtr_ tgtMapPtr_
); );
//if (tgtMapPtr_.valid())
//{
// Pout<< "tgtMap:" << endl;
// string oldPrefix = Pout.prefix();
// Pout.prefix() = oldPrefix + " ";
// tgtMapPtr_().printLayout(Pout);
// Pout.prefix() = oldPrefix;
//}
agglomerate agglomerate
( (
fineAMI.srcMapPtr_, fineAMI.srcMapPtr_,
@ -818,15 +809,6 @@ Foam::AMIInterpolation<SourcePatch, TargetPatch>::AMIInterpolation
tgtWeightsSum_, tgtWeightsSum_,
srcMapPtr_ srcMapPtr_
); );
//if (srcMapPtr_.valid())
//{
// Pout<< "srcMap:" << endl;
// string oldPrefix = Pout.prefix();
// Pout.prefix() = oldPrefix + " ";
// srcMapPtr_().printLayout(Pout);
// Pout.prefix() = oldPrefix;
//}
} }
@ -883,7 +865,7 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::update
if (singlePatchProc_ == -1) if (singlePatchProc_ == -1)
{ {
// convert local addressing to global addressing // Convert local addressing to global addressing
globalIndex globalSrcFaces(srcPatch.size()); globalIndex globalSrcFaces(srcPatch.size());
globalIndex globalTgtFaces(tgtPatch.size()); globalIndex globalTgtFaces(tgtPatch.size());
@ -893,12 +875,13 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::update
autoPtr<mapDistribute> mapPtr = calcProcMap(srcPatch, tgtPatch); autoPtr<mapDistribute> mapPtr = calcProcMap(srcPatch, tgtPatch);
const mapDistribute& map = mapPtr(); const mapDistribute& map = mapPtr();
// create new target patch that fully encompasses source patch // Create new target patch that fully encompasses source patch
// faces and points // Faces and points
faceList newTgtFaces; faceList newTgtFaces;
pointField newTgtPoints; pointField newTgtPoints;
// original faces from tgtPatch (in globalIndexing since might be
// Original faces from tgtPatch (in globalIndexing since might be
// remote) // remote)
labelList tgtFaceIDs; labelList tgtFaceIDs;
distributeAndMergePatches distributeAndMergePatches
@ -922,7 +905,7 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::update
newTgtPoints newTgtPoints
); );
// calculate AMI interpolation // Calculate AMI interpolation
autoPtr<AMIMethod<SourcePatch, TargetPatch>> AMIPtr autoPtr<AMIMethod<SourcePatch, TargetPatch>> AMIPtr
( (
AMIMethod<SourcePatch, TargetPatch>::New AMIMethod<SourcePatch, TargetPatch>::New
@ -976,7 +959,7 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::update
} }
} }
// send data back to originating procs. Note that contributions // Send data back to originating procs. Note that contributions
// from different processors get added (ListAppendEqOp) // from different processors get added (ListAppendEqOp)
mapDistributeBase::distribute mapDistributeBase::distribute
@ -1009,7 +992,7 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::update
scalarList() scalarList()
); );
// weights normalisation // Weights normalisation
normaliseWeights normaliseWeights
( (
srcMagSf_, srcMagSf_,
@ -1033,7 +1016,7 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::update
lowWeightCorrection_ lowWeightCorrection_
); );
// cache maps and reset addresses // Cache maps and reset addresses
List<Map<label>> cMap; List<Map<label>> cMap;
srcMapPtr_.reset(new mapDistribute(globalSrcFaces, tgtAddress_, cMap)); srcMapPtr_.reset(new mapDistribute(globalSrcFaces, tgtAddress_, cMap));
tgtMapPtr_.reset(new mapDistribute(globalTgtFaces, srcAddress_, cMap)); tgtMapPtr_.reset(new mapDistribute(globalTgtFaces, srcAddress_, cMap));
@ -1045,7 +1028,7 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::update
} }
else else
{ {
// calculate AMI interpolation // Calculate AMI interpolation
autoPtr<AMIMethod<SourcePatch, TargetPatch>> AMIPtr autoPtr<AMIMethod<SourcePatch, TargetPatch>> AMIPtr
( (
AMIMethod<SourcePatch, TargetPatch>::New AMIMethod<SourcePatch, TargetPatch>::New
@ -1431,41 +1414,36 @@ const
{ {
const pointField& srcPoints = srcPatch.points(); const pointField& srcPoints = srcPatch.points();
// source face addresses that intersect target face tgtFacei // Source face addresses that intersect target face tgtFacei
const labelList& addr = tgtAddress_[tgtFacei]; const labelList& addr = tgtAddress_[tgtFacei];
pointHit nearest;
nearest.setDistance(GREAT);
label nearestFacei = -1;
forAll(addr, i) forAll(addr, i)
{ {
label srcFacei = addr[i]; const label srcFacei = addr[i];
const face& f = srcPatch[srcFacei]; const face& f = srcPatch[srcFacei];
pointHit ray = f.ray(tgtPoint, n, srcPoints); pointHit ray = f.ray(tgtPoint, n, srcPoints);
if (ray.hit()) if (ray.hit())
{ {
tgtPoint = ray.rawPoint(); // tgtPoint = ray.rawPoint();
return srcFacei; return srcFacei;
} }
else if (ray.distance() < nearest.distance())
{
nearest = ray;
nearestFacei = srcFacei;
}
} }
// no hit registered - try with face normal instead of input normal if (nearest.hit() || nearest.eligibleMiss())
forAll(addr, i)
{ {
label srcFacei = addr[i]; // tgtPoint = nearest.rawPoint();
const face& f = srcPatch[srcFacei]; return nearestFacei;
vector nFace(-srcPatch.faceNormals()[srcFacei]);
nFace += tgtPatch.faceNormals()[tgtFacei];
pointHit ray = f.ray(tgtPoint, nFace, srcPoints);
if (ray.hit())
{
tgtPoint = ray.rawPoint();
return srcFacei;
}
} }
return -1; return -1;
@ -1485,41 +1463,36 @@ const
{ {
const pointField& tgtPoints = tgtPatch.points(); const pointField& tgtPoints = tgtPatch.points();
// target face addresses that intersect source face srcFacei pointHit nearest;
nearest.setDistance(GREAT);
label nearestFacei = -1;
// Target face addresses that intersect source face srcFacei
const labelList& addr = srcAddress_[srcFacei]; const labelList& addr = srcAddress_[srcFacei];
forAll(addr, i) forAll(addr, i)
{ {
label tgtFacei = addr[i]; const label tgtFacei = addr[i];
const face& f = tgtPatch[tgtFacei]; const face& f = tgtPatch[tgtFacei];
pointHit ray = f.ray(srcPoint, n, tgtPoints); pointHit ray = f.ray(srcPoint, n, tgtPoints);
if (ray.hit()) if (ray.hit() || ray.eligibleMiss())
{ {
srcPoint = ray.rawPoint(); // srcPoint = ray.rawPoint();
return tgtFacei; return tgtFacei;
} }
else if (ray.distance() < nearest.distance())
{
nearest = ray;
nearestFacei = tgtFacei;
}
} }
// no hit registered - try with face normal instead of input normal if (nearest.hit() || nearest.eligibleMiss())
forAll(addr, i)
{ {
label tgtFacei = addr[i]; // srcPoint = nearest.rawPoint();
const face& f = tgtPatch[tgtFacei]; return nearestFacei;
vector nFace(-srcPatch.faceNormals()[srcFacei]);
nFace += tgtPatch.faceNormals()[tgtFacei];
pointHit ray = f.ray(srcPoint, n, tgtPoints);
if (ray.hit())
{
srcPoint = ray.rawPoint();
return tgtFacei;
}
} }
return -1; return -1;
@ -1543,6 +1516,7 @@ const
{ {
const labelList& addr = srcAddress[i]; const labelList& addr = srcAddress[i];
const point& srcPt = srcPatch.faceCentres()[i]; const point& srcPt = srcPatch.faceCentres()[i];
forAll(addr, j) forAll(addr, j)
{ {
label tgtPtI = addr[j]; label tgtPtI = addr[j];