diff --git a/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/LocalInteraction/LocalInteraction.C b/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/LocalInteraction/LocalInteraction.C index b5e7d162db..946564c1b8 100644 --- a/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/LocalInteraction/LocalInteraction.C +++ b/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/LocalInteraction/LocalInteraction.C @@ -37,21 +37,23 @@ Foam::LocalInteraction::LocalInteraction PatchInteractionModel(dict, cloud, typeName), patchData_(cloud.mesh(), this->coeffDict()), nEscape_(patchData_.size()), - massEscape_(patchData_.size()), - nStick_(patchData_.size()), - massStick_(patchData_.size()), + massEscape_(nEscape_.size()), + nStick_(nEscape_.size()), + massStick_(nEscape_.size()), writeFields_(this->coeffDict().lookupOrDefault("writeFields", false)), - outputByInjectorId_(this->coeffDict().lookupOrDefault("outputByInjectorId", false)), - injIdToIndex_(cloud.injectors().size()), + injIdToIndex_(), massEscapePtr_(nullptr), massStickPtr_(nullptr) { + const bool outputByInjectorId + = this->coeffDict().lookupOrDefault("outputByInjectorId", false); + if (writeFields_) { - word massEscapeName(this->owner().name() + ":massEscape"); - word massStickName(this->owner().name() + ":massStick"); - Info<< " Interaction fields will be written to " << massEscapeName - << " and " << massStickName << endl; + Info<< " Interaction fields will be written to " + << this->owner().name() << ":massEscape" + << " and " + << this->owner().name() << ":massStick" << endl; (void)massEscape(); (void)massStick(); @@ -61,7 +63,23 @@ Foam::LocalInteraction::LocalInteraction Info<< " Interaction fields will not be written" << endl; } - // check that interactions are valid/specified + // Determine the number of injectors and the injector mapping + label nInjectors = 0; + if (outputByInjectorId) + { + for (const auto& inj : cloud.injectors()) + { + injIdToIndex_.insert(inj.injectorID(), nInjectors++); + } + } + + // The normal case, and safety if injector mapping was somehow null. + if (!nInjectors) + { + nInjectors = 1; + } + + // Check that interactions are valid/specified forAll(patchData_, patchi) { const word& interactionTypeName = @@ -80,20 +98,10 @@ Foam::LocalInteraction::LocalInteraction << nl << exit(FatalError); } - label nInjectors(1); - if (outputByInjectorId_) - { - nInjectors = cloud.injectors().size(); - for (label i=0; i::LocalInteraction nStick_(pim.nStick_), massStick_(pim.massStick_), writeFields_(pim.writeFields_), - outputByInjectorId_(pim.outputByInjectorId_), injIdToIndex_(pim.injIdToIndex_), massEscapePtr_(nullptr), massStickPtr_(nullptr) {} -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -template -Foam::LocalInteraction::~LocalInteraction() -{} - - // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // template @@ -193,12 +193,20 @@ bool Foam::LocalInteraction::correct bool& keepParticle ) { - label patchi = patchData_.applyToPatch(pp.index()); + const label patchi = patchData_.applyToPatch(pp.index()); if (patchi >= 0) { vector& U = p.U(); + // Location for storing the stats. + const label idx = + ( + injIdToIndex_.size() + ? injIdToIndex_.lookup(p.typeId(), 0) + : 0 + ); + typename PatchInteractionModel::interactionType it = this->wordToInteractionType ( @@ -213,50 +221,38 @@ bool Foam::LocalInteraction::correct } case PatchInteractionModel::itEscape: { - scalar dm = p.mass()*p.nParticle(); - keepParticle = false; p.active(false); U = Zero; - if (outputByInjectorId_) - { - nEscape_[patchi][injIdToIndex_[p.typeId()]]++; - massEscape_[patchi][injIdToIndex_[p.typeId()]] += dm; - } - else - { - nEscape_[patchi][0]++; - massEscape_[patchi][0] += dm; - } + + const scalar dm = p.mass()*p.nParticle(); + + nEscape_[patchi][idx]++; + massEscape_[patchi][idx] += dm; + if (writeFields_) { - label pI = pp.index(); - label fI = pp.whichFace(p.face()); + const label pI = pp.index(); + const label fI = pp.whichFace(p.face()); massEscape().boundaryFieldRef()[pI][fI] += dm; } break; } case PatchInteractionModel::itStick: { - scalar dm = p.mass()*p.nParticle(); - keepParticle = true; p.active(false); U = Zero; - if (outputByInjectorId_) - { - nStick_[patchi][injIdToIndex_[p.typeId()]]++; - massStick_[patchi][injIdToIndex_[p.typeId()]] += dm; - } - else - { - nStick_[patchi][0]++; - massStick_[patchi][0] += dm; - } + + const scalar dm = p.mass()*p.nParticle(); + + nStick_[patchi][idx]++; + massStick_[patchi][idx] += dm; + if (writeFields_) { - label pI = pp.index(); - label fI = pp.whichFace(p.face()); + const label pI = pp.index(); + const label fI = pp.whichFace(p.face()); massStick().boundaryFieldRef()[pI][fI] += dm; } break; @@ -355,21 +351,28 @@ void Foam::LocalInteraction::info(Ostream& os) mps[i] = mps[i] + mps0[i]; } - - if (outputByInjectorId_) + if (injIdToIndex_.size()) { + // Since injIdToIndex_ is a one-to-one mapping (starting as zero), + // can simply invert it. + labelList indexToInjector(injIdToIndex_.size()); + forAllConstIters(injIdToIndex_, iter) + { + indexToInjector[iter.object()] = iter.key(); + } + forAll(patchData_, i) { - forAll (mpe[i], injId) + forAll(mpe[i], idx) { os << " Parcel fate: patch " << patchData_[i].patchName() << " (number, mass)" << nl - << " - escape (injector " << injIdToIndex_.toc()[injId] - << " ) = " << npe[i][injId] - << ", " << mpe[i][injId] << nl - << " - stick (injector " << injIdToIndex_.toc()[injId] - << " ) = " << nps[i][injId] - << ", " << mps[i][injId] << nl; + << " - escape (injector " << indexToInjector[idx] + << " ) = " << npe[i][idx] + << ", " << mpe[i][idx] << nl + << " - stick (injector " << indexToInjector[idx] + << " ) = " << nps[i][idx] + << ", " << mps[i][idx] << nl; } } } @@ -379,25 +382,23 @@ void Foam::LocalInteraction::info(Ostream& os) { os << " Parcel fate: patch " << patchData_[i].patchName() << " (number, mass)" << nl - << " - escape = " << npe[i][0] - << ", " << mpe[i][0] << nl - << " - stick = " << nps[i][0] - << ", " << mps[i][0] << nl; + << " - escape = " + << npe[i][0] << ", " << mpe[i][0] << nl + << " - stick = " + << nps[i][0] << ", " << mps[i][0] << nl; } } if (this->writeTime()) { this->setModelProperty("nEscape", npe); - nEscape_ = Zero; - this->setModelProperty("massEscape", mpe); - massEscape_ = Zero; - this->setModelProperty("nStick", nps); - nStick_ = Zero; - this->setModelProperty("massStick", mps); + + nEscape_ = Zero; + massEscape_ = Zero; + nStick_ = Zero; massStick_ = Zero; } } diff --git a/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/LocalInteraction/LocalInteraction.H b/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/LocalInteraction/LocalInteraction.H index 693389c1b4..72b00ffb98 100644 --- a/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/LocalInteraction/LocalInteraction.H +++ b/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/LocalInteraction/LocalInteraction.H @@ -43,6 +43,7 @@ Description namespace Foam { + /*---------------------------------------------------------------------------*\ Class LocalInteraction Declaration \*---------------------------------------------------------------------------*/ @@ -57,29 +58,25 @@ class LocalInteraction //- List of participating patches const patchInteractionDataList patchData_; + // Bookkeeping for particle fates - // Counters for particle fates + //- Number of parcels escaped + List> nEscape_; - //- Number of parcels escaped - List> nEscape_; + //- Mass of parcels escaped + List> massEscape_; - //- Mass of parcels escaped - List> massEscape_; - - //- Number of parcels stuck to patches - List> nStick_; - - //- Mass of parcels stuck to patches - List> massStick_; + //- Number of parcels stuck to patches + List> nStick_; + //- Mass of parcels stuck to patches + List> massStick_; //- Flag to output data as fields - Switch writeFields_; + bool writeFields_; - //- Flag to output escaped/mass particles sorted by injectorID - Switch outputByInjectorId_; - - //- InjectorId to index map + //- InjectorId to index map, when outputting escaped/stick/... + // particles sorted by injectorID Map