diff --git a/src/TurbulenceModels/turbulenceModels/derivedFvPatchFields/porousBafflePressure/porousBafflePressureFvPatchField.C b/src/TurbulenceModels/turbulenceModels/derivedFvPatchFields/porousBafflePressure/porousBafflePressureFvPatchField.C index 7fe6149034873a4ceb3c85d820d248b323a90670..4a84834687dda1d0cd8f6f94b95b310f2e4e739a 100644 --- a/src/TurbulenceModels/turbulenceModels/derivedFvPatchFields/porousBafflePressure/porousBafflePressureFvPatchField.C +++ b/src/TurbulenceModels/turbulenceModels/derivedFvPatchFields/porousBafflePressure/porousBafflePressureFvPatchField.C @@ -162,21 +162,26 @@ void Foam::porousBafflePressureFvPatchField::updateCoeffs() const scalar D = D_->value(t); const scalar I = I_->value(t); - jump_ = + setJump + ( -sign(Un) *( D*turbModel.nu(patch().index()) + I*0.5*magUn - )*magUn*length_; + )*magUn*length_ + ); if (internalField().dimensions() == dimPressure) { - jump_ *= patch().lookupPatchField<volScalarField, scalar>(rhoName_); + setJump + ( + jump()*patch().lookupPatchField<volScalarField, scalar>(rhoName_) + ); } if (debug) { - scalar avePressureJump = gAverage(jump_); + scalar avePressureJump = gAverage(jump()); scalar aveVelocity = gAverage(Un); Info<< patch().boundaryMesh().mesh().name() << ':' diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchFields.C b/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchFields.C index c404004e312d784acf7669e1d21da73f1b1bd04f..53ec3fac7f612a07b0941e085bc5683a56101560 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchFields.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchFields.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2017-2020 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -74,12 +74,14 @@ void Foam::fanFvPatchField<Foam::scalar>::calcFanJump() deltap*pow4(constant::mathematical::pi)*sqr(dm_*rpm_)/1800.0 ); - this->jump_ = pdFan; + this->setJump(pdFan); } else { - this->jump_ = this->jumpTable_->value(Un); + this->setJump(jumpTable_->value(Un)); } + + this->relax(); } } @@ -94,7 +96,7 @@ Foam::fanFvPatchField<Foam::scalar>::fanFvPatchField const dictionary& dict ) : - uniformJumpFvPatchField<scalar>(p, iF), + uniformJumpFvPatchField<scalar>(p, iF, dict), phiName_(dict.getOrDefault<word>("phi", "phi")), rhoName_(dict.getOrDefault<word>("rho", "rho")), uniformJump_(dict.getOrDefault("uniformJump", false)), diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fixedJump/fixedJumpFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/fixedJump/fixedJumpFvPatchField.C index 1b23bef43484058b7f073cd6468c6775d7290127..d96fe62121335dc6f94de1ea0f5e4f4bce19927c 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/fixedJump/fixedJumpFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/fixedJump/fixedJumpFvPatchField.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation + Copyright (C) 2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -37,7 +38,11 @@ Foam::fixedJumpFvPatchField<Type>::fixedJumpFvPatchField ) : jumpCyclicFvPatchField<Type>(p, iF), - jump_(this->size(), Zero) + jump_(this->size(), Zero), + jump0_(this->size(), Zero), + minJump_(pTraits<Type>::min), + relaxFactor_(-1), + timeIndex_(-1) {} @@ -51,7 +56,11 @@ Foam::fixedJumpFvPatchField<Type>::fixedJumpFvPatchField ) : jumpCyclicFvPatchField<Type>(ptf, p, iF, mapper), - jump_(ptf.jump_, mapper) + jump_(ptf.jump_, mapper), + jump0_(ptf.jump0_, mapper), + minJump_(ptf.minJump_), + relaxFactor_(ptf.relaxFactor_), + timeIndex_(ptf.timeIndex_) {} @@ -63,12 +72,21 @@ Foam::fixedJumpFvPatchField<Type>::fixedJumpFvPatchField const dictionary& dict ) : - jumpCyclicFvPatchField<Type>(p, iF), - jump_(p.size(), Zero) + jumpCyclicFvPatchField<Type>(p, iF, dict), + jump_(p.size(), Zero), + jump0_(p.size(), Zero), + minJump_(dict.getOrDefault<Type>("minJump", pTraits<Type>::min)), + relaxFactor_(dict.getOrDefault<scalar>("relax", -1)), + timeIndex_(this->db().time().timeIndex()) { if (this->cyclicPatch().owner()) { jump_ = Field<Type>("jump", dict, p.size()); + + if (dict.found("jump0")) + { + jump0_ = Field<Type>("jump0", dict, p.size()); + } } if (dict.found("value")) @@ -92,7 +110,11 @@ Foam::fixedJumpFvPatchField<Type>::fixedJumpFvPatchField ) : jumpCyclicFvPatchField<Type>(ptf), - jump_(ptf.jump_) + jump_(ptf.jump_), + jump0_(ptf.jump0_), + minJump_(ptf.minJump_), + relaxFactor_(ptf.relaxFactor_), + timeIndex_(ptf.timeIndex_) {} @@ -104,12 +126,36 @@ Foam::fixedJumpFvPatchField<Type>::fixedJumpFvPatchField ) : jumpCyclicFvPatchField<Type>(ptf, iF), - jump_(ptf.jump_) + jump_(ptf.jump_), + jump0_(ptf.jump0_), + minJump_(ptf.minJump_), + relaxFactor_(ptf.relaxFactor_), + timeIndex_(ptf.timeIndex_) {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +template<class Type> +void Foam::fixedJumpFvPatchField<Type>::setJump(const Field<Type>& jump) +{ + if (this->cyclicPatch().owner()) + { + jump_ = max(jump, minJump_); + } +} + + +template<class Type> +void Foam::fixedJumpFvPatchField<Type>::setJump(const Type& jump) +{ + if (this->cyclicPatch().owner()) + { + jump_ = max(jump, minJump_); + } +} + + template<class Type> Foam::tmp<Foam::Field<Type>> Foam::fixedJumpFvPatchField<Type>::jump() const { @@ -127,6 +173,49 @@ Foam::tmp<Foam::Field<Type>> Foam::fixedJumpFvPatchField<Type>::jump() const } +template<class Type> +Foam::tmp<Foam::Field<Type>> Foam::fixedJumpFvPatchField<Type>::jump0() const +{ + if (this->cyclicPatch().owner()) + { + return jump0_; + } + else + { + return refCast<const fixedJumpFvPatchField<Type>> + ( + this->neighbourPatchField() + ).jump0(); + } +} + + +template<class Type> +Foam::scalar Foam::fixedJumpFvPatchField<Type>::relaxFactor() const +{ + return relaxFactor_; +} + + +template<class Type> +void Foam::fixedJumpFvPatchField<Type>::relax() +{ + if (!this->cyclicPatch().owner() || relaxFactor_ < 0) + { + return; + } + + jump_ = relaxFactor_*jump_ + (1 - relaxFactor_)*jump0_; + + if (timeIndex_ != this->db().time().timeIndex()) + { + jump0_ = jump_; + + timeIndex_ = this->db().time().timeIndex(); + } +} + + template<class Type> void Foam::fixedJumpFvPatchField<Type>::autoMap ( @@ -135,6 +224,7 @@ void Foam::fixedJumpFvPatchField<Type>::autoMap { jumpCyclicFvPatchField<Type>::autoMap(m); jump_.autoMap(m); + jump0_.autoMap(m); } @@ -147,9 +237,9 @@ void Foam::fixedJumpFvPatchField<Type>::rmap { jumpCyclicFvPatchField<Type>::rmap(ptf, addr); - const fixedJumpFvPatchField<Type>& tiptf = - refCast<const fixedJumpFvPatchField<Type>>(ptf); - jump_.rmap(tiptf.jump_, addr); + const auto& fjptf = refCast<const fixedJumpFvPatchField<Type>>(ptf); + jump_.rmap(fjptf.jump_, addr); + jump0_.rmap(fjptf.jump0_, addr); } @@ -157,11 +247,27 @@ template<class Type> void Foam::fixedJumpFvPatchField<Type>::write(Ostream& os) const { fvPatchField<Type>::write(os); - os.writeEntry("patchType", this->interfaceFieldType()); + + // Write patchType if not done already by fvPatchField + if (!this->patchType().size()) + { + os.writeEntry("patchType", this->interfaceFieldType()); + } if (this->cyclicPatch().owner()) { jump_.writeEntry("jump", os); + + if (relaxFactor_ > 0) + { + os.writeEntry("relax", relaxFactor_); + jump0_.writeEntry("jump0", os); + } + } + + if (minJump_ != pTraits<Type>::min) + { + os.writeEntry("minJump", minJump_); } this->writeEntry("value", os); diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fixedJump/fixedJumpFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/fixedJump/fixedJumpFvPatchField.H index db10041f52464a9142d22b82e2a9a465e9cbb8ba..8c5470782f523850d455846c6b20c904dd869e77 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/fixedJump/fixedJumpFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/fixedJump/fixedJumpFvPatchField.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -41,6 +42,8 @@ Usage Property | Description | Required | Default value patchType | underlying patch type should be \c cyclic| yes | jump | current jump value | yes | + relax | under-relaxation factor | no | + minJump | Minimum jump value | no | \endtable Example of the boundary condition specification: @@ -86,13 +89,24 @@ class fixedJumpFvPatchField public jumpCyclicFvPatchField<Type> { -protected: - - // Protected data + // Private data //- "jump" field Field<Type> jump_; + //- "jump" field at old time level + Field<Type> jump0_; + + //- Minimum allowable jump value + Type minJump_; + + + //- Under-relaxation factor + scalar relaxFactor_; + + //- Time index + label timeIndex_; + public: @@ -165,9 +179,24 @@ public: // Access + //- Set the jump field + virtual void setJump(const Field<Type>& jump); + + //- Set the jump field (uniform value) + virtual void setJump(const Type& jump); + //- Return the "jump" across the patch virtual tmp<Field<Type>> jump() const; + //- Return the old time "jump" across the patch + virtual tmp<Field<Type>> jump0() const; + + //- Return the under-relaxation factor + virtual scalar relaxFactor() const; + + //- Return the relaxed "jump" across the patch + virtual void relax(); + // Mapping functions diff --git a/src/finiteVolume/fields/fvPatchFields/derived/swirlFanVelocity/swirlFanVelocityFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/swirlFanVelocity/swirlFanVelocityFvPatchField.C index a7bcfd3a20f7af86140716d3086c7bc65561ba4f..b75e4b32225882ce9d20512127f095c166b68bde 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/swirlFanVelocity/swirlFanVelocityFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/swirlFanVelocity/swirlFanVelocityFvPatchField.C @@ -104,7 +104,7 @@ void Foam::swirlFanVelocityFvPatchField::calcFanJump() // Calculate the tangential velocity const vectorField tangentialVelocity(magTangU*tanDir); - this->jump_ = tangentialVelocity; + this->setJump(tangentialVelocity); } } diff --git a/src/finiteVolume/fields/fvPatchFields/derived/uniformJump/uniformJumpFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/uniformJump/uniformJumpFvPatchField.C index 94bdd0c9acf73ee543a071c6b88aa1c2d680ff34..75758640834b61990e897521b0b43c1259dbb648 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/uniformJump/uniformJumpFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/uniformJump/uniformJumpFvPatchField.C @@ -63,7 +63,7 @@ Foam::uniformJumpFvPatchField<Type>::uniformJumpFvPatchField const dictionary& dict ) : - fixedJumpFvPatchField<Type>(p, iF), + fixedJumpFvPatchField<Type>(p, iF, dict), jumpTable_() { if (this->cyclicPatch().owner()) @@ -120,7 +120,7 @@ void Foam::uniformJumpFvPatchField<Type>::updateCoeffs() if (this->cyclicPatch().owner()) { - this->jump_ = jumpTable_->value(this->db().time().value()); + this->setJump(jumpTable_->value(this->db().time().value())); } fixedJumpFvPatchField<Type>::updateCoeffs(); diff --git a/src/thermophysicalModels/basic/derivedFvPatchFields/energyJump/energyJump/energyJumpFvPatchScalarField.C b/src/thermophysicalModels/basic/derivedFvPatchFields/energyJump/energyJump/energyJumpFvPatchScalarField.C index 7ccaecc93f5051c3a022d2e9e8537ebd4172cc46..5fd72a0f7fde9cf58fa303b5071a456fa5eea234 100644 --- a/src/thermophysicalModels/basic/derivedFvPatchFields/energyJump/energyJump/energyJumpFvPatchScalarField.C +++ b/src/thermophysicalModels/basic/derivedFvPatchFields/energyJump/energyJump/energyJumpFvPatchScalarField.C @@ -125,7 +125,7 @@ void Foam::energyJumpFvPatchScalarField::updateCoeffs() const labelUList& faceCells = this->patch().faceCells(); - jump_ = thermo.he(pp, Tbp.jump(), faceCells); + setJump(thermo.he(pp, Tbp.jump(), faceCells)); } fixedJumpFvPatchField<scalar>::updateCoeffs();