From 22bd391903bd39dcc7fbe2bf80a6035a9ca3250c Mon Sep 17 00:00:00 2001 From: Will Bainbridge Date: Tue, 22 Aug 2017 17:57:11 +0100 Subject: [PATCH] lagrangian: Simplification of parallel transfer --- src/lagrangian/basic/Cloud/Cloud.C | 63 +++++++++--------- src/lagrangian/basic/particle/particle.C | 56 ++++++++++++++++ src/lagrangian/basic/particle/particle.H | 19 +----- .../basic/particle/particleTemplates.C | 66 ------------------- .../trackedParticle/trackedParticle.C | 3 +- .../trackedParticle/trackedParticle.H | 7 +- 6 files changed, 94 insertions(+), 120 deletions(-) diff --git a/src/lagrangian/basic/Cloud/Cloud.C b/src/lagrangian/basic/Cloud/Cloud.C index b17c8fdbee..394a38fb10 100644 --- a/src/lagrangian/basic/Cloud/Cloud.C +++ b/src/lagrangian/basic/Cloud/Cloud.C @@ -264,38 +264,41 @@ void Foam::Cloud::move // (i.e. it hasn't passed through an inlet or outlet) if (keepParticle) { - // If we are running in parallel and the particle is on a - // boundary face - if - ( - Pstream::parRun() - && td.switchProcessor - && p.face() >= pMesh().nInternalFaces() - ) + if (td.switchProcessor) { - label patchi = pbm.whichPatch(p.face()); - - // ... and the face is on a processor patch - // prepare it for transfer - if (procPatchIndices[patchi] != -1) + #ifdef FULLDEBUG + if + ( + !Pstream::parRun() + || !p.onBoundaryFace() + || procPatchIndices[p.patch()] < 0 + ) { - label n = neighbourProcIndices - [ - refCast - ( - pbm[patchi] - ).neighbProcNo() - ]; - - p.prepareForParallelTransfer(patchi, cloud, td); - - particleTransferLists[n].append(this->remove(&p)); - - patchIndexTransferLists[n].append - ( - procPatchNeighbours[patchi] - ); + FatalErrorInFunction + << "Switch processor flag is true when no parallel " + << "transfer is possible. This is a bug." + << exit(FatalError); } + #endif + + const label patchi = p.patch(); + + const label n = neighbourProcIndices + [ + refCast + ( + pbm[patchi] + ).neighbProcNo() + ]; + + p.prepareForParallelTransfer(); + + particleTransferLists[n].append(this->remove(&p)); + + patchIndexTransferLists[n].append + ( + procPatchNeighbours[patchi] + ); } } else @@ -380,7 +383,7 @@ void Foam::Cloud::move label patchi = procPatches[receivePatchIndex[pI++]]; - newp.correctAfterParallelTransfer(patchi, cloud, td); + newp.correctAfterParallelTransfer(patchi, td); addParticle(newParticles.remove(&newp)); } diff --git a/src/lagrangian/basic/particle/particle.C b/src/lagrangian/basic/particle/particle.C index f7520aa76a..72a18e61a8 100644 --- a/src/lagrangian/basic/particle/particle.C +++ b/src/lagrangian/basic/particle/particle.C @@ -1024,6 +1024,62 @@ Foam::scalar Foam::particle::wallImpactDistance(const vector&) const } +void Foam::particle::prepareForParallelTransfer() +{ + // Convert the face index to be local to the processor patch + facei_ = mesh_.boundaryMesh()[patch()].whichFace(facei_); +} + + +void Foam::particle::correctAfterParallelTransfer +( + const label patchi, + trackingData& td +) +{ + const coupledPolyPatch& ppp = + refCast(mesh_.boundaryMesh()[patchi]); + + if (!ppp.parallel()) + { + const tensor& T = + ( + ppp.forwardT().size() == 1 + ? ppp.forwardT()[0] + : ppp.forwardT()[facei_] + ); + transformProperties(T); + } + else if (ppp.separated()) + { + const vector& s = + ( + (ppp.separation().size() == 1) + ? ppp.separation()[0] + : ppp.separation()[facei_] + ); + transformProperties(-s); + } + + // Set the topology + celli_ = ppp.faceCells()[facei_]; + facei_ += ppp.start(); + tetFacei_ = facei_; + // Faces either side of a coupled patch are numbered in opposite directions + // as their normals both point away from their connected cells. The tet + // point therefore counts in the opposite direction from the base point. + tetPti_ = mesh_.faces()[tetFacei_].size() - 1 - tetPti_; + + // Reflect to account for the change of triangle orientation in the new cell + reflect(); + + // Note that the position does not need transforming explicitly. The face- + // triangle on the receive patch is the transformation of the one on the + // send patch, so whilst the barycentric coordinates remain the same, the + // change of triangle implicitly transforms the position. +} + + void Foam::particle::prepareForInteractionListReferral ( const vectorTensorTransform& transform diff --git a/src/lagrangian/basic/particle/particle.H b/src/lagrangian/basic/particle/particle.H index 1043bb20b4..4b1d43e139 100644 --- a/src/lagrangian/basic/particle/particle.H +++ b/src/lagrangian/basic/particle/particle.H @@ -661,25 +661,12 @@ public: // Parallel transfer - //- Convert global addressing to the processor patch - // local equivalents - template - void prepareForParallelTransfer - ( - const label patchi, - TrackCloudType& cloud, - trackingData& td - ); + //- Convert global addressing to the processor patch local equivalents + void prepareForParallelTransfer(); //- Convert processor patch addressing to the global equivalents // and set the celli to the face-neighbour - template - void correctAfterParallelTransfer - ( - const label patchi, - TrackCloudType& cloud, - trackingData& td - ); + void correctAfterParallelTransfer(const label patchi, trackingData& td); // Interaction list referral diff --git a/src/lagrangian/basic/particle/particleTemplates.C b/src/lagrangian/basic/particle/particleTemplates.C index eac77b61fa..45ee75ac60 100644 --- a/src/lagrangian/basic/particle/particleTemplates.C +++ b/src/lagrangian/basic/particle/particleTemplates.C @@ -35,72 +35,6 @@ License #include "wedgePolyPatch.H" #include "meshTools.H" -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - -template -void Foam::particle::prepareForParallelTransfer -( - const label patchi, - TrackCloudType& cloud, - trackingData& td -) -{ - // Convert the face index to be local to the processor patch - facei_ = mesh_.boundaryMesh()[patchi].whichFace(facei_); -} - - -template -void Foam::particle::correctAfterParallelTransfer -( - const label patchi, - TrackCloudType& cloud, - trackingData& td -) -{ - const coupledPolyPatch& ppp = - refCast(mesh_.boundaryMesh()[patchi]); - - if (!ppp.parallel()) - { - const tensor& T = - ( - ppp.forwardT().size() == 1 - ? ppp.forwardT()[0] - : ppp.forwardT()[facei_] - ); - transformProperties(T); - } - else if (ppp.separated()) - { - const vector& s = - ( - (ppp.separation().size() == 1) - ? ppp.separation()[0] - : ppp.separation()[facei_] - ); - transformProperties(-s); - } - - // Set the topology - celli_ = ppp.faceCells()[facei_]; - facei_ += ppp.start(); - tetFacei_ = facei_; - // Faces either side of a coupled patch are numbered in opposite directions - // as their normals both point away from their connected cells. The tet - // point therefore counts in the opposite direction from the base point. - tetPti_ = mesh_.faces()[tetFacei_].size() - 1 - tetPti_; - - // Reflect to account for the change of triangle orientation in the new cell - reflect(); - - // Note that the position does not need transforming explicitly. The face- - // triangle on the receive patch is the transformation of the one on the - // send patch, so whilst the barycentric coordinates remain the same, the - // change of triangle implicitly transforms the position. -} - - // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template diff --git a/src/mesh/snappyHexMesh/trackedParticle/trackedParticle.C b/src/mesh/snappyHexMesh/trackedParticle/trackedParticle.C index de27997d73..f8cb6711f1 100644 --- a/src/mesh/snappyHexMesh/trackedParticle/trackedParticle.C +++ b/src/mesh/snappyHexMesh/trackedParticle/trackedParticle.C @@ -264,11 +264,10 @@ void Foam::trackedParticle::hitPatch void Foam::trackedParticle::correctAfterParallelTransfer ( const label patchi, - Cloud& cloud, trackingData& td ) { - particle::correctAfterParallelTransfer(patchi, cloud, td); + particle::correctAfterParallelTransfer(patchi, td); label edgeI = k(); if (edgeI != -1) diff --git a/src/mesh/snappyHexMesh/trackedParticle/trackedParticle.H b/src/mesh/snappyHexMesh/trackedParticle/trackedParticle.H index d329808baa..ae38eb8445 100644 --- a/src/mesh/snappyHexMesh/trackedParticle/trackedParticle.H +++ b/src/mesh/snappyHexMesh/trackedParticle/trackedParticle.H @@ -326,12 +326,7 @@ public: //- Convert processor patch addressing to the global equivalents // and set the celli to the face-neighbour - void correctAfterParallelTransfer - ( - const label, - Cloud& cloud, - trackingData& td - ); + void correctAfterParallelTransfer(const label, trackingData& td); // Ostream Operator