ENH: simplify assign zero for Dimensioned and Geometric fields (#3402)

- regular or forced assignment from `zero` does not need dimension
  checking:

    Old:  U = dimensionedVector(U.dimensions(), Zero);
    New:  U = Zero;

  this eliminates a fair bit of clutter and simplifies new coding
  without losing general dimension checking capabilities.
This commit is contained in:
Mark Olesen
2025-07-28 16:18:22 +02:00
parent a68ed1371f
commit 53af711c6a
60 changed files with 213 additions and 156 deletions

View File

@ -15,11 +15,10 @@ volVectorField U
// Initialise the velocity internal field to zero
// Note: explicitly bypass evaluation of contraint patch overrides
// (e.g. swirlFanVelocity might lookup phi,rho)
//U = dimensionedVector(U.dimensions(), Zero);
//U = Zero;
{
const dimensionedVector dt(U.dimensions(), Zero);
U.internalFieldRef() = dt;
U.boundaryFieldRef() = dt.value();
U.internalFieldRef() = Zero;
U.boundaryFieldRef() = Zero;
}
surfaceScalarField phi

View File

@ -1086,7 +1086,7 @@ void Foam::multiphaseMixtureThermo::solveAlphas
MULES::limitSum(alphaPhiCorrs);
rhoPhi_ = dimensionedScalar(dimensionSet(1, 0, -1, 0, 0), Zero);
rhoPhi_ = Zero;
volScalarField sumAlpha
(

View File

@ -557,7 +557,7 @@ void Foam::radiation::laserDTRM::calculate()
// Reset the field
Q_ == dimensionedScalar(Q_.dimensions(), Zero);
Q_ == Zero;
a_ = absorptionEmission_->a();
e_ = absorptionEmission_->e();

View File

@ -232,7 +232,7 @@
surfaceScalarField mSfGradp("mSfGradp", pEqnIncomp.flux()/rAUf);
phasei = 0;
phi = dimensionedScalar("phi", phi.dimensions(), Zero);
phi = Zero;
for (phaseModel& phase : fluid.phases())
{
@ -261,7 +261,7 @@
mSfGradp = pEqnIncomp.flux()/rAUf;
U = dimensionedVector("U", dimVelocity, Zero);
U = Zero;
phasei = 0;
for (phaseModel& phase : fluid.phases())

View File

@ -626,7 +626,7 @@ void Foam::multiphaseMixture::solveAlphas
MULES::limitSum(alphaPhiCorrs);
rhoPhi_ = dimensionedScalar(dimMass/dimTime, Zero);
rhoPhi_ = Zero;
volScalarField sumAlpha
(

View File

@ -14,6 +14,6 @@ if (!(runTime.timeIndex() % 5))
if (smi < -SMALL)
{
Info<< "Resetting Dcorr to 0" << endl;
Dcorr == dimensionedVector(Dcorr.dimensions(), Zero);
Dcorr == Zero;
}
}