From 6a4b5995bcef4041bb187a13efcc215f1fd15518 Mon Sep 17 00:00:00 2001 From: andy Date: Tue, 31 Jul 2012 10:27:03 +0100 Subject: [PATCH 1/8] BUG: Corrected injection tet for cellZoneInjection model --- .../InjectionModel/CellZoneInjection/CellZoneInjection.C | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/CellZoneInjection/CellZoneInjection.C b/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/CellZoneInjection/CellZoneInjection.C index 8ae15bab76..4764de1af6 100644 --- a/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/CellZoneInjection/CellZoneInjection.C +++ b/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/CellZoneInjection/CellZoneInjection.C @@ -77,7 +77,7 @@ void Foam::CellZoneInjection::setPositions for (label tetI = 1; tetI < cellTetIs.size() - 1; tetI++) { cTetVFrac[tetI] = - (cTetVFrac[tetI-1] + cellTetIs[tetI].tet(mesh).mag())/V[cellI]; + cTetVFrac[tetI-1] + cellTetIs[tetI].tet(mesh).mag()/V[cellI]; } cTetVFrac.last() = 1.0; From a9238db4a304a6fdc282d7f9d3682cd816e617ba Mon Sep 17 00:00:00 2001 From: andy Date: Tue, 31 Jul 2012 10:46:30 +0100 Subject: [PATCH 2/8] STYLE: minor code formatting --- .../Kinematic/InjectionModel/PatchInjection/PatchInjection.C | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/PatchInjection/PatchInjection.C b/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/PatchInjection/PatchInjection.C index aae52b8e22..bc33cdc06f 100644 --- a/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/PatchInjection/PatchInjection.C +++ b/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/PatchInjection/PatchInjection.C @@ -141,7 +141,7 @@ Foam::label Foam::PatchInjection::parcelsToInject { if ((time0 >= 0.0) && (time0 < duration_)) { - scalar nParcels =fraction_*(time1 - time0)*parcelsPerSecond_; + scalar nParcels = fraction_*(time1 - time0)*parcelsPerSecond_; cachedRandom& rnd = this->owner().rndGen(); From 114c9851ca2556295945f84d7f342b06048d91c5 Mon Sep 17 00:00:00 2001 From: andy Date: Tue, 31 Jul 2012 15:03:26 +0100 Subject: [PATCH 3/8] ENH: Enabled writing of mass stick/escape for particle localInteraction model --- .../LocalInteraction/LocalInteraction.C | 110 ++++++++++++++++-- .../LocalInteraction/LocalInteraction.H | 17 +++ 2 files changed, 119 insertions(+), 8 deletions(-) diff --git a/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/LocalInteraction/LocalInteraction.C b/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/LocalInteraction/LocalInteraction.C index c1ce95e215..2350ee62f8 100644 --- a/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/LocalInteraction/LocalInteraction.C +++ b/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/LocalInteraction/LocalInteraction.C @@ -39,8 +39,26 @@ Foam::LocalInteraction::LocalInteraction nEscape_(patchData_.size(), 0), massEscape_(patchData_.size(), 0.0), nStick_(patchData_.size(), 0), - massStick_(patchData_.size(), 0.0) + massStick_(patchData_.size(), 0.0), + writeFields_(this->coeffDict().lookupOrDefault("writeFields", false)), + massEscapePtr_(NULL), + massStickPtr_(NULL) { + 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; + + (void)massEscape(); + (void)massStick(); + } + else + { + Info<< " Interaction fields will not be written" << endl; + } + // check that interactions are valid/specified forAll(patchData_, patchI) { @@ -74,7 +92,10 @@ Foam::LocalInteraction::LocalInteraction nEscape_(pim.nEscape_), massEscape_(pim.massEscape_), nStick_(pim.nStick_), - massStick_(pim.massStick_) + massStick_(pim.massStick_), + writeFields_(pim.writeFields_), + massEscapePtr_(NULL), + massStickPtr_(NULL) {} @@ -87,6 +108,64 @@ Foam::LocalInteraction::~LocalInteraction() // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // +template +Foam::volScalarField& Foam::LocalInteraction::massEscape() +{ + if (!massEscapePtr_.valid()) + { + const fvMesh& mesh = this->owner().mesh(); + + massEscapePtr_.reset + ( + new volScalarField + ( + IOobject + ( + this->owner().name() + "::massEscape", + mesh.time().timeName(), + mesh, + IOobject::READ_IF_PRESENT, + IOobject::AUTO_WRITE + ), + mesh, + dimensionedScalar("zero", dimMass, 0.0) + ) + ); + } + + return massEscapePtr_(); +} + + +template +Foam::volScalarField& Foam::LocalInteraction::massStick() +{ + if (!massStickPtr_.valid()) + { + const fvMesh& mesh = this->owner().mesh(); + + massStickPtr_.reset + ( + new volScalarField + ( + IOobject + ( + this->owner().name() + "::massStick", + mesh.time().timeName(), + mesh, + IOobject::READ_IF_PRESENT, + IOobject::AUTO_WRITE + ), + mesh, + dimensionedScalar("zero", dimMass, 0.0) + ) + ); + } + + return massStickPtr_(); +} + + template bool Foam::LocalInteraction::correct ( @@ -97,14 +176,13 @@ bool Foam::LocalInteraction::correct const tetIndices& tetIs ) { - vector& U = p.U(); - - bool& active = p.active(); - label patchI = patchData_.applyToPatch(pp.index()); if (patchI >= 0) { + vector& U = p.U(); + bool& active = p.active(); + typename PatchInteractionModel::interactionType it = this->wordToInteractionType ( @@ -115,20 +193,36 @@ bool Foam::LocalInteraction::correct { case PatchInteractionModel::itEscape: { + scalar dm = p.mass()*p.nParticle(); + keepParticle = false; active = false; U = vector::zero; nEscape_[patchI]++; - massEscape_[patchI] += p.mass()*p.nParticle(); + massEscape_[patchI] += dm; + if (writeFields_) + { + label pI = pp.index(); + label fI = pp.whichFace(p.face()); + massEscape().boundaryField()[pI][fI] += dm; + } break; } case PatchInteractionModel::itStick: { + scalar dm = p.mass()*p.nParticle(); + keepParticle = true; active = false; U = vector::zero; nStick_[patchI]++; - massStick_[patchI] += p.mass()*p.nParticle(); + massStick_[patchI] += dm; + if (writeFields_) + { + label pI = pp.index(); + label fI = pp.whichFace(p.face()); + massStick().boundaryField()[pI][fI] += dm; + } break; } case PatchInteractionModel::itRebound: diff --git a/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/LocalInteraction/LocalInteraction.H b/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/LocalInteraction/LocalInteraction.H index a3a28121f0..3a8c776776 100644 --- a/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/LocalInteraction/LocalInteraction.H +++ b/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/LocalInteraction/LocalInteraction.H @@ -34,6 +34,7 @@ Description #include "PatchInteractionModel.H" #include "patchInteractionDataList.H" +#include "Switch.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -69,6 +70,16 @@ class LocalInteraction List massStick_; + //- Flag to output data as fields + Switch writeFields_; + + //- Mass escape field + autoPtr massEscapePtr_; + + //- Mass stick field + autoPtr massStickPtr_; + + public: //- Runtime type information @@ -99,6 +110,12 @@ public: // Member Functions + //- Return access to the massEscape field + volScalarField& massEscape(); + + //- Return access to the massStick field + volScalarField& massStick(); + //- Apply velocity correction // Returns true if particle remains in same cell virtual bool correct From 8b9caf978c7e024359f8b50f882c4cc1d1b2ea87 Mon Sep 17 00:00:00 2001 From: andy Date: Tue, 31 Jul 2012 15:14:36 +0100 Subject: [PATCH 4/8] ENH: Added new patchFlowRate particle injection model --- .../PatchFlowRateInjection.C | 316 ++++++++++++++++++ .../PatchFlowRateInjection.H | 204 +++++++++++ 2 files changed, 520 insertions(+) create mode 100644 src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/PatchFlowRateInjection/PatchFlowRateInjection.C create mode 100644 src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/PatchFlowRateInjection/PatchFlowRateInjection.H diff --git a/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/PatchFlowRateInjection/PatchFlowRateInjection.C b/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/PatchFlowRateInjection/PatchFlowRateInjection.C new file mode 100644 index 0000000000..bf4bd87b1c --- /dev/null +++ b/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/PatchFlowRateInjection/PatchFlowRateInjection.C @@ -0,0 +1,316 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "PatchFlowRateInjection.H" +#include "TimeDataEntry.H" +#include "distributionModel.H" +#include "mathematicalConstants.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +Foam::PatchFlowRateInjection::PatchFlowRateInjection +( + const dictionary& dict, + CloudType& owner, + const word& modelName +) +: + InjectionModel(dict, owner, modelName,typeName), + patchName_(this->coeffDict().lookup("patchName")), + patchId_(owner.mesh().boundaryMesh().findPatchID(patchName_)), + patchArea_(0.0), + patchNormal_(vector::zero), + phiName_(this->coeffDict().template lookupOrDefault("phi", "phi")), + rhoName_(this->coeffDict().template lookupOrDefault("rho", "rho")), + duration_(readScalar(this->coeffDict().lookup("duration"))), + concentration_(readScalar(this->coeffDict().lookup("concentration"))), + parcelsPerSecond_ + ( + readScalar(this->coeffDict().lookup("parcelsPerSecond")) + ), + U0_(vector::zero), + sizeDistribution_ + ( + distributionModels::distributionModel::New + ( + this->coeffDict().subDict("sizeDistribution"), + owner.rndGen() + ) + ), + cellOwners_(), + fraction_(1.0), + pMeanVolume_(0.0) +{ + if (patchId_ < 0) + { + FatalErrorIn + ( + "PatchFlowRateInjection::PatchFlowRateInjection" + "(" + "const dictionary&, " + "CloudType&" + ")" + ) << "Requested patch " << patchName_ << " not found" << nl + << "Available patches are: " << owner.mesh().boundaryMesh().names() + << nl << exit(FatalError); + } + + const polyPatch& patch = owner.mesh().boundaryMesh()[patchId_]; + + duration_ = owner.db().time().userTimeToTime(duration_); + + cellOwners_ = patch.faceCells(); + + // TODO: retrieve mean diameter from distrution model + scalar pMeanDiameter = + readScalar(this->coeffDict().lookup("meanParticleDiameter")); + pMeanVolume_ = constant::mathematical::pi*pow3(pMeanDiameter)/6.0; + + // patch geometry + label patchSize = cellOwners_.size(); + label totalPatchSize = patchSize; + reduce(totalPatchSize, sumOp