diff --git a/OFsolvers/OF13/birdmultiphaseEuler/Allwclean b/OFsolvers/OF13/birdmultiphaseEuler/Allwclean index f9e3cd1f..3b33d620 100755 --- a/OFsolvers/OF13/birdmultiphaseEuler/Allwclean +++ b/OFsolvers/OF13/birdmultiphaseEuler/Allwclean @@ -10,5 +10,8 @@ wclean wclean libso fvModels wclean libso functionObjects +wclean libso boundaryConditions +wclean libso fvConstraints/limitCourant +wclean libso fvConstraints/residualPhaseVelocity #------------------------------------------------------------------------------ diff --git a/OFsolvers/OF13/birdmultiphaseEuler/Allwmake b/OFsolvers/OF13/birdmultiphaseEuler/Allwmake index fc432ad1..ba2859c5 100755 --- a/OFsolvers/OF13/birdmultiphaseEuler/Allwmake +++ b/OFsolvers/OF13/birdmultiphaseEuler/Allwmake @@ -13,5 +13,8 @@ wmake $targetType wmake -j 20 $targetType fvModels wmake -j 20 $targetType functionObjects +wmake -j 20 $targetType boundaryConditions +wmake $targetType fvConstraints/limitCourant +wmake $targetType fvConstraints/residualPhaseVelocity #------------------------------------------------------------------------------ diff --git a/OFsolvers/OF13/birdmultiphaseEuler/boundaryConditions/Make/files b/OFsolvers/OF13/birdmultiphaseEuler/boundaryConditions/Make/files new file mode 100644 index 00000000..9279f1a1 --- /dev/null +++ b/OFsolvers/OF13/birdmultiphaseEuler/boundaryConditions/Make/files @@ -0,0 +1,3 @@ +recirculatedSpecies/recirculatedSpeciesFvPatchScalarField.C + +LIB = $(FOAM_USER_LIBBIN)/libbirdBoundaryConditions diff --git a/OFsolvers/OF13/birdmultiphaseEuler/boundaryConditions/Make/options b/OFsolvers/OF13/birdmultiphaseEuler/boundaryConditions/Make/options new file mode 100644 index 00000000..ad2b36e5 --- /dev/null +++ b/OFsolvers/OF13/birdmultiphaseEuler/boundaryConditions/Make/options @@ -0,0 +1,14 @@ +EXE_INC = \ + -I$(LIB_SRC)/finiteVolume/lnInclude \ + -I$(LIB_SRC)/meshTools/lnInclude \ + -I../phaseSystem/lnInclude \ + -I$(LIB_SRC)/physicalProperties/lnInclude \ + -I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \ + -I$(LIB_SRC)/twoPhaseModels/twoPhaseMixture/lnInclude \ + + +LIB_LIBS = \ + -lfiniteVolume \ + -lmeshTools \ + -L$(FOAM_USER_LIBBIN) \ + -lbirdphaseSystem diff --git a/OFsolvers/OF13/birdmultiphaseEuler/boundaryConditions/recirculatedSpecies/recirculatedSpeciesFvPatchScalarField.C b/OFsolvers/OF13/birdmultiphaseEuler/boundaryConditions/recirculatedSpecies/recirculatedSpeciesFvPatchScalarField.C new file mode 100644 index 00000000..aafc13f9 --- /dev/null +++ b/OFsolvers/OF13/birdmultiphaseEuler/boundaryConditions/recirculatedSpecies/recirculatedSpeciesFvPatchScalarField.C @@ -0,0 +1,226 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2026 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 "recirculatedSpeciesFvPatchScalarField.H" +#include "addToRunTimeSelectionTable.H" +#include "fieldMapper.H" +#include "volFields.H" +#include "surfaceFields.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +Foam::scalar Foam::recirculatedSpeciesFvPatchScalarField::t() const +{ + return db().time().value(); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::recirculatedSpeciesFvPatchScalarField:: +recirculatedSpeciesFvPatchScalarField +( + const fvPatch& p, + const DimensionedField& iF, + const dictionary& dict +) +: + fixedValueFvPatchScalarField(p, iF), + Y0_ + ( + Function1::New + ( + "Y0", + db().time().userUnits(), + unitAny, + dict + ) + ), + r_ + ( + Function1::New + ( + "r", + db().time().userUnits(), + unitAny, + dict + ) + ), + phaseName_(dict.lookupOrDefault("phase","gas")), + otherPatchName_(dict.lookup("otherPatch")) +{ + + +// fixedValueFvPatchScalarField::evaluate(); + + + // Initialise with the value entry if evaluation is not possible + fvPatchScalarField::operator= + ( + scalarField("value", iF.dimensions(), dict, p.size()) + ); + +} + + +Foam::recirculatedSpeciesFvPatchScalarField:: +recirculatedSpeciesFvPatchScalarField +( + const recirculatedSpeciesFvPatchScalarField& ptf, + const fvPatch& p, + const DimensionedField& iF, + const fieldMapper& mapper +) +: + fixedValueFvPatchScalarField(ptf, p, iF, mapper), + Y0_(ptf.Y0_, false), + r_(ptf.r_, false), + phaseName_(ptf.phaseName_), + otherPatchName_(ptf.otherPatchName_) +{} + + +Foam::recirculatedSpeciesFvPatchScalarField:: +recirculatedSpeciesFvPatchScalarField +( + const recirculatedSpeciesFvPatchScalarField& ptf, + const DimensionedField& iF +) +: + fixedValueFvPatchScalarField(ptf, iF), + Y0_(ptf.Y0_, false), + r_(ptf.r_, false), + phaseName_(ptf.phaseName_), + otherPatchName_(ptf.otherPatchName_) +{} + + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::recirculatedSpeciesFvPatchScalarField::map +( + const fvPatchScalarField& ptf, + const fieldMapper& mapper +) +{ + fixedValueFvPatchScalarField::map(ptf, mapper); +} + + +void Foam::recirculatedSpeciesFvPatchScalarField::reset +( + const fvPatchScalarField& ptf +) +{ + fixedValueFvPatchScalarField::reset(ptf); +} + + +void Foam::recirculatedSpeciesFvPatchScalarField::updateCoeffs() +{ + if (updated()) + { + return; + } + + const phaseModel& phase + ( + db().lookupObject + ( + IOobject::groupName("alpha", phaseName_) + ) + ); + + + if ( !db().foundObject("alphaRhoPhi." + phase.name()) ) + { + return; + } + + // Since we're inside initEvaluate/evaluate there might be processor + // comms underway. Change the tag we use. + int oldTag = UPstream::msgType(); + UPstream::msgType() = oldTag+1; + + const fvMesh& mesh = this->internalField().mesh(); + + label patchID = mesh.boundaryMesh().findIndex(otherPatchName_); + + scalar alphaRhoPhiYr = 0.; + scalar alphaRhoPhiTot = 1e-16; + + if ( patchID != 1 ) + { + const fvPatch& nbrPatch = mesh.boundary()[patchID]; + const scalarField& alphaRhoPhip = nbrPatch.lookupPatchField("alphaRhoPhi." + phase.name()); + const scalarField& Yp = nbrPatch.lookupPatchField(this->internalField().name()); + + alphaRhoPhiTot = max( mag( sum(alphaRhoPhip)),1e-16 ); + alphaRhoPhiYr = mag( sum(alphaRhoPhip*Yp) ); + } + + reduce(alphaRhoPhiTot, sumOp()); + reduce(alphaRhoPhiYr, sumOp()); + + const scalar Yr = min(max( alphaRhoPhiYr/alphaRhoPhiTot, 0.), 1.); + + scalar rf = min(max(r_->value(t()),0.),1.); + + // Restore tag + UPstream::msgType() = oldTag; + + fixedValueFvPatchScalarField::operator==( (1. - rf)*Y0_->value(t()) + rf*Yr ); + + fixedValueFvPatchScalarField::updateCoeffs(); +} + + +void Foam::recirculatedSpeciesFvPatchScalarField::write +( + Ostream& os +) const +{ + fvPatchScalarField::write(os); + writeEntry(os, db().time().userUnits(), unitAny, Y0_()); + writeEntry(os, db().time().userUnits(), unitAny, r_()); + writeEntry(os, "phase", phaseName_); + writeEntry(os, "otherPatch", otherPatchName_); + writeEntry(os, "value", *this); +} + + +// * * * * * * * * * * * * * * Build Macro Function * * * * * * * * * * * * // + +namespace Foam +{ + makePatchTypeField + ( + fvPatchScalarField, + recirculatedSpeciesFvPatchScalarField + ); +} + +// ************************************************************************* // diff --git a/OFsolvers/OF13/birdmultiphaseEuler/boundaryConditions/recirculatedSpecies/recirculatedSpeciesFvPatchScalarField.H b/OFsolvers/OF13/birdmultiphaseEuler/boundaryConditions/recirculatedSpecies/recirculatedSpeciesFvPatchScalarField.H new file mode 100644 index 00000000..ab8f9052 --- /dev/null +++ b/OFsolvers/OF13/birdmultiphaseEuler/boundaryConditions/recirculatedSpecies/recirculatedSpeciesFvPatchScalarField.H @@ -0,0 +1,203 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2026 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 . + +Class + Foam::recirculatedSpeciesFvPatchScalarField + +Description + This boundary condition provides a recirculatedSpecies condition, + calculated as: + + \f[ + Y = Y_{0}*(1-r) + r*Y_{r} + \f] + and + \f[ + Y_{r} = sum(\alphaRhoPhi_{pr} Y_{pr}) / sum(\alphaRhoPhi_{pr}) + \f] + + where + \vartable + r | recirculation factor [-] + Y_{0} | base patch value [-] + Y_{r} | recirculating patch mean [-] + alphaRhoPhi_{pr}| mass flow rate at recirculating patch [Kg/s] + Y_{pr}| mass fraction at recirculating patch [Kg/Kg] + \endtable + +Usage + \table + Property | Description | Req'd? | Default + Y0 | base value | yes | + r | recirculation factor | yes | + otherPatch | name of other patch | yes | + \endtable + + Example of the boundary condition specification: + \verbatim + + { + type recirculatedSpecies; + Y0 1; //Initial stream only has this species + r table ( + (0 0) + (1 1) + ); // Switch to full recirculation after one second + otherPatch outlet; + value uniform 1; // optional initial value + } + \endverbatim + +SourceFiles + recirculatedSpeciesFvPatchScalarField.C + +\*---------------------------------------------------------------------------*/ + +#ifndef BC_H +#define BC_H + +#include "fixedValueFvPatchFields.H" +#include "Function1.H" +#include "phaseModel.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class recirculatedSpeciesFvPatchScalarField Declaration +\*---------------------------------------------------------------------------*/ + +class recirculatedSpeciesFvPatchScalarField +: + public fixedValueFvPatchScalarField +{ + // Private Data + + //- Base value + autoPtr> Y0_; + + //- Recirculation factor + autoPtr> r_; + + word phaseName_; + + word otherPatchName_; + + + // Private Member Functions + + //- Return current time + scalar t() const; + + +public: + + //- Runtime type information + TypeName("recirculatedSpecies"); + + + // Constructors + + //- Construct from patch, internal field and dictionary + recirculatedSpeciesFvPatchScalarField + ( + const fvPatch&, + const DimensionedField&, + const dictionary& + ); + + //- Construct by mapping given fixedValueTypeFvPatchField + // onto a new patch + recirculatedSpeciesFvPatchScalarField + ( + const recirculatedSpeciesFvPatchScalarField&, + const fvPatch&, + const DimensionedField&, + const fieldMapper& + ); + + //- Disallow copy without setting internal field reference + recirculatedSpeciesFvPatchScalarField + ( + const recirculatedSpeciesFvPatchScalarField& + ) = delete; + + //- Copy constructor setting internal field reference + recirculatedSpeciesFvPatchScalarField + ( + const recirculatedSpeciesFvPatchScalarField&, + const DimensionedField& + ); + + //- Construct and return a clone setting internal field reference + virtual tmp clone + ( + const DimensionedField& iF + ) const + { + return tmp + ( + new recirculatedSpeciesFvPatchScalarField + ( + *this, + iF + ) + ); + } + + + // Member Functions + + // Mapping functions + + //- Map the given fvPatchField onto this fvPatchField + virtual void map(const fvPatchScalarField&, const fieldMapper&); + + //- Reset the fvPatchField to the given fvPatchField + // Used for mesh to mesh mapping + virtual void reset(const fvPatchScalarField&); + + + // Evaluation functions + + //- Update the coefficients associated with the patch field + virtual void updateCoeffs(); + + + //- Write + virtual void write(Ostream&) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + + +#endif + +// ************************************************************************* // diff --git a/OFsolvers/OF13/birdmultiphaseEuler/fvConstraints/limitCourant/Make/files b/OFsolvers/OF13/birdmultiphaseEuler/fvConstraints/limitCourant/Make/files new file mode 100644 index 00000000..7ca93fa5 --- /dev/null +++ b/OFsolvers/OF13/birdmultiphaseEuler/fvConstraints/limitCourant/Make/files @@ -0,0 +1,3 @@ +limitCourant.C + +LIB = $(FOAM_USER_LIBBIN)/liblimitCourant diff --git a/OFsolvers/OF13/birdmultiphaseEuler/fvConstraints/limitCourant/Make/options b/OFsolvers/OF13/birdmultiphaseEuler/fvConstraints/limitCourant/Make/options new file mode 100644 index 00000000..a3ae8da8 --- /dev/null +++ b/OFsolvers/OF13/birdmultiphaseEuler/fvConstraints/limitCourant/Make/options @@ -0,0 +1,7 @@ +EXE_INC = \ + -I$(LIB_SRC)/finiteVolume/lnInclude \ + -I$(LIB_SRC)/meshTools/lnInclude + +LIB_LIBS = \ + -lfiniteVolume \ + -lmeshTools diff --git a/OFsolvers/OF13/birdmultiphaseEuler/fvConstraints/limitCourant/limitCourant.C b/OFsolvers/OF13/birdmultiphaseEuler/fvConstraints/limitCourant/limitCourant.C new file mode 100644 index 00000000..37b62844 --- /dev/null +++ b/OFsolvers/OF13/birdmultiphaseEuler/fvConstraints/limitCourant/limitCourant.C @@ -0,0 +1,191 @@ + +#include "limitCourant.H" +#include "IOMRFZoneList.H" +#include "fvcReconstruct.H" +#include "addToRunTimeSelectionTable.H" + + +namespace Foam +{ +namespace fv +{ + defineTypeNameAndDebug(limitCourant, 0); + addToRunTimeSelectionTable + ( + fvConstraint, + limitCourant, + dictionary + ); +} +} + + +void Foam::fv::limitCourant::readCoeffs(const dictionary& dict) +{ + if (dict.found("fields")) + { + fieldNames_ = dict.lookup("fields"); + } + else + { + fieldNames_ = wordList(1, dict.lookup("field")); + } + + maxCo_ = dict.lookup("maxCo"); + MRF_ = dict.lookupOrDefault("MRF", true); + report_ = dict.lookupOrDefault("report", true); +} + + +Foam::fv::limitCourant::limitCourant +( + const word& name, + const word& modelType, + const fvMesh& mesh, + const dictionary& dict +) +: + fvConstraint(name, modelType, mesh, dict), + zone_(mesh, coeffs(dict)), + fieldNames_(), + maxCo_(great), + MRF_(true), + report_(true) +{ + readCoeffs(coeffs(dict)); +} + + +Foam::wordList Foam::fv::limitCourant::constrainedFields() const +{ + return fieldNames_; +} + + +bool Foam::fv::limitCourant::constrain(volVectorField& U) const +{ + const fvMesh& mesh = this->mesh(); + const scalar deltaT = mesh.time().deltaTValue(); + + // Velocity relative to the computational frame + volVectorField Urel(IOobject::groupName("limitCourantUrel", U.group()), U); + + if (MRF_ && mesh.foundObject("MRFProperties")) + { + mesh.lookupObject("MRFProperties").makeRelative(Urel); + } + + if (mesh.moving()) + { + Urel.primitiveFieldRef() -= fvc::reconstruct(mesh.phi())().primitiveField(); + } + + const vectorField& Urelc = Urel.primitiveField(); + + // Sum of |U_rel . S_f| over the faces of each cell + scalarField sumMagUSf(mesh.nCells(), 0); + + const labelUList& own = mesh.owner(); + const labelUList& nei = mesh.neighbour(); + const vectorField& Sf = mesh.Sf().primitiveField(); + + forAll(own, facei) + { + sumMagUSf[own[facei]] += mag(Urelc[own[facei]] & Sf[facei]); + sumMagUSf[nei[facei]] += mag(Urelc[nei[facei]] & Sf[facei]); + } + + forAll(mesh.boundary(), patchi) + { + const labelUList& faceCells = mesh.boundary()[patchi].faceCells(); + const vectorField& Sfp = mesh.Sf().boundaryField()[patchi]; + + forAll(Sfp, i) + { + sumMagUSf[faceCells[i]] += mag(Urelc[faceCells[i]] & Sfp[i]); + } + } + + // Clip + const scalarField& V = mesh.V(); + vectorField& Uc = U.primitiveFieldRef(); + + const labelList& cells = zone_.zone(); + + label nClipped = 0; + scalar maxCoFound = 0; + + forAll(cells, i) + { + const label celli = cells[i]; + const scalar Co = 0.5*deltaT*sumMagUSf[celli]/V[celli]; + + maxCoFound = max(maxCoFound, Co); + + if (Co > maxCo_) + { + // U = U_frame + s U_rel, with U_frame = U - U_rel + Uc[celli] -= (1 - maxCo_/Co)*Urelc[celli]; + nClipped++; + } + } + + U.correctBoundaryConditions(); + + if (report_) + { + reduce(nClipped, sumOp