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 // Initialise the velocity internal field to zero
// Note: explicitly bypass evaluation of contraint patch overrides // Note: explicitly bypass evaluation of contraint patch overrides
// (e.g. swirlFanVelocity might lookup phi,rho) // (e.g. swirlFanVelocity might lookup phi,rho)
//U = dimensionedVector(U.dimensions(), Zero); //U = Zero;
{ {
const dimensionedVector dt(U.dimensions(), Zero); U.internalFieldRef() = Zero;
U.internalFieldRef() = dt; U.boundaryFieldRef() = Zero;
U.boundaryFieldRef() = dt.value();
} }
surfaceScalarField phi surfaceScalarField phi

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -70,7 +70,7 @@ static inline bool checkDims
Foam::dimensionSet::dimensionSet() Foam::dimensionSet::dimensionSet()
: :
exponents_(Zero) exponents_(Foam::zero{})
{} {}
@ -142,7 +142,7 @@ Foam::dimensionSet::values() noexcept
void Foam::dimensionSet::clear() void Foam::dimensionSet::clear()
{ {
exponents_ = Zero; exponents_ = Foam::zero{};
} }
@ -166,13 +166,13 @@ Foam::scalar& Foam::dimensionSet::operator[](const dimensionType type)
} }
Foam::scalar Foam::dimensionSet::operator[](const label type) const Foam::scalar Foam::dimensionSet::operator[](const int type) const
{ {
return exponents_[type]; return exponents_[type];
} }
Foam::scalar& Foam::dimensionSet::operator[](const label type) Foam::scalar& Foam::dimensionSet::operator[](const int type)
{ {
return exponents_[type]; return exponents_[type];
} }

View File

@ -329,17 +329,26 @@ public:
scalar operator[](const dimensionType) const; scalar operator[](const dimensionType) const;
scalar& operator[](const dimensionType); scalar& operator[](const dimensionType);
scalar operator[](const label) const; scalar operator[](const int) const;
scalar& operator[](const label); scalar& operator[](const int);
bool operator==(const dimensionSet&) const; bool operator==(const dimensionSet&) const;
bool operator!=(const dimensionSet&) const; bool operator!=(const dimensionSet&) const;
//- Assignment operation, checks for identical dimensions.
//- Use reset() to change the dimensions.
bool operator=(const dimensionSet&) const; bool operator=(const dimensionSet&) const;
//- Addition operation, checks for identical dimensions.
bool operator+=(const dimensionSet&) const; bool operator+=(const dimensionSet&) const;
//- Subtraction operation, checks for identical dimensions.
bool operator-=(const dimensionSet&) const; bool operator-=(const dimensionSet&) const;
//- Multiplication, modifies the exponents.
bool operator*=(const dimensionSet&); bool operator*=(const dimensionSet&);
//- Division, modifies the exponents.
bool operator/=(const dimensionSet&); bool operator/=(const dimensionSet&);
}; };
@ -414,7 +423,7 @@ dimensionSet invTransform(const dimensionSet& ds);
//- The dimensionSet inverted //- The dimensionSet inverted
dimensionSet operator~(const dimensionSet& ds); dimensionSet operator~(const dimensionSet& ds);
//- Unary negation. //- Unary negation; does not change the dimensions
dimensionSet operator-(const dimensionSet& ds); dimensionSet operator-(const dimensionSet& ds);
dimensionSet operator+(const dimensionSet& ds1, const dimensionSet& ds2); dimensionSet operator+(const dimensionSet& ds1, const dimensionSet& ds2);

View File

@ -560,6 +560,13 @@ void Foam::DimensionedField<Type, GeoMesh>::operator=
} }
template<class Type, class GeoMesh>
void Foam::DimensionedField<Type, GeoMesh>::operator=(Foam::zero)
{
Field<Type>::operator=(Foam::zero{});
}
#define COMPUTED_ASSIGNMENT(TYPE, op) \ #define COMPUTED_ASSIGNMENT(TYPE, op) \
\ \
template<class Type, class GeoMesh> \ template<class Type, class GeoMesh> \

View File

@ -631,9 +631,12 @@ public:
void operator=(const DimensionedField<Type, GeoMesh>& df); void operator=(const DimensionedField<Type, GeoMesh>& df);
void operator=(const tmp<DimensionedField<Type, GeoMesh>>& tdf); void operator=(const tmp<DimensionedField<Type, GeoMesh>>& tdf);
//- Assign dimensions and value. //- Assign value (with dimension check)
void operator=(const dimensioned<Type>& dt); void operator=(const dimensioned<Type>& dt);
//- Assign value zero (no dimension checks)
void operator=(Foam::zero);
void operator+=(const DimensionedField<Type, GeoMesh>& df); void operator+=(const DimensionedField<Type, GeoMesh>& df);
void operator+=(const tmp<DimensionedField<Type, GeoMesh>>& tdf); void operator+=(const tmp<DimensionedField<Type, GeoMesh>>& tdf);

View File

@ -450,9 +450,9 @@ void FieldField<Field, Type>::operator=(const tmp<FieldField>& tf)
template<template<class> class Field, class Type> template<template<class> class Field, class Type>
void FieldField<Field, Type>::operator=(const Type& val) void FieldField<Field, Type>::operator=(const Type& val)
{ {
forAll(*this, i) for (auto& pfld : *this)
{ {
this->operator[](i) = val; pfld = val;
} }
} }
@ -460,9 +460,9 @@ void FieldField<Field, Type>::operator=(const Type& val)
template<template<class> class Field, class Type> template<template<class> class Field, class Type>
void FieldField<Field, Type>::operator=(Foam::zero) void FieldField<Field, Type>::operator=(Foam::zero)
{ {
forAll(*this, i) for (auto& pfld : *this)
{ {
this->operator[](i) = Foam::zero{}; pfld = Foam::zero{};
} }
} }
@ -489,11 +489,11 @@ void FieldField<Field, Type>::operator op \
} \ } \
\ \
template<template<class> class Field, class Type> \ template<template<class> class Field, class Type> \
void FieldField<Field, Type>::operator op(const TYPE& t) \ void FieldField<Field, Type>::operator op(const TYPE& val) \
{ \ { \
forAll(*this, i) \ for (auto& pfld : *this) \
{ \ { \
this->operator[](i) op t; \ pfld op val; \
} \ } \
} }

View File

@ -951,6 +951,16 @@ void Foam::GeometricBoundaryField<Type, PatchField, GeoMesh>::operator=
} }
template<class Type, template<class> class PatchField, class GeoMesh>
void Foam::GeometricBoundaryField<Type, PatchField, GeoMesh>::operator=
(
Foam::zero
)
{
FieldField<PatchField, Type>::operator=(Foam::zero{});
}
template<class Type, template<class> class PatchField, class GeoMesh> template<class Type, template<class> class PatchField, class GeoMesh>
void Foam::GeometricBoundaryField<Type, PatchField, GeoMesh>::operator== void Foam::GeometricBoundaryField<Type, PatchField, GeoMesh>::operator==
( (
@ -983,9 +993,9 @@ void Foam::GeometricBoundaryField<Type, PatchField, GeoMesh>::operator==
const Type& val const Type& val
) )
{ {
forAll(*this, patchi) for (auto& pfld : *this)
{ {
this->operator[](patchi) == val; pfld == val;
} }
} }

View File

@ -260,6 +260,9 @@ public:
//- Assignment to uniform value //- Assignment to uniform value
void operator=(const Type& val); void operator=(const Type& val);
//- Assignment to zero
void operator=(Foam::zero);
//- Forced assignment from GeometricBoundaryField //- Forced assignment from GeometricBoundaryField
void operator==(const GeometricBoundaryField& bf); void operator==(const GeometricBoundaryField& bf);
@ -269,10 +272,14 @@ public:
//- Forced assignment to uniform value //- Forced assignment to uniform value
void operator==(const Type& val); void operator==(const Type& val);
//- Forced assignment to zero
void operator==(Foam::zero) { *this == Type(Foam::zero{}); }
// Prevent automatic comparison rewriting (c++20) // Prevent automatic comparison rewriting (c++20)
bool operator!=(const GeometricBoundaryField&) = delete; bool operator!=(const GeometricBoundaryField&) = delete;
bool operator!=(const FieldField<PatchField, Type>&) = delete; bool operator!=(const FieldField<PatchField, Type>&) = delete;
bool operator!=(const Type&) = delete; bool operator!=(const Type&) = delete;
bool operator!=(Foam::zero) = delete;
}; };

View File

@ -1478,6 +1478,21 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::operator=
} }
template<class Type, template<class> class PatchField, class GeoMesh>
void Foam::GeometricField<Type, PatchField, GeoMesh>::operator=(Foam::zero)
{
// No dimension checking
primitiveFieldRef() = Foam::zero{};
boundaryFieldRef() = Foam::zero{};
// Make sure any e.g. jump-cyclic are updated.
boundaryFieldRef().evaluate_if
(
[](const auto& pfld) { return pfld.constraintOverride(); }
);
}
template<class Type, template<class> class PatchField, class GeoMesh> template<class Type, template<class> class PatchField, class GeoMesh>
void Foam::GeometricField<Type, PatchField, GeoMesh>::operator== void Foam::GeometricField<Type, PatchField, GeoMesh>::operator==
( (
@ -1520,6 +1535,21 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::operator==
} }
template<class Type, template<class> class PatchField, class GeoMesh>
void Foam::GeometricField<Type, PatchField, GeoMesh>::operator==(Foam::zero)
{
// No dimension checking
primitiveFieldRef() = Foam::zero{};
boundaryFieldRef() == Foam::zero{};
// Make sure any e.g. jump-cyclic are updated.
boundaryFieldRef().evaluate_if
(
[](const auto& pfld) { return pfld.constraintOverride(); }
);
}
#define COMPUTED_ASSIGNMENT(TYPE, op) \ #define COMPUTED_ASSIGNMENT(TYPE, op) \
\ \
template<class Type, template<class> class PatchField, class GeoMesh> \ template<class Type, template<class> class PatchField, class GeoMesh> \

View File

@ -1028,11 +1028,21 @@ public:
void operator=(const GeometricField<Type, PatchField, GeoMesh>&); void operator=(const GeometricField<Type, PatchField, GeoMesh>&);
void operator=(const tmp<GeometricField<Type, PatchField, GeoMesh>>&); void operator=(const tmp<GeometricField<Type, PatchField, GeoMesh>>&);
void operator=(const dimensioned<Type>&);
//- Assign value (with dimension check)
void operator=(const dimensioned<Type>& dt);
//- Assign value zero (no dimension checks)
void operator=(Foam::zero);
void operator==(const tmp<GeometricField<Type, PatchField, GeoMesh>>&); void operator==(const tmp<GeometricField<Type, PatchField, GeoMesh>>&);
//- Assign value (with dimension check). Force assign for boundary.
void operator==(const dimensioned<Type>&); void operator==(const dimensioned<Type>&);
//- Assign value zero (no dimension checks). Force assign for boundary.
void operator==(Foam::zero);
void operator+=(const GeometricField<Type, PatchField, GeoMesh>&); void operator+=(const GeometricField<Type, PatchField, GeoMesh>&);
void operator+=(const tmp<GeometricField<Type, PatchField, GeoMesh>>&); void operator+=(const tmp<GeometricField<Type, PatchField, GeoMesh>>&);
@ -1061,6 +1071,7 @@ public:
const tmp<GeometricField<Type, PatchField, GeoMesh>>& const tmp<GeometricField<Type, PatchField, GeoMesh>>&
) = delete; ) = delete;
bool operator!=(const dimensioned<Type>&) = delete; bool operator!=(const dimensioned<Type>&) = delete;
bool operator!=(Foam::zero) = delete;
// Write // Write

View File

@ -50,7 +50,7 @@ tmp<scalarField> sumNeighbours
{ {
const fvMesh& mesh = field.mesh(); const fvMesh& mesh = field.mesh();
result == dimensioned<Type>(field.dimensions(), Zero); result == Zero;
auto tscaling = tmp<scalarField>::New(mesh.nCells(), Zero); auto tscaling = tmp<scalarField>::New(mesh.nCells(), Zero);
auto& scaling = tscaling.ref(); auto& scaling = tscaling.ref();

View File

@ -307,7 +307,7 @@ void FSD<ReactionThermo, ThermoType>::calculateSourceNorm()
template<class ReactionThermo, class ThermoType> template<class ReactionThermo, class ThermoType>
void FSD<ReactionThermo, ThermoType>::correct() void FSD<ReactionThermo, ThermoType>::correct()
{ {
this->wFuel_ == dimensionedScalar(dimMass/dimTime/dimVolume, Zero); this->wFuel_ == Zero;
if (this->active()) if (this->active())
{ {

View File

@ -69,7 +69,7 @@ diffusion<ReactionThermo, ThermoType>::~diffusion()
template<class ReactionThermo, class ThermoType> template<class ReactionThermo, class ThermoType>
void diffusion<ReactionThermo, ThermoType>::correct() void diffusion<ReactionThermo, ThermoType>::correct()
{ {
this->wFuel_ == dimensionedScalar(dimMass/dimVolume/dimTime, Zero); this->wFuel_ == Zero;
if (this->active()) if (this->active())
{ {

View File

@ -216,15 +216,13 @@ diffusionMulticomponent<ReactionThermo, ThermoType>::correct()
forAll(lhs, l) forAll(lhs, l)
{ {
const label lIndex = lhs[l].index; const label lIndex = lhs[l].index;
this->chemistryPtr_->RR(lIndex) = this->chemistryPtr_->RR(lIndex) = Zero;
dimensionedScalar(dimMass/dimTime/dimVolume, Zero);
} }
forAll(rhs, l) forAll(rhs, l)
{ {
const label rIndex = rhs[l].index; const label rIndex = rhs[l].index;
this->chemistryPtr_->RR(rIndex) = this->chemistryPtr_->RR(rIndex) = Zero;
dimensionedScalar(dimMass/dimTime/dimVolume, Zero);
} }
} }

View File

@ -81,7 +81,7 @@ eddyDissipationModelBase<ReactionThermo, ThermoType>::rtTurb() const
template<class ReactionThermo, class ThermoType> template<class ReactionThermo, class ThermoType>
void eddyDissipationModelBase<ReactionThermo, ThermoType>::correct() void eddyDissipationModelBase<ReactionThermo, ThermoType>::correct()
{ {
this->wFuel_ == dimensionedScalar(dimMass/dimVolume/dimTime, Zero); this->wFuel_ == Zero;
if (this->active()) if (this->active())
{ {

View File

@ -67,7 +67,7 @@ infinitelyFastChemistry<ReactionThermo, ThermoType>::~infinitelyFastChemistry()
template<class ReactionThermo, class ThermoType> template<class ReactionThermo, class ThermoType>
void infinitelyFastChemistry<ReactionThermo, ThermoType>::correct() void infinitelyFastChemistry<ReactionThermo, ThermoType>::correct()
{ {
this->wFuel_ == dimensionedScalar(dimMass/dimVolume/dimTime, Zero); this->wFuel_ == Zero;
if (this->active()) if (this->active())
{ {

View File

@ -510,8 +510,8 @@ public:
void operator+=(const dimensioned<Type>&); void operator+=(const dimensioned<Type>&);
void operator-=(const dimensioned<Type>&); void operator-=(const dimensioned<Type>&);
void operator+=(const Foam::zero) {} void operator+=(Foam::zero) {}
void operator-=(const Foam::zero) {} void operator-=(Foam::zero) {}
void operator*=(const areaScalarField::Internal&); void operator*=(const areaScalarField::Internal&);
void operator*=(const tmp<areaScalarField::Internal>&); void operator*=(const tmp<areaScalarField::Internal>&);

View File

@ -27,6 +27,6 @@ volScalarField dpdt(dpdtHeader, fvc::ddt(p));
if (!thermo.dpdt()) if (!thermo.dpdt())
{ {
dpdt == dimensionedScalar(dpdt.dimensions(), Zero); dpdt == Zero;
dpdt.writeOpt(IOobject::NO_WRITE); dpdt.writeOpt(IOobject::NO_WRITE);
} }

View File

@ -60,7 +60,7 @@ Foam::fv::skewCorrectedSnGrad<Type>::fullGradCorrection
auto& ssf = tssf.ref(); auto& ssf = tssf.ref();
ssf.setOriented(); ssf.setOriented();
ssf = dimensioned<Type>(ssf.dimensions(), Zero); ssf = Zero;
typedef typename typedef typename

View File

@ -693,8 +693,8 @@ public:
void operator+=(const dimensioned<Type>&); void operator+=(const dimensioned<Type>&);
void operator-=(const dimensioned<Type>&); void operator-=(const dimensioned<Type>&);
void operator+=(const Foam::zero) {} void operator+=(Foam::zero) {}
void operator-=(const Foam::zero) {} void operator-=(Foam::zero) {}
void operator*=(const volScalarField::Internal&); void operator*=(const volScalarField::Internal&);
void operator*=(const tmp<volScalarField::Internal>&); void operator*=(const tmp<volScalarField::Internal>&);

View File

@ -427,7 +427,7 @@ const Foam::surfaceScalarField& Foam::fvMesh::phi() const
// mesh motion fluxes if the time has been incremented // mesh motion fluxes if the time has been incremented
if (!time().subCycling() && phiPtr_->timeIndex() != time().timeIndex()) if (!time().subCycling() && phiPtr_->timeIndex() != time().timeIndex())
{ {
(*phiPtr_) = dimensionedScalar(dimVolume/dimTime, Foam::zero{}); (*phiPtr_) = Zero;
} }
phiPtr_->setOriented(); phiPtr_->setOriented();

View File

@ -310,7 +310,7 @@ public:
auto tcorr = auto tcorr =
SurfaceField::New("correction", vf.mesh(), vf.dimensions()); SurfaceField::New("correction", vf.mesh(), vf.dimensions());
auto& corr = tcorr.ref(); auto& corr = tcorr.ref();
corr = dimensioned<Type>(vf.dimensions(), Zero); corr = Zero;
// Set default scheme correction // Set default scheme correction
const auto& scheme0 = this->scheme(0); const auto& scheme0 = this->scheme(0);

View File

@ -122,8 +122,8 @@ void Foam::functionObjects::forceCoeffs::reset()
Cf_.reset(); Cf_.reset();
Cm_.reset(); Cm_.reset();
forceCoeff() == dimensionedVector(dimless, Zero); forceCoeff() == Zero;
momentCoeff() == dimensionedVector(dimless, Zero); momentCoeff() == Zero;
} }

View File

@ -200,8 +200,8 @@ void Foam::functionObjects::forces::reset()
if (porosity_) if (porosity_)
{ {
force == dimensionedVector(force.dimensions(), Zero); force == Zero;
moment == dimensionedVector(moment.dimensions(), Zero); moment == Zero;
} }
else else
{ {

View File

@ -195,7 +195,7 @@ Foam::functionObjects::scalarTransport::scalarTransport
if (resetOnStartUp_) if (resetOnStartUp_)
{ {
s == dimensionedScalar(dimless, Zero); s == Zero;
} }
} }

View File

@ -188,7 +188,7 @@ void fusedGaussLaplacianScheme<Type, GType>::gradComponent
GeometricField<Type, fvPatchField, volMesh>& gGrad GeometricField<Type, fvPatchField, volMesh>& gGrad
) )
{ {
gGrad = dimensioned<Type>(vf.dimensions()/dimLength, Zero); gGrad = Zero;
// Calculate grad of vf.component(cmpt) // Calculate grad of vf.component(cmpt)
fvc::GaussOp fvc::GaussOp

View File

@ -109,7 +109,7 @@ void Foam::patchCorrectedInterpolation::interpolateDataFromPatchGroups
dimensionedScalar(dimless, Zero), dimensionedScalar(dimless, Zero),
pointPatchFieldBase::zeroGradientType() pointPatchFieldBase::zeroGradientType()
); );
data = dimensioned<Type>(data.dimensions(), Zero); data = Zero;
forAll(patchGroups_, patchGroupI) forAll(patchGroups_, patchGroupI)
{ {

View File

@ -240,29 +240,27 @@ void objectiveIncompressible::nullify()
{ {
if (hasdJdv()) if (hasdJdv())
{ {
dJdvPtr_() == dimensionedVector(dJdvPtr_().dimensions(), Zero); dJdvPtr_() == Zero;
} }
if (hasdJdp()) if (hasdJdp())
{ {
dJdpPtr_() == dimensionedScalar(dJdpPtr_().dimensions(), Zero); dJdpPtr_() == Zero;
} }
if (hasdJdT()) if (hasdJdT())
{ {
dJdTPtr_() == dimensionedScalar(dJdTPtr_().dimensions(), Zero); dJdTPtr_() == Zero;
} }
if (hasdJdTMVar1()) if (hasdJdTMVar1())
{ {
dJdTMvar1Ptr_() == dJdTMvar1Ptr_() == Zero;
dimensionedScalar(dJdTMvar1Ptr_().dimensions(), Zero);
} }
if (hasdJdTMVar2()) if (hasdJdTMVar2())
{ {
dJdTMvar2Ptr_() == dJdTMvar2Ptr_() == Zero;
dimensionedScalar(dJdTMvar2Ptr_().dimensions(), Zero);
} }
if (hasBoundarydJdv()) if (hasBoundarydJdv())
{ {
bdJdvPtr_() == vector::zero; bdJdvPtr_() == Zero;
} }
if (hasBoundarydJdvn()) if (hasBoundarydJdvn())
{ {
@ -270,11 +268,11 @@ void objectiveIncompressible::nullify()
} }
if (hasBoundarydJdvt()) if (hasBoundarydJdvt())
{ {
bdJdvtPtr_() == vector::zero; bdJdvtPtr_() == Zero;
} }
if (hasBoundarydJdp()) if (hasBoundarydJdp())
{ {
bdJdpPtr_() == vector::zero; bdJdpPtr_() == Zero;
} }
if (hasBoundarydJdT()) if (hasBoundarydJdT())
{ {
@ -294,7 +292,7 @@ void objectiveIncompressible::nullify()
} }
if (hasBoundarydJdGradU()) if (hasBoundarydJdGradU())
{ {
bdJdGradUPtr_() == tensor::zero; bdJdGradUPtr_() == Zero;
} }
// Nullify geometric fields and sets nullified_ to true // Nullify geometric fields and sets nullified_ to true

View File

@ -484,7 +484,7 @@ void objective::nullify()
{ {
if (hasdJdb()) if (hasdJdb())
{ {
dJdbPtr_() == dimensionedScalar(dJdbPtr_().dimensions(), Zero); dJdbPtr_() == Zero;
} }
if (hasdJdbField()) if (hasdJdbField())
{ {
@ -492,40 +492,38 @@ void objective::nullify()
} }
if (hasBoundarydJdb()) if (hasBoundarydJdb())
{ {
bdJdbPtr_() == vector::zero; bdJdbPtr_() == Zero;
} }
if (hasdSdbMult()) if (hasdSdbMult())
{ {
bdSdbMultPtr_() == vector::zero; bdSdbMultPtr_() == Zero;
} }
if (hasdndbMult()) if (hasdndbMult())
{ {
bdndbMultPtr_() == vector::zero; bdndbMultPtr_() == Zero;
} }
if (hasdxdbMult()) if (hasdxdbMult())
{ {
bdxdbMultPtr_() == vector::zero; bdxdbMultPtr_() == Zero;
} }
if (hasdxdbDirectMult()) if (hasdxdbDirectMult())
{ {
bdxdbDirectMultPtr_() == vector::zero; bdxdbDirectMultPtr_() == Zero;
} }
if (hasBoundaryEdgeContribution()) if (hasBoundaryEdgeContribution())
{ {
for (Field<vectorField>& field : bEdgeContribution_()) for (auto& field : bEdgeContribution_())
{ {
field = vector::zero; field = Zero;
} }
} }
if (hasDivDxDbMult()) if (hasDivDxDbMult())
{ {
divDxDbMultPtr_() == divDxDbMultPtr_() == Zero;
dimensionedScalar(divDxDbMultPtr_().dimensions(), Zero);
} }
if (hasGradDxDbMult()) if (hasGradDxDbMult())
{ {
gradDxDbMultPtr_() == gradDxDbMultPtr_() == Zero;
dimensionedTensor(gradDxDbMultPtr_().dimensions(), Zero);
} }
nullified_ = true; nullified_ = true;

View File

@ -266,8 +266,8 @@ void adjointEikonalSolver::solve()
void adjointEikonalSolver::reset() void adjointEikonalSolver::reset()
{ {
source_ == dimensionedScalar(source_.dimensions(), Zero); source_ == Zero;
distanceSensPtr_() = vector::zero; distanceSensPtr_() = Zero;
} }

View File

@ -187,7 +187,7 @@ void adjointMeshMovementSolver::solve()
void adjointMeshMovementSolver::reset() void adjointMeshMovementSolver::reset()
{ {
source_ == dimensionedVector(source_.dimensions(), Zero); source_ == Zero;
meshMovementSensPtr_() = Zero; meshMovementSensPtr_() = Zero;
} }

View File

@ -237,7 +237,7 @@ void Foam::ShapeSensitivitiesBase::allocateMultipliers()
void Foam::ShapeSensitivitiesBase::clearMultipliers() void Foam::ShapeSensitivitiesBase::clearMultipliers()
{ {
gradDxDbMult_() = dimensionedTensor(gradDxDbMult_().dimensions(), Zero); gradDxDbMult_() = Zero;
if (divDxDbMult_) if (divDxDbMult_)
{ {
divDxDbMult_() = Zero; divDxDbMult_() = Zero;

View File

@ -402,9 +402,9 @@ void incompressibleVars::resetMeanFields()
Info<< "Resetting mean fields to zero" << endl; Info<< "Resetting mean fields to zero" << endl;
// Reset fields to zero // Reset fields to zero
pMeanPtr_() == dimensionedScalar(pInst().dimensions(), Zero); pMeanPtr_() == Zero;
UMeanPtr_() == dimensionedVector(UInst().dimensions(), Zero); UMeanPtr_() == Zero;
phiMeanPtr_() == dimensionedScalar(phiInst().dimensions(), Zero); phiMeanPtr_() == Zero;
RASModelVariables_().resetMeanFields(); RASModelVariables_().resetMeanFields();
// Reset averaging iteration index to 0 // Reset averaging iteration index to 0

View File

@ -72,9 +72,9 @@ void incompressibleAdjointVars::restoreInitValues()
if (solverControl_.storeInitValues()) if (solverControl_.storeInitValues())
{ {
Info<< "Restoring adjoint field to initial ones" << endl; Info<< "Restoring adjoint field to initial ones" << endl;
paInst() == dimensionedScalar(paInst().dimensions(), Zero); paInst() == Zero;
UaInst() == dimensionedVector(UaInst().dimensions(), Zero); UaInst() == Zero;
phiaInst() == dimensionedScalar(phiaInst().dimensions(), Zero); phiaInst() == Zero;
adjointTurbulence_().restoreInitValues(); adjointTurbulence_().restoreInitValues();
} }
} }
@ -87,9 +87,9 @@ void incompressibleAdjointVars::resetMeanFields()
Info<< "Resetting adjoint mean fields to zero" << endl; Info<< "Resetting adjoint mean fields to zero" << endl;
// Reset fields to zero // Reset fields to zero
paMeanPtr_() == dimensionedScalar(paPtr_().dimensions(), Zero); paMeanPtr_() == Zero;
UaMeanPtr_() == dimensionedVector(UaPtr_().dimensions(), Zero); UaMeanPtr_() == Zero;
phiaMeanPtr_() == dimensionedScalar(phiaPtr_().dimensions(), Zero); phiaMeanPtr_() == Zero;
adjointTurbulence_().resetMeanFields(); adjointTurbulence_().resetMeanFields();
// Reset averaging iteration index to 0 // Reset averaging iteration index to 0

View File

@ -348,11 +348,10 @@ void variablesSet::nullifyField
GeometricField<Type, PatchField, GeoMesh>& field GeometricField<Type, PatchField, GeoMesh>& field
) )
{ {
typedef GeometricField<Type, PatchField, GeoMesh> fieldType; field == Zero;
field == dimensioned<Type>(field.dimensions(), Zero);
if (field.nOldTimes()) if (field.nOldTimes())
{ {
fieldType& oldTime = field.oldTime(); auto& oldTime = field.oldTime();
variablesSet::nullifyField(oldTime); variablesSet::nullifyField(oldTime);
} }
} }

View File

@ -68,14 +68,12 @@ void adjointRASModel::restoreInitValues()
{ {
if (adjointTMVariable1Ptr_) if (adjointTMVariable1Ptr_)
{ {
volScalarField& var1 = adjointTMVariable1Ptr_.ref(); adjointTMVariable1Ptr_.ref() == Zero;
var1 == dimensionedScalar(var1.dimensions(), Zero);
} }
if (adjointTMVariable2Ptr_) if (adjointTMVariable2Ptr_)
{ {
volScalarField& var2 = adjointTMVariable2Ptr_.ref(); adjointTMVariable2Ptr_.ref() == Zero;
var2 == dimensionedScalar(var2.dimensions(), Zero);
} }
} }
} }
@ -465,13 +463,11 @@ void adjointRASModel::resetMeanFields()
{ {
if (adjointTMVariable1MeanPtr_) if (adjointTMVariable1MeanPtr_)
{ {
adjointTMVariable1MeanPtr_() == adjointTMVariable1MeanPtr_.ref() == Zero;
dimensionedScalar(adjointTMVariable1Ptr_().dimensions(), Zero);
} }
if (adjointTMVariable2MeanPtr_) if (adjointTMVariable2MeanPtr_)
{ {
adjointTMVariable2MeanPtr_() == adjointTMVariable2MeanPtr_.ref() == Zero;
dimensionedScalar(adjointTMVariable2Ptr_().dimensions(), Zero);
} }
} }
} }

View File

@ -363,18 +363,15 @@ void RASModelVariables::resetMeanFields()
// Reset fields to zero // Reset fields to zero
if (TMVar1MeanPtr_) if (TMVar1MeanPtr_)
{ {
TMVar1MeanPtr_.ref() == TMVar1MeanPtr_.ref() == Zero;
dimensionedScalar(TMVar1Inst().dimensions(), Zero);
} }
if (TMVar2MeanPtr_) if (TMVar2MeanPtr_)
{ {
TMVar2MeanPtr_.ref() == TMVar2MeanPtr_.ref() == Zero;
dimensionedScalar(TMVar2Inst().dimensions(), Zero);
} }
if (nutMeanPtr_) if (nutMeanPtr_)
{ {
nutMeanPtr_.ref() == nutMeanPtr_.ref() == Zero;
dimensionedScalar(nutRefInst().dimensions(), Zero);
} }
} }
} }

View File

@ -262,8 +262,8 @@ void Foam::multiphaseInter::multiphaseSystem::solveAlphas()
// Set Su and Sp to zero // Set Su and Sp to zero
for (const multiphaseInter::phaseModel& phase : phases_) for (const multiphaseInter::phaseModel& phase : phases_)
{ {
Su_[phase.name()] = dimensionedScalar("Su", dimless/dimTime, Zero); Su_[phase.name()] = Zero;
Sp_[phase.name()] = dimensionedScalar("Sp", dimless/dimTime, Zero); Sp_[phase.name()] = Zero;
// Add alpha*div(U) // Add alpha*div(U)
//const volScalarField& alpha = phase; //const volScalarField& alpha = phase;
@ -368,7 +368,7 @@ void Foam::multiphaseInter::multiphaseSystem::solveAlphas()
); );
// Reset rhoPhi // Reset rhoPhi
rhoPhi_ = dimensionedScalar("rhoPhi", dimMass/dimTime, Zero); rhoPhi_ = Zero;
for (multiphaseInter::phaseModel& phase : phases_) for (multiphaseInter::phaseModel& phase : phases_)
{ {

View File

@ -101,7 +101,7 @@ template<class BasePhaseModel>
const Foam::surfaceScalarField& const Foam::surfaceScalarField&
Foam::StaticPhaseModel<BasePhaseModel>::phi() Foam::StaticPhaseModel<BasePhaseModel>::phi()
{ {
phi_ = dimensionedScalar(dimensionSet(0, 3, -1, 0, 0), Zero); phi_ = Zero;
return phi_; return phi_;
} }
@ -128,7 +128,7 @@ template<class BasePhaseModel>
Foam::surfaceScalarField& Foam::surfaceScalarField&
Foam::StaticPhaseModel<BasePhaseModel>::alphaPhi() Foam::StaticPhaseModel<BasePhaseModel>::alphaPhi()
{ {
alphaPhi_ = dimensionedScalar(dimensionSet(0, 3, -1, 0, 0), Zero); alphaPhi_ = Zero;
return alphaPhi_; return alphaPhi_;
} }

View File

@ -418,7 +418,7 @@ Foam::ThermalPhaseChangePhaseSystem<BasePhaseSystem>::correctInterfaceThermo()
} }
else else
{ {
iDmdtNew == dimensionedScalar(iDmdt.dimensions()); iDmdtNew == Zero;
} }
volScalarField H1(heatTransferModelIter().first()->K()); volScalarField H1(heatTransferModelIter().first()->K());

View File

@ -63,7 +63,7 @@ Foam::RASModels::phasePressureModel::phasePressureModel
expMax_(coeffDict_.get<scalar>("expMax")), expMax_(coeffDict_.get<scalar>("expMax")),
g0_("g0", dimPressure, coeffDict_) g0_("g0", dimPressure, coeffDict_)
{ {
nut_ == dimensionedScalar(nut_.dimensions()); nut_ == Zero;
if (type == typeName) if (type == typeName)
{ {
@ -205,11 +205,8 @@ Foam::RASModels::phasePressureModel::devRhoReff
IOobject::groupName("devRhoReff", U.group()), IOobject::groupName("devRhoReff", U.group()),
IOobject::NO_REGISTER, IOobject::NO_REGISTER,
mesh_, mesh_,
dimensioned<symmTensor> Zero,
( rho_.dimensions()*dimensionSet(0, 2, -2, 0, 0)
rho_.dimensions()*dimensionSet(0, 2, -2, 0, 0),
Zero
)
); );
} }

View File

@ -61,7 +61,7 @@ Foam::diameterModels::IATEsources::dummy::R
iate_.phase().mesh() iate_.phase().mesh()
), ),
iate_.phase().mesh(), iate_.phase().mesh(),
dimensionedScalar(kappai.dimensions()/dimTime, 0) dimensionedScalar(kappai.dimensions()/dimTime, Zero)
); );
return fvm::Su(R, kappai); return fvm::Su(R, kappai);

View File

@ -66,7 +66,7 @@ Foam::RASModels::phasePressureModel::phasePressureModel
expMax_(coeffDict_.get<scalar>("expMax")), expMax_(coeffDict_.get<scalar>("expMax")),
g0_("g0", dimPressure, coeffDict_) g0_("g0", dimPressure, coeffDict_)
{ {
nut_ == dimensionedScalar(nut_.dimensions(), Zero); nut_ == Zero;
if (type == typeName) if (type == typeName)
{ {
@ -213,10 +213,8 @@ Foam::RASModels::phasePressureModel::devRhoReff
IOobject::groupName("devRhoReff", U.group()), IOobject::groupName("devRhoReff", U.group()),
IOobject::NO_REGISTER, IOobject::NO_REGISTER,
mesh_, mesh_,
dimensioned<symmTensor> Zero,
( rho_.dimensions()*dimensionSet(0, 2, -2, 0, 0)
rho_.dimensions()*dimensionSet(0, 2, -2, 0, 0), Zero
)
); );
} }

View File

@ -266,8 +266,8 @@ void liquidFilmModel::preEvolveRegion()
liquidFilmBase::preEvolveRegion(); liquidFilmBase::preEvolveRegion();
cloudMassTrans_ == dimensionedScalar(dimMass, Zero); cloudMassTrans_ == Zero;
cloudDiameterTrans_ == dimensionedScalar(dimLength, Zero); cloudDiameterTrans_ == Zero;
const scalar deltaT = primaryMesh().time().deltaTValue(); const scalar deltaT = primaryMesh().time().deltaTValue();
const scalarField rAreaDeltaT(scalar(1)/deltaT/regionMesh().S().field()); const scalarField rAreaDeltaT(scalar(1)/deltaT/regionMesh().S().field());

View File

@ -92,7 +92,7 @@ bool reactingOneDim::read(const dictionary& dict)
void reactingOneDim::updateqr() void reactingOneDim::updateqr()
{ {
// Update local qr from coupled qr field // Update local qr from coupled qr field
qr_ == dimensionedScalar(qr_.dimensions(), Zero); qr_ == Zero;
// Retrieve field from coupled region using mapped boundary conditions // Retrieve field from coupled region using mapped boundary conditions
qr_.correctBoundaryConditions(); qr_.correctBoundaryConditions();
@ -143,8 +143,8 @@ void reactingOneDim::updateqr()
void reactingOneDim::updatePhiGas() void reactingOneDim::updatePhiGas()
{ {
phiHsGas_ == dimensionedScalar(phiHsGas_.dimensions(), Zero); phiHsGas_ == Zero;
phiGas_ == dimensionedScalar(phiGas_.dimensions(), Zero); phiGas_ == Zero;
const speciesTable& gasTable = solidChemistry_->gasTable(); const speciesTable& gasTable = solidChemistry_->gasTable();

View File

@ -85,9 +85,9 @@ void kinematicSingleLayer::resetPrimaryRegionSourceTerms()
{ {
DebugInFunction << endl; DebugInFunction << endl;
rhoSpPrimary_ == dimensionedScalar(rhoSp_.dimensions(), Zero); rhoSpPrimary_ == Zero;
USpPrimary_ == dimensionedVector(USp_.dimensions(), Zero); USpPrimary_ == Zero;
pSpPrimary_ == dimensionedScalar(pSp_.dimensions(), Zero); pSpPrimary_ == Zero;
} }
@ -849,9 +849,9 @@ void kinematicSingleLayer::preEvolveRegion()
// Reset transfer fields // Reset transfer fields
availableMass_ = mass(); availableMass_ = mass();
cloudMassTrans_ == dimensionedScalar(dimMass, Zero); cloudMassTrans_ == Zero;
cloudDiameterTrans_ == dimensionedScalar(dimLength, Zero); cloudDiameterTrans_ == Zero;
primaryMassTrans_ == dimensionedScalar(dimMass, Zero); primaryMassTrans_ == Zero;
} }

View File

@ -98,7 +98,7 @@ void thermoSingleLayer::resetPrimaryRegionSourceTerms()
kinematicSingleLayer::resetPrimaryRegionSourceTerms(); kinematicSingleLayer::resetPrimaryRegionSourceTerms();
hsSpPrimary_ == dimensionedScalar(hsSp_.dimensions(), Zero); hsSpPrimary_ == Zero;
} }
@ -607,7 +607,7 @@ void thermoSingleLayer::preEvolveRegion()
DebugInFunction << endl; DebugInFunction << endl;
kinematicSingleLayer::preEvolveRegion(); kinematicSingleLayer::preEvolveRegion();
primaryEnergyTrans_ == dimensionedScalar(dimEnergy, Zero); primaryEnergyTrans_ == Zero;
} }

View File

@ -725,10 +725,10 @@ void Foam::radiation::fvDOM::updateBlackBodyEmission()
void Foam::radiation::fvDOM::updateG() void Foam::radiation::fvDOM::updateG()
{ {
G_ = dimensionedScalar(dimMass/pow3(dimTime), Zero); G_ = Zero;
qr_ = dimensionedScalar(dimMass/pow3(dimTime), Zero); qr_ = Zero;
qem_ = dimensionedScalar(dimMass/pow3(dimTime), Zero); qem_ = Zero;
qin_ = dimensionedScalar(dimMass/pow3(dimTime), Zero); qin_ = Zero;
forAll(IRay_, rayI) forAll(IRay_, rayI)
{ {

View File

@ -300,7 +300,7 @@ Foam::scalar Foam::radiation::radiativeIntensityRay::correct()
void Foam::radiation::radiativeIntensityRay::addIntensity() void Foam::radiation::radiativeIntensityRay::addIntensity()
{ {
I_ = dimensionedScalar(dimMass/pow3(dimTime), Zero); I_ = Zero;
forAll(ILambda_, lambdaI) forAll(ILambda_, lambdaI)
{ {

View File

@ -868,7 +868,7 @@ void Foam::radiation::solarLoad::calculate()
if (firstIter_ || facesChanged || timeDependentLoad) if (firstIter_ || facesChanged || timeDependentLoad)
{ {
// Reset Ru // Reset Ru
Ru_ = dimensionedScalar("Ru", dimMass/dimLength/pow3(dimTime), Zero); Ru_ = Zero;
solarCalc_.correctDirectSolarRad(); solarCalc_.correctDirectSolarRad();
solarCalc_.correctDiffuseSolarRad(); solarCalc_.correctDiffuseSolarRad();

View File

@ -328,7 +328,7 @@ void Foam::radiation::wideBandAbsorptionEmission::correct
PtrList<volScalarField>& aLambda PtrList<volScalarField>& aLambda
) const ) const
{ {
a = dimensionedScalar(dimless/dimLength, Zero); a = Zero;
for (label j=0; j<nBands_; j++) for (label j=0; j<nBands_; j++)
{ {

View File

@ -151,8 +151,8 @@ heSolidThermo
heThermo<BasicSolidThermo, MixtureType>(mesh, phaseName) heThermo<BasicSolidThermo, MixtureType>(mesh, phaseName)
{ {
calculate(); calculate();
this->mu_ == dimensionedScalar(this->mu_.dimensions(), Zero); this->mu_ == Zero;
this->psi_ == dimensionedScalar(this->psi_.dimensions(), Zero); this->psi_ == Zero;
} }
@ -168,8 +168,8 @@ heSolidThermo
heThermo<BasicSolidThermo, MixtureType>(mesh, dict, phaseName) heThermo<BasicSolidThermo, MixtureType>(mesh, dict, phaseName)
{ {
calculate(); calculate();
this->mu_ == dimensionedScalar(this->mu_.dimensions(), Zero); this->mu_ == Zero;
this->psi_ == dimensionedScalar(this->psi_.dimensions(), Zero); this->psi_ == Zero;
} }
@ -188,8 +188,8 @@ heSolidThermo
// TBD. initialise psi, mu (at heThermo level) since these do not // TBD. initialise psi, mu (at heThermo level) since these do not
// get initialised. Move to heThermo constructor? // get initialised. Move to heThermo constructor?
this->mu_ == dimensionedScalar(this->mu_.dimensions(), Zero); this->mu_ == Zero;
this->psi_ == dimensionedScalar(this->psi_.dimensions(), Zero); this->psi_ == Zero;
} }

View File

@ -150,7 +150,7 @@ void Foam::isoAdvection::limitFluxes
DebugInfo << "boundAlpha... " << endl; DebugInfo << "boundAlpha... " << endl;
DynamicList<label> correctedFaces(3*nOvershoots); DynamicList<label> correctedFaces(3*nOvershoots);
dVfcorrectionValues = dimensionedScalar("0",dimVolume,0.0); dVfcorrectionValues = Zero;
boundFlux(needBounding, dVfcorrectionValues, correctedFaces,Sp,Su); boundFlux(needBounding, dVfcorrectionValues, correctedFaces,Sp,Su);
correctedFaces.append correctedFaces.append

View File

@ -151,8 +151,8 @@ void Foam::reconstruction::gradAlpha::reconstruct(bool forceUpdate)
} }
} }
interfaceNormal_.resize(interfaceLabels_.size()); interfaceNormal_.resize(interfaceLabels_.size());
centre_ = dimensionedVector("centre", dimLength, Zero); centre_ = Zero;
normal_ = dimensionedVector("normal", dimArea, Zero); normal_ = Zero;
gradSurf(alpha1_); gradSurf(alpha1_);

View File

@ -372,8 +372,8 @@ Foam::reconstruction::plicRDF::plicRDF
{ {
setInitNormals(false); setInitNormals(false);
centre_ = dimensionedVector("centre", dimLength, Zero); centre_ = Zero;
normal_ = dimensionedVector("normal", dimArea, Zero); normal_ = Zero;
forAll(interfaceLabels_, i) forAll(interfaceLabels_, i)
{ {
@ -436,8 +436,8 @@ void Foam::reconstruction::plicRDF::reconstruct(bool forceUpdate)
// Sets interfaceCell_ and interfaceNormal // Sets interfaceCell_ and interfaceNormal
setInitNormals(interpolateNormal_); setInitNormals(interpolateNormal_);
centre_ = dimensionedVector("centre", dimLength, Zero); centre_ = Zero;
normal_ = dimensionedVector("normal", dimArea, Zero); normal_ = Zero;
// nextToInterface is update on setInitNormals // nextToInterface is update on setInitNormals
const boolList& nextToInterface_ = RDF_.nextToInterface(); const boolList& nextToInterface_ = RDF_.nextToInterface();