mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: neg(x) instead of '1 - pos0(x)' for less-than 0 check
- fewer operations ENH: replace 'neg(x)*a + pos0(x)*b' with 'lerp(a, b, pos0(x))' - uses pos0 as a 0-1 selector. Fewer operations.
This commit is contained in:
@ -207,7 +207,7 @@ void Foam::CLASS::updateCoeffs()
|
|||||||
const scalarField& phip =
|
const scalarField& phip =
|
||||||
this->patch().template lookupPatchField<surfaceScalarField>("phi");
|
this->patch().template lookupPatchField<surfaceScalarField>("phi");
|
||||||
|
|
||||||
this->valueFraction() = 1.0 - pos0(phip);
|
this->valueFraction() = neg(phip);
|
||||||
|
|
||||||
PARENT::updateCoeffs();
|
PARENT::updateCoeffs();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -113,7 +113,7 @@ tmp<volScalarField> SpalartAllmarasIDDES<BasicTurbulenceModel>::dTilda
|
|||||||
if (fe_)
|
if (fe_)
|
||||||
{
|
{
|
||||||
tmp<volScalarField> fe1 =
|
tmp<volScalarField> fe1 =
|
||||||
2*(pos0(alpha)*pow(expTerm, -11.09) + neg(alpha)*pow(expTerm, -9.));
|
2*lerp(pow(expTerm, -9.), pow(expTerm, -11.09), pos0(alpha));
|
||||||
tmp<volScalarField> fe2 = 1 - max(ft(magGradU), fl(magGradU));
|
tmp<volScalarField> fe2 = 1 - max(ft(magGradU), fl(magGradU));
|
||||||
tmp<volScalarField> fe = max(fe1 - 1, scalar(0))*psi*fe2;
|
tmp<volScalarField> fe = max(fe1 - 1, scalar(0))*psi*fe2;
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ tmp<volScalarField> SpalartAllmarasIDDES<BasicTurbulenceModel>::dTilda
|
|||||||
// Simplified formulation from Gritskevich et al. paper (2011) where fe = 0
|
// Simplified formulation from Gritskevich et al. paper (2011) where fe = 0
|
||||||
return max
|
return max
|
||||||
(
|
(
|
||||||
fdTilda*lRAS + (1 - fdTilda)*lLES,
|
lerp(lLES, lRAS, fdTilda),
|
||||||
dimensionedScalar("SMALL", dimLength, SMALL)
|
dimensionedScalar("SMALL", dimLength, SMALL)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -109,7 +109,7 @@ tmp<volScalarField> kOmegaSSTIDDES<BasicTurbulenceModel>::dTilda
|
|||||||
if (fe_)
|
if (fe_)
|
||||||
{
|
{
|
||||||
tmp<volScalarField> fe1 =
|
tmp<volScalarField> fe1 =
|
||||||
2*(pos0(alpha)*pow(expTerm, -11.09) + neg(alpha)*pow(expTerm, -9.));
|
2*lerp(pow(expTerm, -9.), pow(expTerm, -11.09), pos0(alpha));
|
||||||
tmp<volScalarField> fe2 = 1 - max(ft(magGradU), fl(magGradU));
|
tmp<volScalarField> fe2 = 1 - max(ft(magGradU), fl(magGradU));
|
||||||
tmp<volScalarField> fe = max(fe1 - 1, scalar(0))*fe2;
|
tmp<volScalarField> fe = max(fe1 - 1, scalar(0))*fe2;
|
||||||
|
|
||||||
@ -124,7 +124,7 @@ tmp<volScalarField> kOmegaSSTIDDES<BasicTurbulenceModel>::dTilda
|
|||||||
// Simplified formulation from Gritskevich et al. paper (2011) where fe = 0
|
// Simplified formulation from Gritskevich et al. paper (2011) where fe = 0
|
||||||
return max
|
return max
|
||||||
(
|
(
|
||||||
fdTilda*lRAS + (1 - fdTilda)*lLES,
|
lerp(lLES, lRAS, fdTilda),
|
||||||
dimensionedScalar(dimLength, SMALL)
|
dimensionedScalar(dimLength, SMALL)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -157,7 +157,7 @@ void turbulentMixingLengthDissipationRateInletFvPatchScalarField::updateCoeffs()
|
|||||||
patch().lookupPatchField<surfaceScalarField>(this->phiName_);
|
patch().lookupPatchField<surfaceScalarField>(this->phiName_);
|
||||||
|
|
||||||
this->refValue() = (Cmu75/mixingLength_)*pow(kp, 1.5);
|
this->refValue() = (Cmu75/mixingLength_)*pow(kp, 1.5);
|
||||||
this->valueFraction() = 1.0 - pos0(phip);
|
this->valueFraction() = neg(phip);
|
||||||
|
|
||||||
inletOutletFvPatchScalarField::updateCoeffs();
|
inletOutletFvPatchScalarField::updateCoeffs();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -146,7 +146,7 @@ void turbulentMixingLengthFrequencyInletFvPatchScalarField::updateCoeffs()
|
|||||||
patch().lookupPatchField<surfaceScalarField>(this->phiName_);
|
patch().lookupPatchField<surfaceScalarField>(this->phiName_);
|
||||||
|
|
||||||
this->refValue() = sqrt(kp)/(Cmu25*mixingLength_);
|
this->refValue() = sqrt(kp)/(Cmu25*mixingLength_);
|
||||||
this->valueFraction() = 1.0 - pos0(phip);
|
this->valueFraction() = neg(phip);
|
||||||
|
|
||||||
inletOutletFvPatchScalarField::updateCoeffs();
|
inletOutletFvPatchScalarField::updateCoeffs();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -126,7 +126,7 @@ void Foam::inletOutletFaPatchField<Type>::updateCoeffs()
|
|||||||
const Field<scalar>& phip =
|
const Field<scalar>& phip =
|
||||||
this->patch().template lookupPatchField<edgeScalarField>(phiName_);
|
this->patch().template lookupPatchField<edgeScalarField>(phiName_);
|
||||||
|
|
||||||
this->valueFraction() = 1.0 - pos(phip);
|
this->valueFraction() = neg(phip);
|
||||||
|
|
||||||
mixedFaPatchField<Type>::updateCoeffs();
|
mixedFaPatchField<Type>::updateCoeffs();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -152,7 +152,7 @@ void Foam::SRFFreestreamVelocityFvPatchVectorField::updateCoeffs()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set the inlet-outlet choice based on the direction of the freestream
|
// Set the inlet-outlet choice based on the direction of the freestream
|
||||||
valueFraction() = 1.0 - pos0(refValue() & patch().Sf());
|
valueFraction() = neg(refValue() & patch().Sf());
|
||||||
|
|
||||||
mixedFvPatchField<vector>::updateCoeffs();
|
mixedFvPatchField<vector>::updateCoeffs();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -128,7 +128,7 @@ void Foam::inletOutletFvPatchField<Type>::updateCoeffs()
|
|||||||
const Field<scalar>& phip =
|
const Field<scalar>& phip =
|
||||||
this->patch().template lookupPatchField<surfaceScalarField>(phiName_);
|
this->patch().template lookupPatchField<surfaceScalarField>(phiName_);
|
||||||
|
|
||||||
this->valueFraction() = 1.0 - pos0(phip);
|
this->valueFraction() = neg(phip);
|
||||||
|
|
||||||
mixedFvPatchField<Type>::updateCoeffs();
|
mixedFvPatchField<Type>::updateCoeffs();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -181,8 +181,8 @@ void Foam::inletOutletTotalTemperatureFvPatchScalarField::updateCoeffs()
|
|||||||
scalar gM1ByG = (gamma_ - 1.0)/gamma_;
|
scalar gM1ByG = (gamma_ - 1.0)/gamma_;
|
||||||
|
|
||||||
this->refValue() =
|
this->refValue() =
|
||||||
T0_/(1.0 + 0.5*psip*gM1ByG*(1.0 - pos0(phip))*magSqr(Up));
|
T0_/(1.0 + 0.5*psip*gM1ByG*(neg(phip))*magSqr(Up));
|
||||||
this->valueFraction() = 1.0 - pos0(phip);
|
this->valueFraction() = neg(phip);
|
||||||
|
|
||||||
inletOutletFvPatchScalarField::updateCoeffs();
|
inletOutletFvPatchScalarField::updateCoeffs();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -272,7 +272,12 @@ void Foam::plenumPressureFvPatchScalarField::updateCoeffs()
|
|||||||
// Limit to prevent outflow
|
// Limit to prevent outflow
|
||||||
const scalarField p_new
|
const scalarField p_new
|
||||||
(
|
(
|
||||||
(1.0 - pos0(phi))*t*plenumPressure + pos0(phi)*max(p, plenumPressure)
|
lerp
|
||||||
|
(
|
||||||
|
t*plenumPressure, // Negative phi
|
||||||
|
max(p, plenumPressure), // Positive phi
|
||||||
|
pos0(phi) // 0-1 selector
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Relaxation fraction
|
// Relaxation fraction
|
||||||
@ -280,7 +285,7 @@ void Foam::plenumPressureFvPatchScalarField::updateCoeffs()
|
|||||||
const scalar fraction = oneByFraction < 1.0 ? 1.0 : 1.0/oneByFraction;
|
const scalar fraction = oneByFraction < 1.0 ? 1.0 : 1.0/oneByFraction;
|
||||||
|
|
||||||
// Set the new value
|
// Set the new value
|
||||||
operator==((1.0 - fraction)*p_old + fraction*p_new);
|
operator==(lerp(p_old, p_new, fraction));
|
||||||
fixedValueFvPatchScalarField::updateCoeffs();
|
fixedValueFvPatchScalarField::updateCoeffs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -176,7 +176,7 @@ void Foam::pressureDirectedInletOutletVelocityFvPatchVectorField::updateCoeffs()
|
|||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
valueFraction() = 1.0 - pos0(phip);
|
valueFraction() = neg(phip);
|
||||||
|
|
||||||
mixedFvPatchVectorField::updateCoeffs();
|
mixedFvPatchVectorField::updateCoeffs();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -150,7 +150,7 @@ void Foam::pressureInletOutletParSlipVelocityFvPatchVectorField::updateCoeffs()
|
|||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
valueFraction() = 1.0 - pos0(phip);
|
valueFraction() = neg(phip);
|
||||||
|
|
||||||
mixedFvPatchVectorField::updateCoeffs();
|
mixedFvPatchVectorField::updateCoeffs();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -146,7 +146,7 @@ void Foam::pressureNormalInletOutletVelocityFvPatchVectorField::updateCoeffs()
|
|||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
valueFraction() = 1.0 - pos0(phip);
|
valueFraction() = neg(phip);
|
||||||
|
|
||||||
mixedFvPatchVectorField::updateCoeffs();
|
mixedFvPatchVectorField::updateCoeffs();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -155,7 +155,7 @@ updateCoeffs()
|
|||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
valueFraction() = 1.0 - pos0(phip);
|
valueFraction() = neg(phip);
|
||||||
|
|
||||||
if (alphaName_ != "none")
|
if (alphaName_ != "none")
|
||||||
{
|
{
|
||||||
|
|||||||
@ -215,7 +215,7 @@ void Foam::prghPermeableAlphaTotalPressureFvPatchScalarField::updateSnGrad
|
|||||||
tmp<scalarField> p
|
tmp<scalarField> p
|
||||||
(
|
(
|
||||||
p0_->value(t)
|
p0_->value(t)
|
||||||
- 0.5*rhop*(1.0 - pos0(phip))*magSqr(Up)
|
- 0.5*rhop*(neg(phip))*magSqr(Up)
|
||||||
- rhop*((g.value() & patch().Cf()) - ghRef.value())
|
- rhop*((g.value() & patch().Cf()) - ghRef.value())
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -136,7 +136,7 @@ void Foam::prghTotalHydrostaticPressureFvPatchScalarField::updateCoeffs()
|
|||||||
operator==
|
operator==
|
||||||
(
|
(
|
||||||
ph_rghp
|
ph_rghp
|
||||||
- 0.5*rhop*(1.0 - pos0(phip))*magSqr(Up)
|
- 0.5*rhop*(neg(phip))*magSqr(Up)
|
||||||
);
|
);
|
||||||
|
|
||||||
fixedValueFvPatchScalarField::updateCoeffs();
|
fixedValueFvPatchScalarField::updateCoeffs();
|
||||||
|
|||||||
@ -178,7 +178,7 @@ void Foam::prghTotalPressureFvPatchScalarField::updateCoeffs()
|
|||||||
operator==
|
operator==
|
||||||
(
|
(
|
||||||
p0_
|
p0_
|
||||||
- 0.5*rhop*(1.0 - pos0(phip))*magSqr(Up)
|
- 0.5*rhop*(neg(phip))*magSqr(Up)
|
||||||
- rhop*((g.value() & patch().Cf()) - ghRef.value())
|
- rhop*((g.value() & patch().Cf()) - ghRef.value())
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -178,7 +178,7 @@ void Foam::totalPressureFvPatchScalarField::updateCoeffs
|
|||||||
const auto& rho =
|
const auto& rho =
|
||||||
patch().lookupPatchField<volScalarField>(rhoName_);
|
patch().lookupPatchField<volScalarField>(rhoName_);
|
||||||
|
|
||||||
operator==(p0p - 0.5*rho*(1.0 - pos0(phip))*magSqr(Up));
|
operator==(p0p - 0.5*rho*(neg(phip))*magSqr(Up));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -196,14 +196,14 @@ void Foam::totalPressureFvPatchScalarField::updateCoeffs
|
|||||||
p0p
|
p0p
|
||||||
/pow
|
/pow
|
||||||
(
|
(
|
||||||
(1.0 + 0.5*psip*gM1ByG*(1.0 - pos0(phip))*magSqr(Up)),
|
(1.0 + 0.5*psip*gM1ByG*(neg(phip))*magSqr(Up)),
|
||||||
1.0/gM1ByG
|
1.0/gM1ByG
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
operator==(p0p/(1.0 + 0.5*psip*(1.0 - pos0(phip))*magSqr(Up)));
|
operator==(p0p/(1.0 + 0.5*psip*(neg(phip))*magSqr(Up)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,7 +211,7 @@ void Foam::totalPressureFvPatchScalarField::updateCoeffs
|
|||||||
else if (internalField().dimensions() == dimPressure/dimDensity)
|
else if (internalField().dimensions() == dimPressure/dimDensity)
|
||||||
{
|
{
|
||||||
// Incompressible flow
|
// Incompressible flow
|
||||||
operator==(p0p - 0.5*(1.0 - pos0(phip))*magSqr(Up));
|
operator==(p0p - 0.5*(neg(phip))*magSqr(Up));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -170,7 +170,7 @@ void Foam::totalTemperatureFvPatchScalarField::updateCoeffs()
|
|||||||
|
|
||||||
operator==
|
operator==
|
||||||
(
|
(
|
||||||
T0_/(1.0 + 0.5*psip*gM1ByG*(1.0 - pos0(phip))*magSqr(Up))
|
T0_/(1.0 + 0.5*psip*gM1ByG*(neg(phip))*magSqr(Up))
|
||||||
);
|
);
|
||||||
|
|
||||||
fixedValueFvPatchScalarField::updateCoeffs();
|
fixedValueFvPatchScalarField::updateCoeffs();
|
||||||
|
|||||||
@ -140,7 +140,7 @@ updateCoeffs()
|
|||||||
patch().lookupPatchField<surfaceScalarField>(this->phiName_);
|
patch().lookupPatchField<surfaceScalarField>(this->phiName_);
|
||||||
|
|
||||||
this->refValue() = 1.5*sqr(intensity_)*magSqr(Up);
|
this->refValue() = 1.5*sqr(intensity_)*magSqr(Up);
|
||||||
this->valueFraction() = 1.0 - pos0(phip);
|
this->valueFraction() = neg(phip);
|
||||||
|
|
||||||
inletOutletFvPatchScalarField::updateCoeffs();
|
inletOutletFvPatchScalarField::updateCoeffs();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -157,7 +157,7 @@ void Foam::uniformInletOutletFvPatchField<Type>::updateCoeffs()
|
|||||||
phiName_
|
phiName_
|
||||||
);
|
);
|
||||||
|
|
||||||
this->valueFraction() = 1.0 - pos0(phip);
|
this->valueFraction() = neg(phip);
|
||||||
|
|
||||||
mixedFvPatchField<Type>::updateCoeffs();
|
mixedFvPatchField<Type>::updateCoeffs();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -166,7 +166,7 @@ void Foam::uniformTotalPressureFvPatchScalarField::updateCoeffs
|
|||||||
const auto& rho =
|
const auto& rho =
|
||||||
patch().lookupPatchField<volScalarField>(rhoName_);
|
patch().lookupPatchField<volScalarField>(rhoName_);
|
||||||
|
|
||||||
operator==(p0 - 0.5*rho*(1.0 - pos0(phip))*magSqr(Up));
|
operator==(p0 - 0.5*rho*(neg(phip))*magSqr(Up));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -184,14 +184,14 @@ void Foam::uniformTotalPressureFvPatchScalarField::updateCoeffs
|
|||||||
p0
|
p0
|
||||||
/pow
|
/pow
|
||||||
(
|
(
|
||||||
(1.0 + 0.5*psip*gM1ByG*(1.0 - pos0(phip))*magSqr(Up)),
|
(1.0 + 0.5*psip*gM1ByG*(neg(phip))*magSqr(Up)),
|
||||||
1.0/gM1ByG
|
1.0/gM1ByG
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
operator==(p0/(1.0 + 0.5*psip*(1.0 - pos0(phip))*magSqr(Up)));
|
operator==(p0/(1.0 + 0.5*psip*(neg(phip))*magSqr(Up)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,7 +199,7 @@ void Foam::uniformTotalPressureFvPatchScalarField::updateCoeffs
|
|||||||
else if (internalField().dimensions() == dimPressure/dimDensity)
|
else if (internalField().dimensions() == dimPressure/dimDensity)
|
||||||
{
|
{
|
||||||
// Incompressible flow
|
// Incompressible flow
|
||||||
operator==(p0 - 0.5*(1.0 - pos0(phip))*magSqr(Up));
|
operator==(p0 - 0.5*(neg(phip))*magSqr(Up));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -412,7 +412,7 @@ Foam::scalar Foam::cutFaceAdvect::timeIntegratedArea
|
|||||||
// If all cuttings are in the future but non of them within [0,dt] then
|
// If all cuttings are in the future but non of them within [0,dt] then
|
||||||
// if cell is filling up (Un0 > 0) face must be empty during whole time
|
// if cell is filling up (Un0 > 0) face must be empty during whole time
|
||||||
// interval
|
// interval
|
||||||
tIntArea = magSf * dt * (1 - pos0(Un0));
|
tIntArea = magSf * dt * neg(Un0);
|
||||||
return tIntArea;
|
return tIntArea;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -437,7 +437,7 @@ Foam::scalar Foam::cutFaceAdvect::timeIntegratedArea
|
|||||||
// If Un0 > 0 cell is filling up and it must initially be empty.
|
// If Un0 > 0 cell is filling up and it must initially be empty.
|
||||||
// If Un0 < 0 cell must initially be full(y immersed in fluid A).
|
// If Un0 < 0 cell must initially be full(y immersed in fluid A).
|
||||||
time = firstTime;
|
time = firstTime;
|
||||||
initialArea = magSf * (1.0 - pos0(Un0));
|
initialArea = magSf * neg(Un0);
|
||||||
tIntArea = initialArea * time;
|
tIntArea = initialArea * time;
|
||||||
cutPoints(fPts, pTimes, time, FIIL);
|
cutPoints(fPts, pTimes, time, FIIL);
|
||||||
}
|
}
|
||||||
@ -669,7 +669,7 @@ Foam::scalar Foam::cutFaceAdvect::timeIntegratedArea
|
|||||||
// If all cuttings are in the future but non of them within [0,dt] then
|
// If all cuttings are in the future but non of them within [0,dt] then
|
||||||
// if cell is filling up (Un0 > 0) face must be empty during whole time
|
// if cell is filling up (Un0 > 0) face must be empty during whole time
|
||||||
// interval
|
// interval
|
||||||
tIntArea = magSf * dt * (1 - pos0(Un0));
|
tIntArea = magSf * dt * neg(Un0);
|
||||||
return tIntArea;
|
return tIntArea;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -694,7 +694,7 @@ Foam::scalar Foam::cutFaceAdvect::timeIntegratedArea
|
|||||||
// If Un0 > 0 cell is filling up and it must initially be empty.
|
// If Un0 > 0 cell is filling up and it must initially be empty.
|
||||||
// If Un0 < 0 cell must initially be full(y immersed in fluid A).
|
// If Un0 < 0 cell must initially be full(y immersed in fluid A).
|
||||||
time = firstTime;
|
time = firstTime;
|
||||||
initialArea = magSf * (1.0 - pos0(Un0));
|
initialArea = magSf * neg(Un0);
|
||||||
tIntArea = initialArea * time;
|
tIntArea = initialArea * time;
|
||||||
cutPoints(faceI, time, FIIL);
|
cutPoints(faceI, time, FIIL);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user