From 05e0749d0e493a6cf94697e5468d264bf6593afc Mon Sep 17 00:00:00 2001 From: Andrew Heather <> Date: Thu, 13 May 2021 09:28:19 +0100 Subject: [PATCH 1/2] ENH: Added under-relaxation to jump conditions Currently only applied to the fanFvPatchField, e.g. plane { type fan; patchType cyclic; jump uniform 0; value uniform 0; uniformJump false; // Optional under-relaxation relax 0.2; ... } --- .../derived/fan/fanFvPatchFields.C | 6 +- .../derived/fixedJump/fixedJumpFvPatchField.C | 96 +++++++++++++++++-- .../derived/fixedJump/fixedJumpFvPatchField.H | 20 ++++ .../uniformJump/uniformJumpFvPatchField.C | 2 +- 4 files changed, 111 insertions(+), 13 deletions(-) diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchFields.C b/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchFields.C index c404004e31..c1d7c10054 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. @@ -80,6 +80,8 @@ void Foam::fanFvPatchField::calcFanJump() { this->jump_ = this->jumpTable_->value(Un); } + + this->relax(); } } @@ -94,7 +96,7 @@ Foam::fanFvPatchField::fanFvPatchField const dictionary& dict ) : - uniformJumpFvPatchField(p, iF), + uniformJumpFvPatchField(p, iF, dict), phiName_(dict.getOrDefault("phi", "phi")), rhoName_(dict.getOrDefault("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 1b23bef434..49fdedd3be 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,10 @@ Foam::fixedJumpFvPatchField::fixedJumpFvPatchField ) : jumpCyclicFvPatchField(p, iF), - jump_(this->size(), Zero) + jump_(this->size(), Zero), + jump0_(this->size(), Zero), + relaxFactor_(-1), + timeIndex_(-1) {} @@ -51,7 +55,10 @@ Foam::fixedJumpFvPatchField::fixedJumpFvPatchField ) : jumpCyclicFvPatchField(ptf, p, iF, mapper), - jump_(ptf.jump_, mapper) + jump_(ptf.jump_, mapper), + jump0_(ptf.jump0_, mapper), + relaxFactor_(ptf.relaxFactor_), + timeIndex_(ptf.timeIndex_) {} @@ -63,12 +70,20 @@ Foam::fixedJumpFvPatchField::fixedJumpFvPatchField const dictionary& dict ) : - jumpCyclicFvPatchField(p, iF), - jump_(p.size(), Zero) + jumpCyclicFvPatchField(p, iF, dict), + jump_(p.size(), Zero), + jump0_(p.size(), Zero), + relaxFactor_(dict.getOrDefault("relax", -1)), + timeIndex_(this->db().time().timeIndex()) { if (this->cyclicPatch().owner()) { jump_ = Field("jump", dict, p.size()); + + if (dict.found("jump0")) + { + jump0_ = Field("jump0", dict, p.size()); + } } if (dict.found("value")) @@ -92,7 +107,10 @@ Foam::fixedJumpFvPatchField::fixedJumpFvPatchField ) : jumpCyclicFvPatchField(ptf), - jump_(ptf.jump_) + jump_(ptf.jump_), + jump0_(ptf.jump0_), + relaxFactor_(ptf.relaxFactor_), + timeIndex_(ptf.timeIndex_) {} @@ -104,7 +122,10 @@ Foam::fixedJumpFvPatchField::fixedJumpFvPatchField ) : jumpCyclicFvPatchField(ptf, iF), - jump_(ptf.jump_) + jump_(ptf.jump_), + jump0_(ptf.jump0_), + relaxFactor_(ptf.relaxFactor_), + timeIndex_(ptf.timeIndex_) {} @@ -127,6 +148,49 @@ Foam::tmp> Foam::fixedJumpFvPatchField::jump() const } +template +Foam::tmp> Foam::fixedJumpFvPatchField::jump0() const +{ + if (this->cyclicPatch().owner()) + { + return jump0_; + } + else + { + return refCast> + ( + this->neighbourPatchField() + ).jump0(); + } +} + + +template +Foam::scalar Foam::fixedJumpFvPatchField::relaxFactor() const +{ + return relaxFactor_; +} + + +template +void Foam::fixedJumpFvPatchField::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 void Foam::fixedJumpFvPatchField::autoMap ( @@ -135,6 +199,7 @@ void Foam::fixedJumpFvPatchField::autoMap { jumpCyclicFvPatchField::autoMap(m); jump_.autoMap(m); + jump0_.autoMap(m); } @@ -147,9 +212,9 @@ void Foam::fixedJumpFvPatchField::rmap { jumpCyclicFvPatchField::rmap(ptf, addr); - const fixedJumpFvPatchField& tiptf = - refCast>(ptf); - jump_.rmap(tiptf.jump_, addr); + const auto& fjptf = refCast>(ptf); + jump_.rmap(fjptf.jump_, addr); + jump0_.rmap(fjptf.jump0_, addr); } @@ -157,11 +222,22 @@ template void Foam::fixedJumpFvPatchField::write(Ostream& os) const { fvPatchField::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); + } } 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 db10041f52..baef3236e6 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,7 @@ 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 | \endtable Example of the boundary condition specification: @@ -93,6 +95,15 @@ protected: //- "jump" field Field jump_; + //- "jump" field at old time level + Field jump0_; + + //- Under-relaxation factor + scalar relaxFactor_; + + //- Time index + label timeIndex_; + public: @@ -168,6 +179,15 @@ public: //- Return the "jump" across the patch virtual tmp> jump() const; + //- Return the old time "jump" across the patch + virtual tmp> 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/uniformJump/uniformJumpFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/uniformJump/uniformJumpFvPatchField.C index 94bdd0c9ac..74ae08f31b 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::uniformJumpFvPatchField const dictionary& dict ) : - fixedJumpFvPatchField(p, iF), + fixedJumpFvPatchField(p, iF, dict), jumpTable_() { if (this->cyclicPatch().owner()) From f54b190f319a8a07fef208d25c64a9ad02f7f529 Mon Sep 17 00:00:00 2001 From: Andrew Heather <> Date: Mon, 17 May 2021 16:03:20 +0100 Subject: [PATCH 2/2] ENH: Jump conditions - added optional minimum jump value Example: plane { type fan; patchType cyclic; jump uniform 0; value uniform 0; uniformJump false; relax 0.2; jumpTable ( (1000 0) (-200 1) (20 2) (-0.75 3) ); // Optional minimum jump value minJump 0; } --- .../porousBafflePressureFvPatchField.C | 13 +++++--- .../derived/fan/fanFvPatchFields.C | 4 +-- .../derived/fixedJump/fixedJumpFvPatchField.C | 30 +++++++++++++++++++ .../derived/fixedJump/fixedJumpFvPatchField.H | 15 ++++++++-- .../swirlFanVelocityFvPatchField.C | 2 +- .../uniformJump/uniformJumpFvPatchField.C | 2 +- .../energyJump/energyJumpFvPatchScalarField.C | 2 +- 7 files changed, 56 insertions(+), 12 deletions(-) diff --git a/src/TurbulenceModels/turbulenceModels/derivedFvPatchFields/porousBafflePressure/porousBafflePressureFvPatchField.C b/src/TurbulenceModels/turbulenceModels/derivedFvPatchFields/porousBafflePressure/porousBafflePressureFvPatchField.C index 7fe6149034..4a84834687 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(rhoName_); + setJump + ( + jump()*patch().lookupPatchField(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 c1d7c10054..53ec3fac7f 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchFields.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/fan/fanFvPatchFields.C @@ -74,11 +74,11 @@ void Foam::fanFvPatchField::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(); diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fixedJump/fixedJumpFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/fixedJump/fixedJumpFvPatchField.C index 49fdedd3be..d96fe62121 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/fixedJump/fixedJumpFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/fixedJump/fixedJumpFvPatchField.C @@ -40,6 +40,7 @@ Foam::fixedJumpFvPatchField::fixedJumpFvPatchField jumpCyclicFvPatchField(p, iF), jump_(this->size(), Zero), jump0_(this->size(), Zero), + minJump_(pTraits::min), relaxFactor_(-1), timeIndex_(-1) {} @@ -57,6 +58,7 @@ Foam::fixedJumpFvPatchField::fixedJumpFvPatchField jumpCyclicFvPatchField(ptf, p, iF, mapper), jump_(ptf.jump_, mapper), jump0_(ptf.jump0_, mapper), + minJump_(ptf.minJump_), relaxFactor_(ptf.relaxFactor_), timeIndex_(ptf.timeIndex_) {} @@ -73,6 +75,7 @@ Foam::fixedJumpFvPatchField::fixedJumpFvPatchField jumpCyclicFvPatchField(p, iF, dict), jump_(p.size(), Zero), jump0_(p.size(), Zero), + minJump_(dict.getOrDefault("minJump", pTraits::min)), relaxFactor_(dict.getOrDefault("relax", -1)), timeIndex_(this->db().time().timeIndex()) { @@ -109,6 +112,7 @@ Foam::fixedJumpFvPatchField::fixedJumpFvPatchField jumpCyclicFvPatchField(ptf), jump_(ptf.jump_), jump0_(ptf.jump0_), + minJump_(ptf.minJump_), relaxFactor_(ptf.relaxFactor_), timeIndex_(ptf.timeIndex_) {} @@ -124,6 +128,7 @@ Foam::fixedJumpFvPatchField::fixedJumpFvPatchField jumpCyclicFvPatchField(ptf, iF), jump_(ptf.jump_), jump0_(ptf.jump0_), + minJump_(ptf.minJump_), relaxFactor_(ptf.relaxFactor_), timeIndex_(ptf.timeIndex_) {} @@ -131,6 +136,26 @@ Foam::fixedJumpFvPatchField::fixedJumpFvPatchField // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +template +void Foam::fixedJumpFvPatchField::setJump(const Field& jump) +{ + if (this->cyclicPatch().owner()) + { + jump_ = max(jump, minJump_); + } +} + + +template +void Foam::fixedJumpFvPatchField::setJump(const Type& jump) +{ + if (this->cyclicPatch().owner()) + { + jump_ = max(jump, minJump_); + } +} + + template Foam::tmp> Foam::fixedJumpFvPatchField::jump() const { @@ -240,6 +265,11 @@ void Foam::fixedJumpFvPatchField::write(Ostream& os) const } } + if (minJump_ != pTraits::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 baef3236e6..8c5470782f 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/fixedJump/fixedJumpFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/fixedJump/fixedJumpFvPatchField.H @@ -43,6 +43,7 @@ Usage 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: @@ -88,9 +89,7 @@ class fixedJumpFvPatchField public jumpCyclicFvPatchField { -protected: - - // Protected data + // Private data //- "jump" field Field jump_; @@ -98,6 +97,10 @@ protected: //- "jump" field at old time level Field jump0_; + //- Minimum allowable jump value + Type minJump_; + + //- Under-relaxation factor scalar relaxFactor_; @@ -176,6 +179,12 @@ public: // Access + //- Set the jump field + virtual void setJump(const Field& jump); + + //- Set the jump field (uniform value) + virtual void setJump(const Type& jump); + //- Return the "jump" across the patch virtual tmp> jump() const; diff --git a/src/finiteVolume/fields/fvPatchFields/derived/swirlFanVelocity/swirlFanVelocityFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/swirlFanVelocity/swirlFanVelocityFvPatchField.C index a7bcfd3a20..b75e4b3222 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 74ae08f31b..7575864083 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/uniformJump/uniformJumpFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/uniformJump/uniformJumpFvPatchField.C @@ -120,7 +120,7 @@ void Foam::uniformJumpFvPatchField::updateCoeffs() if (this->cyclicPatch().owner()) { - this->jump_ = jumpTable_->value(this->db().time().value()); + this->setJump(jumpTable_->value(this->db().time().value())); } fixedJumpFvPatchField::updateCoeffs(); diff --git a/src/thermophysicalModels/basic/derivedFvPatchFields/energyJump/energyJump/energyJumpFvPatchScalarField.C b/src/thermophysicalModels/basic/derivedFvPatchFields/energyJump/energyJump/energyJumpFvPatchScalarField.C index 7ccaecc93f..5fd72a0f7f 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::updateCoeffs();