Merge branch 'feature-relax-fan-jump' into 'develop'

ENH: Added under-relaxation to jump conditions

See merge request Development/openfoam!467
This commit is contained in:
Sergio Ferraris
2021-06-14 15:34:43 +00:00
7 changed files with 167 additions and 25 deletions

View File

@ -162,21 +162,26 @@ void Foam::porousBafflePressureFvPatchField::updateCoeffs()
const scalar D = D_->value(t); const scalar D = D_->value(t);
const scalar I = I_->value(t); const scalar I = I_->value(t);
jump_ = setJump
(
-sign(Un) -sign(Un)
*( *(
D*turbModel.nu(patch().index()) D*turbModel.nu(patch().index())
+ I*0.5*magUn + I*0.5*magUn
)*magUn*length_; )*magUn*length_
);
if (internalField().dimensions() == dimPressure) if (internalField().dimensions() == dimPressure)
{ {
jump_ *= patch().lookupPatchField<volScalarField, scalar>(rhoName_); setJump
(
jump()*patch().lookupPatchField<volScalarField, scalar>(rhoName_)
);
} }
if (debug) if (debug)
{ {
scalar avePressureJump = gAverage(jump_); scalar avePressureJump = gAverage(jump());
scalar aveVelocity = gAverage(Un); scalar aveVelocity = gAverage(Un);
Info<< patch().boundaryMesh().mesh().name() << ':' Info<< patch().boundaryMesh().mesh().name() << ':'

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2017-2020 OpenCFD Ltd. Copyright (C) 2017-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. 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 deltap*pow4(constant::mathematical::pi)*sqr(dm_*rpm_)/1800.0
); );
this->jump_ = pdFan; this->setJump(pdFan);
} }
else 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 const dictionary& dict
) )
: :
uniformJumpFvPatchField<scalar>(p, iF), uniformJumpFvPatchField<scalar>(p, iF, dict),
phiName_(dict.getOrDefault<word>("phi", "phi")), phiName_(dict.getOrDefault<word>("phi", "phi")),
rhoName_(dict.getOrDefault<word>("rho", "rho")), rhoName_(dict.getOrDefault<word>("rho", "rho")),
uniformJump_(dict.getOrDefault("uniformJump", false)), uniformJump_(dict.getOrDefault("uniformJump", false)),

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -37,7 +38,11 @@ Foam::fixedJumpFvPatchField<Type>::fixedJumpFvPatchField
) )
: :
jumpCyclicFvPatchField<Type>(p, iF), 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), 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 const dictionary& dict
) )
: :
jumpCyclicFvPatchField<Type>(p, iF), jumpCyclicFvPatchField<Type>(p, iF, dict),
jump_(p.size(), Zero) 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()) if (this->cyclicPatch().owner())
{ {
jump_ = Field<Type>("jump", dict, p.size()); jump_ = Field<Type>("jump", dict, p.size());
if (dict.found("jump0"))
{
jump0_ = Field<Type>("jump0", dict, p.size());
}
} }
if (dict.found("value")) if (dict.found("value"))
@ -92,7 +110,11 @@ Foam::fixedJumpFvPatchField<Type>::fixedJumpFvPatchField
) )
: :
jumpCyclicFvPatchField<Type>(ptf), 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), jumpCyclicFvPatchField<Type>(ptf, iF),
jump_(ptf.jump_) jump_(ptf.jump_),
jump0_(ptf.jump0_),
minJump_(ptf.minJump_),
relaxFactor_(ptf.relaxFactor_),
timeIndex_(ptf.timeIndex_)
{} {}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * 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> template<class Type>
Foam::tmp<Foam::Field<Type>> Foam::fixedJumpFvPatchField<Type>::jump() const 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> template<class Type>
void Foam::fixedJumpFvPatchField<Type>::autoMap void Foam::fixedJumpFvPatchField<Type>::autoMap
( (
@ -135,6 +224,7 @@ void Foam::fixedJumpFvPatchField<Type>::autoMap
{ {
jumpCyclicFvPatchField<Type>::autoMap(m); jumpCyclicFvPatchField<Type>::autoMap(m);
jump_.autoMap(m); jump_.autoMap(m);
jump0_.autoMap(m);
} }
@ -147,9 +237,9 @@ void Foam::fixedJumpFvPatchField<Type>::rmap
{ {
jumpCyclicFvPatchField<Type>::rmap(ptf, addr); jumpCyclicFvPatchField<Type>::rmap(ptf, addr);
const fixedJumpFvPatchField<Type>& tiptf = const auto& fjptf = refCast<const fixedJumpFvPatchField<Type>>(ptf);
refCast<const fixedJumpFvPatchField<Type>>(ptf); jump_.rmap(fjptf.jump_, addr);
jump_.rmap(tiptf.jump_, addr); jump0_.rmap(fjptf.jump0_, addr);
} }
@ -157,11 +247,27 @@ template<class Type>
void Foam::fixedJumpFvPatchField<Type>::write(Ostream& os) const void Foam::fixedJumpFvPatchField<Type>::write(Ostream& os) const
{ {
fvPatchField<Type>::write(os); 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()) if (this->cyclicPatch().owner())
{ {
jump_.writeEntry("jump", os); 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); this->writeEntry("value", os);

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -41,6 +42,8 @@ Usage
Property | Description | Required | Default value Property | Description | Required | Default value
patchType | underlying patch type should be \c cyclic| yes | patchType | underlying patch type should be \c cyclic| yes |
jump | current jump value | yes | jump | current jump value | yes |
relax | under-relaxation factor | no |
minJump | Minimum jump value | no |
\endtable \endtable
Example of the boundary condition specification: Example of the boundary condition specification:
@ -86,13 +89,24 @@ class fixedJumpFvPatchField
public jumpCyclicFvPatchField<Type> public jumpCyclicFvPatchField<Type>
{ {
protected: // Private data
// Protected data
//- "jump" field //- "jump" field
Field<Type> jump_; 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: public:
@ -165,9 +179,24 @@ public:
// Access // 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 //- Return the "jump" across the patch
virtual tmp<Field<Type>> jump() const; 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 // Mapping functions

View File

@ -104,7 +104,7 @@ void Foam::swirlFanVelocityFvPatchField::calcFanJump()
// Calculate the tangential velocity // Calculate the tangential velocity
const vectorField tangentialVelocity(magTangU*tanDir); const vectorField tangentialVelocity(magTangU*tanDir);
this->jump_ = tangentialVelocity; this->setJump(tangentialVelocity);
} }
} }

View File

@ -63,7 +63,7 @@ Foam::uniformJumpFvPatchField<Type>::uniformJumpFvPatchField
const dictionary& dict const dictionary& dict
) )
: :
fixedJumpFvPatchField<Type>(p, iF), fixedJumpFvPatchField<Type>(p, iF, dict),
jumpTable_() jumpTable_()
{ {
if (this->cyclicPatch().owner()) if (this->cyclicPatch().owner())
@ -120,7 +120,7 @@ void Foam::uniformJumpFvPatchField<Type>::updateCoeffs()
if (this->cyclicPatch().owner()) if (this->cyclicPatch().owner())
{ {
this->jump_ = jumpTable_->value(this->db().time().value()); this->setJump(jumpTable_->value(this->db().time().value()));
} }
fixedJumpFvPatchField<Type>::updateCoeffs(); fixedJumpFvPatchField<Type>::updateCoeffs();

View File

@ -125,7 +125,7 @@ void Foam::energyJumpFvPatchScalarField::updateCoeffs()
const labelUList& faceCells = this->patch().faceCells(); const labelUList& faceCells = this->patch().faceCells();
jump_ = thermo.he(pp, Tbp.jump(), faceCells); setJump(thermo.he(pp, Tbp.jump(), faceCells));
} }
fixedJumpFvPatchField<scalar>::updateCoeffs(); fixedJumpFvPatchField<scalar>::updateCoeffs();