From 05e0749d0e493a6cf94697e5468d264bf6593afc Mon Sep 17 00:00:00 2001 From: Andrew Heather <> Date: Thu, 13 May 2021 09:28:19 +0100 Subject: [PATCH] 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())