diff --git a/src/lagrangian/basic/InteractionLists/InteractionLists.C b/src/lagrangian/basic/InteractionLists/InteractionLists.C index 1a3133e653..6613b5a439 100644 --- a/src/lagrangian/basic/InteractionLists/InteractionLists.C +++ b/src/lagrangian/basic/InteractionLists/InteractionLists.C @@ -307,6 +307,44 @@ void Foam::InteractionLists::buildMap ); } + +template +void Foam::InteractionLists::prepareParticlesToRefer +( + const List >& cellOccupancy +) +{ + // Clear all existing referred particles + + forAll(referredParticles_, i) + { + referredParticles_[i].clear(); + } + + referredParticles_.setSize(cellIndexAndTransformToDistribute_.size()); + + forAll(cellIndexAndTransformToDistribute_, i) + { + const labelPair giat = cellIndexAndTransformToDistribute_[i]; + + label cellIndex = globalTransforms_.index(giat); + + List realParticles = cellOccupancy[cellIndex]; + + IDLList& particlesToRefer = referredParticles_[i]; + + forAll (realParticles, rM) + { + const ParticleType& particle = *realParticles[rM]; + + particlesToRefer.append(particle.clone().ptr()); + + prepareParticleToBeReferred(particlesToRefer.last(), giat); + } + } +} + + template void InteractionLists::prepareParticleToBeReferred ( @@ -323,6 +361,32 @@ void InteractionLists::prepareParticleToBeReferred } +template +void InteractionLists::writeReferredParticleCloud() +{ + bool writeCloud = true; + + if (mesh_.time().outputTime() && writeCloud) + { + cloud_.clear(); + + forAll(referredParticles_, refCellI) + { + const IDLList& refCell = referredParticles_[refCellI]; + + forAllConstIter(typename IDLList, refCell, iter) + { + cloud_.addParticle(iter().clone().ptr()); + } + } + + Particle::writeFields(cloud_); + + cloud_.clear(); + } +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template @@ -525,21 +589,23 @@ Foam::InteractionLists::InteractionLists // the order and structure is preserved, i.e. it, is as if the // cell had never been referred in the first place. - labelList oldToNew(globalIAndTToExchange.size(), -1); + // labelList oldToNew(globalIAndTToExchange.size(), -1); - label refCellI = 0; + // label refCellI = 0; - forAll(bbRequiredByAnyCell, bbReqI) - { - if (bbRequiredByAnyCell[bbReqI]) - { - oldToNew[bbReqI] = refCellI++; - } - } + // forAll(bbRequiredByAnyCell, bbReqI) + // { + // if (bbRequiredByAnyCell[bbReqI]) + // { + // oldToNew[bbReqI] = refCellI++; + // } + // } - inplaceReorder(oldToNew, ril_); + // inplaceReorder(oldToNew, ril_); - ril_.setSize(refCellI); + // ril_.setSize(refCellI); + + inplaceSubset(bbRequiredByAnyCell, ril_); } // Send information about which cells are actually required back @@ -571,32 +637,36 @@ Foam::InteractionLists::InteractionLists // and truncate it { - labelList oldToNew(globalIAndTToExchange.size(), -1); + // labelList oldToNew(globalIAndTToExchange.size(), -1); - label refCellI = 0; + // label refCellI = 0; - forAll(bbRequiredByAnyCell, bbReqI) - { - if (bbRequiredByAnyCell[bbReqI]) - { - oldToNew[bbReqI] = refCellI++; - } - } + // forAll(bbRequiredByAnyCell, bbReqI) + // { + // if (bbRequiredByAnyCell[bbReqI]) + // { + // oldToNew[bbReqI] = refCellI++; + // } + // } - inplaceReorder - ( - oldToNew, - static_cast&>(globalIAndTToExchange) - ); + // inplaceReorder + // ( + // oldToNew, + // globalIAndTToExchange + // ); - inplaceReorder - ( - oldToNew, - static_cast&>(procToDistributeTo) - ); + // inplaceReorder + // ( + // oldToNew, + // procToDistributeTo + // ); - globalIAndTToExchange.setSize(refCellI); - procToDistributeTo.setSize(refCellI); + // globalIAndTToExchange.setSize(refCellI); + // procToDistributeTo.setSize(refCellI); + + inplaceSubset(bbRequiredByAnyCell, globalIAndTToExchange); + + inplaceSubset(bbRequiredByAnyCell, procToDistributeTo); } preDistributionSize = procToDistributeTo.size(); @@ -699,62 +769,73 @@ Foam::InteractionLists::~InteractionLists() // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // template -void Foam::InteractionLists::prepareParticlesToRefer +void Foam::InteractionLists::sendReferredParticles ( const List >& cellOccupancy ) { - // Clear all existing referred particles + prepareParticlesToRefer(cellOccupancy); - forAll(referredParticles_, i) + PstreamBuffers pBufs(Pstream::nonBlocking); + + // Stream data into buffer + for (label domain = 0; domain < Pstream::nProcs(); domain++) { - referredParticles_[i].clear(); - } + const labelList& subMap = map().subMap()[domain]; - referredParticles_.setSize(cellIndexAndTransformToDistribute_.size()); - - forAll(cellIndexAndTransformToDistribute_, i) - { - const labelPair giat = cellIndexAndTransformToDistribute_[i]; - - label cellIndex = globalTransforms_.index(giat); - - List realParticles = cellOccupancy[cellIndex]; - - IDLList& particlesToRefer = referredParticles_[i]; - - forAll (realParticles, rM) + if (subMap.size()) { - const ParticleType& particle = *realParticles[rM]; + // Put data into send buffer + UOPstream toDomain(domain, pBufs); - particlesToRefer.append(particle.clone().ptr()); + UIndirectList > subMappedParticles + ( + referredParticles_, + subMap + ); - prepareParticleToBeReferred(particlesToRefer.last(), giat); - } - } - - // map().distribute(referredParticles_); - - bool writeCloud = true; - - if (mesh_.time().outputTime() && writeCloud) - { - cloud_.clear(); - - forAll(referredParticles_, refCellI) - { - const IDLList& refCell = referredParticles_[refCellI]; - - forAllConstIter(typename IDLList, refCell, iter) + forAll(subMappedParticles, i) { - cloud_.addParticle(iter().clone().ptr()); + toDomain << subMappedParticles[i]; } } - - Particle::writeFields(cloud_); - - cloud_.clear(); } + + // Start sending and receiving but do not block. + pBufs.finishedSends(false); + + // DO OTHER STUFF HERE; + + Pstream::waitRequests(); + + referredParticles_.setSize(map().constructSize()); + + for (label domain = 0; domain < Pstream::nProcs(); domain++) + { + const labelList& constructMap = map().constructMap()[domain]; + + if (constructMap.size()) + { + UIPstream str(domain, pBufs); + + forAll (constructMap, i) + { + referredParticles_[constructMap[i]] = IDLList + ( + str, + typename ParticleType::iNew(cloud_) + ); + } + } + } + + writeReferredParticleCloud(); +}; + + +template +void Foam::InteractionLists::receiveReferredParticles() +{ } diff --git a/src/lagrangian/basic/InteractionLists/InteractionLists.H b/src/lagrangian/basic/InteractionLists/InteractionLists.H index cd341116ac..7803c797fd 100644 --- a/src/lagrangian/basic/InteractionLists/InteractionLists.H +++ b/src/lagrangian/basic/InteractionLists/InteractionLists.H @@ -112,6 +112,13 @@ class InteractionLists //- Build the mapDistribute void buildMap(const List