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:
parent
e1a710014c
commit
70d526cd82
@ -207,7 +207,7 @@ void Foam::CLASS::updateCoeffs()
|
||||
const scalarField& phip =
|
||||
this->patch().template lookupPatchField<surfaceScalarField>("phi");
|
||||
|
||||
this->valueFraction() = 1.0 - pos0(phip);
|
||||
this->valueFraction() = neg(phip);
|
||||
|
||||
PARENT::updateCoeffs();
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ tmp<volScalarField> SpalartAllmarasIDDES<BasicTurbulenceModel>::dTilda
|
||||
if (fe_)
|
||||
{
|
||||
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> 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
|
||||
return max
|
||||
(
|
||||
fdTilda*lRAS + (1 - fdTilda)*lLES,
|
||||
lerp(lLES, lRAS, fdTilda),
|
||||
dimensionedScalar("SMALL", dimLength, SMALL)
|
||||
);
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ tmp<volScalarField> kOmegaSSTIDDES<BasicTurbulenceModel>::dTilda
|
||||
if (fe_)
|
||||
{
|
||||
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> 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
|
||||
return max
|
||||
(
|
||||
fdTilda*lRAS + (1 - fdTilda)*lLES,
|
||||
lerp(lLES, lRAS, fdTilda),
|
||||
dimensionedScalar(dimLength, SMALL)
|
||||
);
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ void turbulentMixingLengthDissipationRateInletFvPatchScalarField::updateCoeffs()
|
||||
patch().lookupPatchField<surfaceScalarField>(this->phiName_);
|
||||
|
||||
this->refValue() = (Cmu75/mixingLength_)*pow(kp, 1.5);
|
||||
this->valueFraction() = 1.0 - pos0(phip);
|
||||
this->valueFraction() = neg(phip);
|
||||
|
||||
inletOutletFvPatchScalarField::updateCoeffs();
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ void turbulentMixingLengthFrequencyInletFvPatchScalarField::updateCoeffs()
|
||||
patch().lookupPatchField<surfaceScalarField>(this->phiName_);
|
||||
|
||||
this->refValue() = sqrt(kp)/(Cmu25*mixingLength_);
|
||||
this->valueFraction() = 1.0 - pos0(phip);
|
||||
this->valueFraction() = neg(phip);
|
||||
|
||||
inletOutletFvPatchScalarField::updateCoeffs();
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ void Foam::inletOutletFaPatchField<Type>::updateCoeffs()
|
||||
const Field<scalar>& phip =
|
||||
this->patch().template lookupPatchField<edgeScalarField>(phiName_);
|
||||
|
||||
this->valueFraction() = 1.0 - pos(phip);
|
||||
this->valueFraction() = neg(phip);
|
||||
|
||||
mixedFaPatchField<Type>::updateCoeffs();
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ void Foam::SRFFreestreamVelocityFvPatchVectorField::updateCoeffs()
|
||||
}
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ void Foam::inletOutletFvPatchField<Type>::updateCoeffs()
|
||||
const Field<scalar>& phip =
|
||||
this->patch().template lookupPatchField<surfaceScalarField>(phiName_);
|
||||
|
||||
this->valueFraction() = 1.0 - pos0(phip);
|
||||
this->valueFraction() = neg(phip);
|
||||
|
||||
mixedFvPatchField<Type>::updateCoeffs();
|
||||
}
|
||||
|
@ -181,8 +181,8 @@ void Foam::inletOutletTotalTemperatureFvPatchScalarField::updateCoeffs()
|
||||
scalar gM1ByG = (gamma_ - 1.0)/gamma_;
|
||||
|
||||
this->refValue() =
|
||||
T0_/(1.0 + 0.5*psip*gM1ByG*(1.0 - pos0(phip))*magSqr(Up));
|
||||
this->valueFraction() = 1.0 - pos0(phip);
|
||||
T0_/(1.0 + 0.5*psip*gM1ByG*(neg(phip))*magSqr(Up));
|
||||
this->valueFraction() = neg(phip);
|
||||
|
||||
inletOutletFvPatchScalarField::updateCoeffs();
|
||||
}
|
||||
|
@ -272,7 +272,12 @@ void Foam::plenumPressureFvPatchScalarField::updateCoeffs()
|
||||
// Limit to prevent outflow
|
||||
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
|
||||
@ -280,7 +285,7 @@ void Foam::plenumPressureFvPatchScalarField::updateCoeffs()
|
||||
const scalar fraction = oneByFraction < 1.0 ? 1.0 : 1.0/oneByFraction;
|
||||
|
||||
// Set the new value
|
||||
operator==((1.0 - fraction)*p_old + fraction*p_new);
|
||||
operator==(lerp(p_old, p_new, fraction));
|
||||
fixedValueFvPatchScalarField::updateCoeffs();
|
||||
}
|
||||
|
||||
|
@ -176,7 +176,7 @@ void Foam::pressureDirectedInletOutletVelocityFvPatchVectorField::updateCoeffs()
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
valueFraction() = 1.0 - pos0(phip);
|
||||
valueFraction() = neg(phip);
|
||||
|
||||
mixedFvPatchVectorField::updateCoeffs();
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ void Foam::pressureInletOutletParSlipVelocityFvPatchVectorField::updateCoeffs()
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
valueFraction() = 1.0 - pos0(phip);
|
||||
valueFraction() = neg(phip);
|
||||
|
||||
mixedFvPatchVectorField::updateCoeffs();
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ void Foam::pressureNormalInletOutletVelocityFvPatchVectorField::updateCoeffs()
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
valueFraction() = 1.0 - pos0(phip);
|
||||
valueFraction() = neg(phip);
|
||||
|
||||
mixedFvPatchVectorField::updateCoeffs();
|
||||
}
|
||||
|
@ -155,7 +155,7 @@ updateCoeffs()
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
valueFraction() = 1.0 - pos0(phip);
|
||||
valueFraction() = neg(phip);
|
||||
|
||||
if (alphaName_ != "none")
|
||||
{
|
||||
|
@ -215,7 +215,7 @@ void Foam::prghPermeableAlphaTotalPressureFvPatchScalarField::updateSnGrad
|
||||
tmp<scalarField> p
|
||||
(
|
||||
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())
|
||||
);
|
||||
|
||||
|
@ -136,7 +136,7 @@ void Foam::prghTotalHydrostaticPressureFvPatchScalarField::updateCoeffs()
|
||||
operator==
|
||||
(
|
||||
ph_rghp
|
||||
- 0.5*rhop*(1.0 - pos0(phip))*magSqr(Up)
|
||||
- 0.5*rhop*(neg(phip))*magSqr(Up)
|
||||
);
|
||||
|
||||
fixedValueFvPatchScalarField::updateCoeffs();
|
||||
|
@ -178,7 +178,7 @@ void Foam::prghTotalPressureFvPatchScalarField::updateCoeffs()
|
||||
operator==
|
||||
(
|
||||
p0_
|
||||
- 0.5*rhop*(1.0 - pos0(phip))*magSqr(Up)
|
||||
- 0.5*rhop*(neg(phip))*magSqr(Up)
|
||||
- rhop*((g.value() & patch().Cf()) - ghRef.value())
|
||||
);
|
||||
|
||||
|
@ -178,7 +178,7 @@ void Foam::totalPressureFvPatchScalarField::updateCoeffs
|
||||
const auto& rho =
|
||||
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
|
||||
{
|
||||
@ -196,14 +196,14 @@ void Foam::totalPressureFvPatchScalarField::updateCoeffs
|
||||
p0p
|
||||
/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
|
||||
)
|
||||
);
|
||||
}
|
||||
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)
|
||||
{
|
||||
// Incompressible flow
|
||||
operator==(p0p - 0.5*(1.0 - pos0(phip))*magSqr(Up));
|
||||
operator==(p0p - 0.5*(neg(phip))*magSqr(Up));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -170,7 +170,7 @@ void Foam::totalTemperatureFvPatchScalarField::updateCoeffs()
|
||||
|
||||
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();
|
||||
|
@ -140,7 +140,7 @@ updateCoeffs()
|
||||
patch().lookupPatchField<surfaceScalarField>(this->phiName_);
|
||||
|
||||
this->refValue() = 1.5*sqr(intensity_)*magSqr(Up);
|
||||
this->valueFraction() = 1.0 - pos0(phip);
|
||||
this->valueFraction() = neg(phip);
|
||||
|
||||
inletOutletFvPatchScalarField::updateCoeffs();
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ void Foam::uniformInletOutletFvPatchField<Type>::updateCoeffs()
|
||||
phiName_
|
||||
);
|
||||
|
||||
this->valueFraction() = 1.0 - pos0(phip);
|
||||
this->valueFraction() = neg(phip);
|
||||
|
||||
mixedFvPatchField<Type>::updateCoeffs();
|
||||
}
|
||||
|
@ -166,7 +166,7 @@ void Foam::uniformTotalPressureFvPatchScalarField::updateCoeffs
|
||||
const auto& rho =
|
||||
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
|
||||
{
|
||||
@ -184,14 +184,14 @@ void Foam::uniformTotalPressureFvPatchScalarField::updateCoeffs
|
||||
p0
|
||||
/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
|
||||
)
|
||||
);
|
||||
}
|
||||
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)
|
||||
{
|
||||
// Incompressible flow
|
||||
operator==(p0 - 0.5*(1.0 - pos0(phip))*magSqr(Up));
|
||||
operator==(p0 - 0.5*(neg(phip))*magSqr(Up));
|
||||
}
|
||||
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 cell is filling up (Un0 > 0) face must be empty during whole time
|
||||
// interval
|
||||
tIntArea = magSf * dt * (1 - pos0(Un0));
|
||||
tIntArea = magSf * dt * neg(Un0);
|
||||
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 must initially be full(y immersed in fluid A).
|
||||
time = firstTime;
|
||||
initialArea = magSf * (1.0 - pos0(Un0));
|
||||
initialArea = magSf * neg(Un0);
|
||||
tIntArea = initialArea * time;
|
||||
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 cell is filling up (Un0 > 0) face must be empty during whole time
|
||||
// interval
|
||||
tIntArea = magSf * dt * (1 - pos0(Un0));
|
||||
tIntArea = magSf * dt * neg(Un0);
|
||||
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 must initially be full(y immersed in fluid A).
|
||||
time = firstTime;
|
||||
initialArea = magSf * (1.0 - pos0(Un0));
|
||||
initialArea = magSf * neg(Un0);
|
||||
tIntArea = initialArea * time;
|
||||
cutPoints(faceI, time, FIIL);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user