ENH: use tmp field factory methods [6] (#2723)

- src/functionObjects
This commit is contained in:
Mark Olesen
2024-01-23 10:08:35 +01:00
parent 995a9705e2
commit 71d4a23ec0
17 changed files with 130 additions and 248 deletions

View File

@ -79,16 +79,10 @@ bool Foam::functionObjects::PecletNo::calc()
const dictionary& model =
mesh_.lookupObject<dictionary>("transportProperties");
nuEff = tmp<volScalarField>::New
nuEff = volScalarField::New
(
IOobject
(
"nuEff",
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
"nuEff",
IOobject::NO_REGISTER,
mesh_,
dimensionedScalar("nu", dimViscosity, model)
);

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015-2020 OpenCFD Ltd.
Copyright (C) 2015-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -531,9 +531,10 @@ bool Foam::functionObjects::extractEulerianParticles::execute()
const volScalarField& alpha =
mesh_.lookupObject<volScalarField>(alphaName_);
const surfaceScalarField alphaf
auto talphaf = surfaceScalarField::New
(
typeName + ":alphaf",
IOobject::scopedName(typeName, "alphaf"),
IOobject::NO_REGISTER,
fvc::interpolate(alpha)
);
@ -546,7 +547,7 @@ bool Foam::functionObjects::extractEulerianParticles::execute()
// Set the blocked faces, i.e. where alpha > alpha threshold value
boolList blockedFaces(fz.size(), false);
setBlockedFaces(alphaf, fz, blockedFaces);
setBlockedFaces(talphaf(), fz, blockedFaces);
// Split the faceZone according to the blockedFaces
// - Returns a list of (disconnected) region index per face zone face
@ -567,7 +568,7 @@ bool Foam::functionObjects::extractEulerianParticles::execute()
// Process latest region information
tmp<surfaceScalarField> tphi = phiU();
accumulateParticleInfo(alphaf, tphi(), regionFaceIDs, fz);
accumulateParticleInfo(talphaf(), tphi(), regionFaceIDs, fz);
Log << " Collected particles : " << nCollectedParticles_ << nl
<< " Collected volume : " << collectedVolume_ << nl

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -49,22 +49,36 @@ bool Foam::functionObjects::limitFields::limitField(const word& fieldName)
if (withBounds_ & limitType::CLAMP_MIN)
{
volScalarField mField(typeName + ":mag" + field.name(), mag(field));
auto tmField = volScalarField::New
(
IOobject::scopedName(typeName, "mag" + field.name()),
IOobject::NO_REGISTER,
mag(field)
);
auto& mField = tmField.ref();
Log << " min(|" << gMin(mField) << "|)";
//field.normalise();
field /= mag(field) + eps;
mField.clamp_min(min_);
field *= mField;
field *= tmField;
}
if (withBounds_ & limitType::CLAMP_MAX)
{
volScalarField mField(typeName + ":mag" + field.name(), mag(field));
auto tmField = volScalarField::New
(
IOobject::scopedName(typeName, "mag" + field.name()),
IOobject::NO_REGISTER,
mag(field)
);
auto& mField = tmField.ref();
Log << " max(|" << gMax(mField) << "|)";
//field.normalise();
field /= mag(field) + eps;
mField.clamp_max(max_);
field *= mField;
field *= tmField;
}
return true;

View File

@ -131,17 +131,10 @@ Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressure::rhoScale
{
if (p.dimensions() == dimPressure)
{
return tmp<volScalarField>::New
return volScalarField::New
(
IOobject
(
"rhoScale",
p.mesh().time().timeName(),
p.mesh(),
IOobject::NO_READ,
IOobject::NO_WRITE,
IOobject::NO_REGISTER
),
"rhoScale",
IOobject::NO_REGISTER,
p,
fvPatchFieldBase::calculatedType()
);
@ -236,21 +229,14 @@ Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressure::calcPressure
) const
{
// Initialise to the pressure reference level
auto tresult =
tmp<volScalarField>::New
(
IOobject
(
scopedName("p"),
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ
),
mesh_,
dimensionedScalar("p", dimPressure, pRef_)
);
volScalarField& result = tresult.ref();
auto tresult = volScalarField::New
(
scopedName("p"),
IOobject::NO_REGISTER,
mesh_,
dimensionedScalar("p", dimPressure, pRef_)
);
auto& result = tresult.ref();
addHydrostaticContribution(p, result);
@ -304,7 +290,7 @@ Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressure::coeff
if (mode_ & COEFF)
{
tmp<volScalarField> tpCoeff(tp.ptr());
volScalarField& pCoeff = tpCoeff.ref();
auto& pCoeff = tpCoeff.ref();
pCoeff -= dimensionedScalar("pInf", dimPressure, pInf_);
@ -325,21 +311,16 @@ Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressure::coeff
bool Foam::functionObjects::pressure::calc()
{
if (foundObject<volScalarField>(fieldName_))
{
const volScalarField& p = lookupObject<volScalarField>(fieldName_);
const auto* pptr = cfindObject<volScalarField>(fieldName_);
auto tp = tmp<volScalarField>::New
if (pptr)
{
const auto& p = *pptr;
auto tp = volScalarField::New
(
IOobject
(
resultName_,
p.mesh().time().timeName(),
p.mesh(),
IOobject::NO_READ,
IOobject::NO_WRITE,
IOobject::REGISTER
),
resultName_,
IOobject::REGISTER,
coeff(calcPressure(p, rhoScale(p)))
);

View File

@ -87,18 +87,13 @@ Foam::functionObjects::proudmanAcousticPower::a() const
return sqrt(thermo.gamma()*thermo.p()/thermo.rho());
}
return
tmp<volScalarField>::New
(
IOobject
(
scopedName("a"),
mesh_.time().timeName(),
mesh_
),
mesh_,
aRef_
);
return volScalarField::New
(
scopedName("a"),
IOobject::NO_REGISTER,
mesh_,
aRef_
);
}

View File

@ -80,20 +80,14 @@ calculateSpeciesRR
const basicChemistryModel& basicChemistry
)
{
auto RRt = tmp<DimensionedField<scalar, volMesh>>::New
auto tRR = volScalarField::Internal::New
(
IOobject
(
"RR",
time_.timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
"RR",
IOobject::NO_REGISTER,
mesh_,
dimensionedScalar(dimMass/dimVolume/dimTime, Zero)
);
auto& RR = RRt.ref();
auto& RR = tRR.ref();
scalar dt = time_.deltaTValue();

View File

@ -449,7 +449,8 @@ bool Foam::functionObjects::regionSizeDistribution::write()
mesh_.time().timeName(),
mesh_,
IOobjectOption::MUST_READ,
IOobjectOption::NO_WRITE
IOobjectOption::NO_WRITE,
IOobjectOption::NO_REGISTER
),
mesh_
)
@ -535,18 +536,11 @@ bool Foam::functionObjects::regionSizeDistribution::write()
{
volScalarField region
(
IOobject
(
"region",
mesh_.time().timeName(),
mesh_,
IOobjectOption::NO_READ,
IOobjectOption::NO_WRITE,
IOobjectOption::NO_REGISTER
),
mesh_.newIOobject("region"),
mesh_,
dimensionedScalar(dimless, Zero)
);
Info<< " Dumping region as volScalarField to "
<< region.name() << endl;

View File

@ -45,17 +45,10 @@ namespace Foam
Foam::tmp<Foam::volScalarField> Foam::resolutionIndexModel::V() const
{
auto tV = tmp<volScalarField>::New
auto tV = volScalarField::New
(
IOobject
(
"V",
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE,
IOobject::NO_REGISTER
),
"V",
IOobject::NO_REGISTER,
mesh_,
dimVolume,
fvPatchFieldBase::zeroGradientType()

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-2020 OpenCFD Ltd.
Copyright (C) 2017-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -240,7 +240,7 @@ bool Foam::functionObjects::setFlow::execute()
const volVectorField& C = mesh_.C();
const volVectorField d
(
typeName + ":d",
IOobject::scopedName(typeName, "d"),
C - dimensionedVector("origin", dimLength, origin_)
);
const scalarField x(d.component(vector::X));
@ -286,7 +286,7 @@ bool Foam::functionObjects::setFlow::execute()
const volVectorField d
(
typeName + ":d",
IOobject::scopedName(typeName, "d"),
C - dimensionedVector("origin", dimLength, origin_)
);
const scalarField x(d.component(vector::X));
@ -350,7 +350,7 @@ bool Foam::functionObjects::setFlow::execute()
const volVectorField d
(
typeName + ":d",
IOobject::scopedName(typeName, "d"),
C - dimensionedVector("origin", dimLength, origin_)
);
const scalarField x(d.component(vector::X));

View File

@ -321,16 +321,10 @@ bool Foam::functionObjects::stabilityBlendingFactor::init(bool first)
<< exit(FatalError);
}
auto tmagGradCC = tmp<volScalarField>::New
auto tmagGradCC = volScalarField::New
(
IOobject
(
"magGradCC",
time_.timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
"magGradCC",
IOobject::NO_REGISTER,
mesh_,
dimensionedScalar(dimless, Zero),
fvPatchFieldBase::zeroGradientType()
@ -340,20 +334,16 @@ bool Foam::functionObjects::stabilityBlendingFactor::init(bool first)
for (direction i=0; i<vector::nComponents; i++)
{
// Create field with zero grad
volScalarField cci
auto tcci = volScalarField::New
(
IOobject
(
"cc" + word(vector::componentNames[i]),
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
"cc" + word(vector::componentNames[i]),
IOobject::NO_REGISTER,
mesh_,
dimensionedScalar(dimLength, Zero),
fvPatchFieldBase::zeroGradientType()
);
auto& cci = tcci.ref();
cci = mesh_.C().component(i);
cci.correctBoundaryConditions();
magGradCC += mag(fvc::grad(cci)).ref();
@ -394,21 +384,14 @@ bool Foam::functionObjects::stabilityBlendingFactor::init(bool first)
<< exit(FatalError);
}
auto CoPtr = tmp<volScalarField>::New
auto CoPtr = volScalarField::New
(
IOobject
(
"Co",
time_.timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
"Co",
IOobject::NO_REGISTER,
mesh_,
dimensionedScalar(dimless, Zero),
fvPatchFieldBase::zeroGradientType()
);
auto& Co = CoPtr.ref();
Co.primitiveFieldRef() =
@ -533,17 +516,10 @@ Foam::functionObjects::stabilityBlendingFactor::stabilityBlendingFactor
read(dict);
setResultName(typeName, "");
auto faceBlendedPtr = tmp<surfaceScalarField>::New
auto faceBlendedPtr = surfaceScalarField::New
(
IOobject
(
resultName_,
time_.timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE,
IOobject::REGISTER
),
resultName_,
IOobject::REGISTER,
mesh_,
dimensionedScalar(dimless, Zero)
);

View File

@ -77,9 +77,10 @@ Foam::functionObjects::turbulenceFields::nuTilda
{
const dimensionedScalar omega0(dimless/dimTime, SMALL);
return tmp<volScalarField>::New
return volScalarField::New
(
"nuTilda.tmp",
IOobject::NO_REGISTER,
model.k()/(model.omega() + omega0)
);
}
@ -96,9 +97,10 @@ Foam::functionObjects::turbulenceFields::L
const scalar Cmu = 0.09;
const dimensionedScalar eps0(sqr(dimVelocity)/dimTime, SMALL);
return tmp<volScalarField>::New
return volScalarField::New
(
"L.tmp",
IOobject::NO_REGISTER,
pow(Cmu, 0.75)*pow(model.k(), 1.5)/(model.epsilon() + eps0)
);
}
@ -116,9 +118,10 @@ Foam::functionObjects::turbulenceFields::I
const volScalarField uPrime(sqrt((2.0/3.0)*model.k()));
const dimensionedScalar U0(dimVelocity, SMALL);
return tmp<volScalarField>::New
return volScalarField::New
(
"I.tmp",
IOobject::NO_REGISTER,
uPrime/max(max(uPrime, mag(model.U())), U0)
);
}

View File

@ -311,14 +311,10 @@ Foam::tmp<Foam::volScalarField> Foam::functionObjects::forces::rho() const
{
if (rhoName_ == "rhoInf")
{
return tmp<volScalarField>::New
return volScalarField::New
(
IOobject
(
"rho",
mesh_.time().timeName(),
mesh_
),
"rho",
IOobject::NO_REGISTER,
mesh_,
dimensionedScalar(dimDensity, rhoRef_)
);

View File

@ -182,7 +182,7 @@ Foam::functionObjects::hydrostaticPressure::hydrostaticPressure
if (read(dict))
{
// Read and store the initial ph_rgh field
volScalarField* ph_rghPtr =
volScalarField* ptr =
new volScalarField
(
IOobject
@ -197,7 +197,7 @@ Foam::functionObjects::hydrostaticPressure::hydrostaticPressure
mesh_
);
regIOobject::store(ph_rghPtr);
regIOobject::store(ptr);
bool reInitialise = dict.getOrDefault("reInitialise", false);

View File

@ -243,7 +243,7 @@ Foam::functionObjects::sizeDistribution::filterField
const scalarField& field
) const
{
return tmp<scalarField>(new scalarField(field, cellId_));
return tmp<scalarField>::New(field, cellId_);
}

View File

@ -78,12 +78,7 @@ Foam::functionObjects::electricPotential::sigma() const
{
const IOobject sigmaIO
(
IOobject::scopedName(typeName, "sigma"),
mesh_.time().timeName(),
mesh_.time(),
IOobject::NO_READ,
IOobject::NO_WRITE,
IOobject::NO_REGISTER
mesh_.thisDb().newIOobject(IOobject::scopedName(typeName, "sigma"))
);
if (phases_.size())
@ -125,12 +120,7 @@ Foam::functionObjects::electricPotential::epsilonm() const
const IOobject epsilonrIO
(
IOobject::scopedName(typeName, "epsilonr"),
mesh_.time().timeName(),
mesh_.time(),
IOobject::NO_READ,
IOobject::NO_WRITE,
IOobject::NO_REGISTER
mesh_.thisDb().newIOobject(IOobject::scopedName(typeName, "epsilonr"))
);
if (phases_.size())
@ -409,17 +399,10 @@ bool Foam::functionObjects::electricPotential::write()
// Write the current density field
tmp<volScalarField> tsigma = this->sigma();
auto eJ = tmp<volVectorField>::New
auto eJ = volVectorField::New
(
IOobject
(
IOobject::scopedName(typeName, "J"),
mesh_.time().timeName(),
mesh_.time(),
IOobject::NO_READ,
IOobject::NO_WRITE,
IOobject::NO_REGISTER
),
IOobject::scopedName(typeName, "J"),
IOobject::NO_REGISTER,
-tsigma*fvc::grad(eV),
fvPatchFieldBase::calculatedType()
);
@ -432,17 +415,10 @@ bool Foam::functionObjects::electricPotential::write()
// Write the free-charge density field
tmp<volScalarField> tepsilonm = this->epsilonm();
auto erho = tmp<volScalarField>::New
auto erho = volScalarField::New
(
IOobject
(
IOobject::scopedName(typeName, "rho"),
mesh_.time().timeName(),
mesh_.time(),
IOobject::NO_READ,
IOobject::NO_WRITE,
IOobject::NO_REGISTER
),
IOobject::scopedName(typeName, "rho"),
IOobject::NO_REGISTER,
fvc::div(tepsilonm*(-fvc::grad(eV))),
fvPatchFieldBase::calculatedType()
);

View File

@ -93,9 +93,10 @@ Foam::functionObjects::energyTransport::kappaEff() const
if (turbPtr)
{
return tmp<volScalarField>
return volScalarField::New
(
new volScalarField
"kappaEff",
IOobject::NO_REGISTER,
(
kappa() + Cp()*turbPtr->nut()*rho()/Prt_
)
@ -113,17 +114,10 @@ Foam::functionObjects::energyTransport::kappaEff() const
Foam::tmp<Foam::volScalarField>
Foam::functionObjects::energyTransport::rho() const
{
auto trho = tmp<volScalarField>::New
auto trho = volScalarField::New
(
IOobject
(
"trho",
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE,
IOobject::NO_REGISTER
),
"trho",
IOobject::NO_REGISTER,
mesh_,
rho_
);
@ -150,17 +144,10 @@ Foam::functionObjects::energyTransport::Cp() const
return tCp;
}
return tmp<volScalarField>::New
return volScalarField::New
(
IOobject
(
"tCp",
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE,
IOobject::NO_REGISTER
),
"tCp",
IOobject::NO_REGISTER,
mesh_,
Cp_
);
@ -181,22 +168,16 @@ Foam::functionObjects::energyTransport::kappa() const
return tkappa;
}
return tmp<volScalarField>::New
return volScalarField::New
(
IOobject
(
"tkappa",
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE,
IOobject::NO_REGISTER
),
"tkappa",
IOobject::NO_REGISTER,
mesh_,
kappa_
);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::energyTransport::energyTransport
@ -404,16 +385,10 @@ bool Foam::functionObjects::energyTransport::execute()
const surfaceScalarField CpPhi(rhoCp*phi);
auto trhoCp = tmp<volScalarField>::New
auto trhoCp = volScalarField::New
(
IOobject
(
"trhoCp",
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
"trhoCp",
IOobject::NO_REGISTER,
mesh_,
rhoCp
);

View File

@ -96,16 +96,10 @@ Foam::tmp<Foam::volScalarField> Foam::functionObjects::scalarTransport::D
if (constantD_)
{
return tmp<volScalarField>::New
return volScalarField::New
(
IOobject
(
Dname,
mesh_.time().timeName(),
mesh_.time(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
Dname,
IOobject::NO_REGISTER,
mesh_,
dimensionedScalar(Dname, phi.dimensions()/dimLength, D_)
);
@ -129,9 +123,10 @@ Foam::tmp<Foam::volScalarField> Foam::functionObjects::scalarTransport::D
if (turb)
{
return tmp<volScalarField>::New
return volScalarField::New
(
Dname,
IOobject::NO_REGISTER,
alphaD_ * turb->nu() + alphaDt_ * turb->nut()
);
}
@ -147,25 +142,20 @@ Foam::tmp<Foam::volScalarField> Foam::functionObjects::scalarTransport::D
if (turb)
{
return tmp<volScalarField>::New
return volScalarField::New
(
Dname,
IOobject::NO_REGISTER,
alphaD_ * turb->mu() + alphaDt_ * turb->mut()
);
}
}
return tmp<volScalarField>::New
return volScalarField::New
(
IOobject
(
Dname,
mesh_.time().timeName(),
mesh_.time(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
Dname,
IOobject::NO_REGISTER,
mesh_,
dimensionedScalar(phi.dimensions()/dimLength, Zero)
);