mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: use lerp for valueFraction (mixed BCs) and field relaxation
Note: in some borderline cases (eg, PDRFoam) the multiplication order and rounding imposed by the lerp function may affect the results slightly. eg, (valueFraction_ * this->patch().deltaCoeffs()*refValue_) vs. (valueFraction_ * (this->patch().deltaCoeffs()*refValue_))
This commit is contained in:
@ -198,12 +198,11 @@ void Foam::mixedFaPatchField<Type>::evaluate(const Pstream::commsTypes)
|
||||
|
||||
Field<Type>::operator=
|
||||
(
|
||||
valueFraction_*refValue_
|
||||
+
|
||||
(1.0 - valueFraction_)*
|
||||
lerp
|
||||
(
|
||||
this->patchInternalField()
|
||||
+ refGrad_/this->patch().deltaCoeffs()
|
||||
this->patchInternalField() + refGrad_/this->patch().deltaCoeffs(),
|
||||
refValue_,
|
||||
valueFraction_
|
||||
)
|
||||
);
|
||||
|
||||
@ -214,11 +213,12 @@ void Foam::mixedFaPatchField<Type>::evaluate(const Pstream::commsTypes)
|
||||
template<class Type>
|
||||
Foam::tmp<Foam::Field<Type>> Foam::mixedFaPatchField<Type>::snGrad() const
|
||||
{
|
||||
return
|
||||
return lerp
|
||||
(
|
||||
refGrad_,
|
||||
(refValue_ - this->patchInternalField())*this->patch().deltaCoeffs(),
|
||||
valueFraction_
|
||||
*(refValue_ - this->patchInternalField())
|
||||
*this->patch().deltaCoeffs()
|
||||
+ (1.0 - valueFraction_)*refGrad_;
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -238,9 +238,12 @@ Foam::tmp<Foam::Field<Type>> Foam::mixedFaPatchField<Type>::valueBoundaryCoeffs
|
||||
const tmp<scalarField>&
|
||||
) const
|
||||
{
|
||||
return
|
||||
valueFraction_*refValue_
|
||||
+ (1.0 - valueFraction_)*refGrad_/this->patch().deltaCoeffs();
|
||||
return lerp
|
||||
(
|
||||
refGrad_/this->patch().deltaCoeffs(),
|
||||
refValue_,
|
||||
valueFraction_
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -256,9 +259,12 @@ template<class Type>
|
||||
Foam::tmp<Foam::Field<Type>>
|
||||
Foam::mixedFaPatchField<Type>::gradientBoundaryCoeffs() const
|
||||
{
|
||||
return
|
||||
valueFraction_*this->patch().deltaCoeffs()*refValue_
|
||||
+ (1.0 - valueFraction_)*refGrad_;
|
||||
return lerp
|
||||
(
|
||||
refGrad_,
|
||||
this->patch().deltaCoeffs()*refValue_,
|
||||
valueFraction_
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -234,25 +234,14 @@ Foam::exprMixedFvPatchField<Type>::exprMixedFvPatchField
|
||||
}
|
||||
else
|
||||
{
|
||||
// Emulate mixedFvPatchField<Type>::evaluate,
|
||||
// Like mixedFvPatchField<Type>::evaluate()
|
||||
// but avoid our own updateCoeffs
|
||||
if (!this->updated())
|
||||
{
|
||||
this->parent_bctype::updateCoeffs();
|
||||
mixedFvPatchField<Type>::updateCoeffs();
|
||||
}
|
||||
|
||||
Field<Type>::operator=
|
||||
(
|
||||
this->valueFraction()*this->refValue()
|
||||
+
|
||||
(1.0 - this->valueFraction())*
|
||||
(
|
||||
this->patchInternalField()
|
||||
+ this->refGrad()/this->patch().deltaCoeffs()
|
||||
)
|
||||
);
|
||||
|
||||
fvPatchField<Type>::evaluate();
|
||||
mixedFvPatchField<Type>::evaluate();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -209,7 +209,6 @@ void Foam::mixedFvPatchField<Type>::rmap
|
||||
template<class Type>
|
||||
void Foam::mixedFvPatchField<Type>::evaluate(const Pstream::commsTypes)
|
||||
{
|
||||
|
||||
if (!this->updated())
|
||||
{
|
||||
this->updateCoeffs();
|
||||
@ -217,11 +216,11 @@ void Foam::mixedFvPatchField<Type>::evaluate(const Pstream::commsTypes)
|
||||
|
||||
Field<Type>::operator=
|
||||
(
|
||||
valueFraction_*refValue_
|
||||
+ (1.0 - valueFraction_)
|
||||
*(
|
||||
this->patchInternalField()
|
||||
+ refGrad_/this->patch().deltaCoeffs()
|
||||
lerp
|
||||
(
|
||||
this->patchInternalField() + refGrad_/this->patch().deltaCoeffs(),
|
||||
refValue_,
|
||||
valueFraction_
|
||||
)
|
||||
);
|
||||
|
||||
@ -233,11 +232,12 @@ template<class Type>
|
||||
Foam::tmp<Foam::Field<Type>>
|
||||
Foam::mixedFvPatchField<Type>::snGrad() const
|
||||
{
|
||||
return
|
||||
return lerp
|
||||
(
|
||||
refGrad_,
|
||||
(refValue_ - this->patchInternalField())*this->patch().deltaCoeffs(),
|
||||
valueFraction_
|
||||
*(refValue_ - this->patchInternalField())
|
||||
*this->patch().deltaCoeffs()
|
||||
+ (1.0 - valueFraction_)*refGrad_;
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -259,9 +259,12 @@ Foam::mixedFvPatchField<Type>::valueBoundaryCoeffs
|
||||
const tmp<scalarField>&
|
||||
) const
|
||||
{
|
||||
return
|
||||
valueFraction_*refValue_
|
||||
+ (1.0 - valueFraction_)*refGrad_/this->patch().deltaCoeffs();
|
||||
return lerp
|
||||
(
|
||||
refGrad_/this->patch().deltaCoeffs(),
|
||||
refValue_,
|
||||
valueFraction_
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -277,9 +280,12 @@ template<class Type>
|
||||
Foam::tmp<Foam::Field<Type>>
|
||||
Foam::mixedFvPatchField<Type>::gradientBoundaryCoeffs() const
|
||||
{
|
||||
return
|
||||
valueFraction_*this->patch().deltaCoeffs()*refValue_
|
||||
+ (1.0 - valueFraction_)*refGrad_;
|
||||
return lerp
|
||||
(
|
||||
refGrad_,
|
||||
this->patch().deltaCoeffs()*refValue_,
|
||||
valueFraction_
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -212,7 +212,7 @@ void Foam::fixedJumpFvPatchField<Type>::relax()
|
||||
return;
|
||||
}
|
||||
|
||||
jump_ = relaxFactor_*jump_ + (1 - relaxFactor_)*jump0_;
|
||||
jump_ = lerp(jump0_, jump_, relaxFactor_);
|
||||
|
||||
if (timeIndex_ != this->db().time().timeIndex())
|
||||
{
|
||||
|
||||
@ -153,8 +153,12 @@ Foam::partialSlipFvPatchField<Type>::snGrad() const
|
||||
|
||||
return
|
||||
(
|
||||
valueFraction_*refValue_
|
||||
+ (1.0 - valueFraction_)*transform(I - sqr(nHat), pif) - pif
|
||||
lerp
|
||||
(
|
||||
transform(I - sqr(nHat), pif),
|
||||
refValue_,
|
||||
valueFraction_
|
||||
) - pif
|
||||
)*this->patch().deltaCoeffs();
|
||||
}
|
||||
|
||||
@ -174,10 +178,12 @@ void Foam::partialSlipFvPatchField<Type>::evaluate
|
||||
|
||||
Field<Type>::operator=
|
||||
(
|
||||
valueFraction_*refValue_
|
||||
+
|
||||
(1.0 - valueFraction_)
|
||||
*transform(I - sqr(nHat), this->patchInternalField())
|
||||
lerp
|
||||
(
|
||||
transform(I - sqr(nHat), this->patchInternalField()),
|
||||
refValue_,
|
||||
valueFraction_
|
||||
)
|
||||
);
|
||||
|
||||
parent_bctype::evaluate();
|
||||
|
||||
@ -180,7 +180,7 @@ void Foam::phaseHydrostaticPressureFvPatchScalarField::operator=
|
||||
{
|
||||
fvPatchScalarField::operator=
|
||||
(
|
||||
valueFraction()*refValue() + (1 - valueFraction())*ptf
|
||||
lerp(ptf, refValue(), valueFraction())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2020 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -204,8 +204,7 @@ void Foam::pressureDirectedInletOutletVelocityFvPatchVectorField::operator=
|
||||
{
|
||||
fvPatchField<vector>::operator=
|
||||
(
|
||||
valueFraction()*(inletDir_*(inletDir_ & pvf))
|
||||
+ (1 - valueFraction())*pvf
|
||||
lerp(pvf, inletDir_*(inletDir_ & pvf), valueFraction())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2020 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -171,10 +171,11 @@ void Foam::pressureNormalInletOutletVelocityFvPatchVectorField::operator=
|
||||
const fvPatchField<vector>& pvf
|
||||
)
|
||||
{
|
||||
tmp<vectorField> n = patch().nf();
|
||||
|
||||
fvPatchField<vector>::operator=
|
||||
(
|
||||
valueFraction()*(patch().nf()*(patch().nf() & pvf))
|
||||
+ (1 - valueFraction())*pvf
|
||||
lerp(pvf, n()*(n() & pvf), valueFraction())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2021 OpenCFD Ltd.
|
||||
Copyright (C) 2021-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -202,8 +202,7 @@ void Foam::pressurePermeableAlphaInletOutletVelocityFvPatchVectorField
|
||||
|
||||
fvPatchField<vector>::operator=
|
||||
(
|
||||
valueFraction()*(n()*(n() & pvf))
|
||||
+ (1 - valueFraction())*pvf
|
||||
lerp(pvf, n()*(n() & pvf), valueFraction())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -317,11 +317,12 @@ void Foam::externalWallHeatFluxTemperatureFvPatchScalarField::updateCoeffs()
|
||||
scalarField qr(Tp.size(), Zero);
|
||||
if (qrName_ != "none")
|
||||
{
|
||||
qr =
|
||||
qr = lerp
|
||||
(
|
||||
qrPrevious_,
|
||||
patch().lookupPatchField<volScalarField>(qrName_),
|
||||
qrRelaxation_
|
||||
*patch().lookupPatchField<volScalarField>(qrName_)
|
||||
+ (1 - qrRelaxation_)*qrPrevious_;
|
||||
|
||||
);
|
||||
qrPrevious_ = qr;
|
||||
}
|
||||
|
||||
@ -454,9 +455,8 @@ void Foam::externalWallHeatFluxTemperatureFvPatchScalarField::updateCoeffs()
|
||||
}
|
||||
}
|
||||
|
||||
valueFraction() =
|
||||
relaxation_*valueFraction() + (1 - relaxation_)*valueFraction0;
|
||||
refValue() = relaxation_*refValue() + (1 - relaxation_)*refValue0;
|
||||
valueFraction() = lerp(valueFraction0, valueFraction(), relaxation_);
|
||||
refValue() = lerp(refValue0, refValue(), relaxation_);
|
||||
|
||||
mixedFvPatchScalarField::updateCoeffs();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user