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

- src/faOptions, src/fvOptions
This commit is contained in:
Mark Olesen
2024-01-23 09:50:54 +01:00
parent 092db087c9
commit 710eb5c142
17 changed files with 178 additions and 256 deletions

View File

@ -41,8 +41,8 @@ Foam::tmp<Foam::faMatrix<Type>> Foam::fa::optionList::source
{ {
checkApplied(); checkApplied();
tmp<faMatrix<Type>> tmtx(new faMatrix<Type>(field, ds)); auto tmtx = tmp<faMatrix<Type>>::New(field, ds);
faMatrix<Type>& mtx = tmtx.ref(); auto& mtx = tmtx.ref();
for (fa::option& source : *this) for (fa::option& source : *this)
{ {
@ -132,8 +132,8 @@ Foam::tmp<Foam::faMatrix<Type>> Foam::fa::optionList::operator()
rho.dimensions()*field.dimensions()/dimTime*dimArea rho.dimensions()*field.dimensions()/dimTime*dimArea
); );
tmp<faMatrix<Type>> tmtx(new faMatrix<Type>(field, ds)); auto tmtx = tmp<faMatrix<Type>>::New(field, ds);
faMatrix<Type>& mtx = tmtx.ref(); auto& mtx = tmtx.ref();
for (fa::option& source : *this) for (fa::option& source : *this)
{ {
@ -184,8 +184,8 @@ Foam::tmp<Foam::faMatrix<Type>> Foam::fa::optionList::operator()
const dimensionSet dsMat(ds*dimArea); const dimensionSet dsMat(ds*dimArea);
tmp<faMatrix<Type>> tmtx(new faMatrix<Type>(field, dsMat)); auto tmtx = tmp<faMatrix<Type>>::New(field, dsMat);
faMatrix<Type>& mtx = tmtx.ref(); auto& mtx = tmtx.ref();
for (fa::option& source : *this) for (fa::option& source : *this)
{ {

View File

@ -58,11 +58,12 @@ Foam::fa::jouleHeatingSource::jouleHeatingSource
( (
IOobject IOobject
( (
typeName + ":V_" + regionName_, IOobject::scopedName(typeName, "V_" + regionName_),
regionMesh().thisDb().time().timeName(), regionMesh().thisDb().time().timeName(),
regionMesh().thisDb(), regionMesh().thisDb(),
IOobject::MUST_READ, IOobject::MUST_READ,
IOobject::AUTO_WRITE IOobject::AUTO_WRITE,
IOobject::REGISTER
), ),
regionMesh() regionMesh()
), ),
@ -141,6 +142,11 @@ void Foam::fa::jouleHeatingSource::addSup
} }
// Add the Joule heating contribution // Add the Joule heating contribution
const word sigmaName
(
IOobject::scopedName(typeName, "sigma_" + regionName_)
);
areaVectorField gradV("gradV", fac::grad(V_)); areaVectorField gradV("gradV", fac::grad(V_));
if (debug > 1 && mesh().time().writeTime()) if (debug > 1 && mesh().time().writeTime())
@ -156,20 +162,14 @@ void Foam::fa::jouleHeatingSource::addSup
if (anisotropicElectricalConductivity_) if (anisotropicElectricalConductivity_)
{ {
const auto& sigma = const auto& sigma =
obr.lookupObject<areaTensorField> obr.lookupObject<areaTensorField>(sigmaName);
(
typeName + ":sigma_" + regionName_
);
tsource = (h*sigma & gradV) & gradV; tsource = (h*sigma & gradV) & gradV;
} }
else else
{ {
const auto& sigma = const auto& sigma =
obr.lookupObject<areaScalarField> obr.lookupObject<areaScalarField>(sigmaName);
(
typeName + ":sigma_" + regionName_
);
tsource = (h*sigma*gradV) & gradV; tsource = (h*sigma*gradV) & gradV;
} }

View File

@ -36,13 +36,13 @@ void Foam::fa::jouleHeatingSource::initialiseSigma
autoPtr<Function1<Type>>& sigmaVsTPtr autoPtr<Function1<Type>>& sigmaVsTPtr
) )
{ {
typedef GeometricField<Type, faPatchField, areaMesh> AreaFieldType; typedef GeometricField<Type, faPatchField, areaMesh> FieldType;
auto& obr = regionMesh().thisDb(); auto& obr = regionMesh().thisDb();
IOobject io IOobject io
( (
typeName + ":sigma_" + regionName_, IOobject::scopedName(typeName, "sigma_" + regionName_),
obr.time().timeName(), obr.time().timeName(),
obr, obr,
IOobject::NO_READ, IOobject::NO_READ,
@ -50,7 +50,7 @@ void Foam::fa::jouleHeatingSource::initialiseSigma
IOobject::REGISTER IOobject::REGISTER
); );
tmp<AreaFieldType> tsigma; autoPtr<FieldType> tsigma;
if (dict.found("sigma")) if (dict.found("sigma"))
{ {
@ -59,7 +59,7 @@ void Foam::fa::jouleHeatingSource::initialiseSigma
tsigma.reset tsigma.reset
( (
new AreaFieldType new FieldType
( (
io, io,
regionMesh(), regionMesh(),
@ -76,7 +76,7 @@ void Foam::fa::jouleHeatingSource::initialiseSigma
// Sigma to be defined by user input // Sigma to be defined by user input
io.readOpt(IOobject::MUST_READ); io.readOpt(IOobject::MUST_READ);
tsigma.reset(new AreaFieldType(io, regionMesh())); tsigma.reset(new FieldType(io, regionMesh()));
Info<< " Conductivity 'sigma' read from file" << nl << endl; Info<< " Conductivity 'sigma' read from file" << nl << endl;
} }
@ -92,12 +92,15 @@ Foam::fa::jouleHeatingSource::updateSigma
const autoPtr<Function1<Type>>& sigmaVsTPtr const autoPtr<Function1<Type>>& sigmaVsTPtr
) const ) const
{ {
typedef GeometricField<Type, faPatchField, areaMesh> AreaFieldType; typedef GeometricField<Type, faPatchField, areaMesh> FieldType;
const auto& obr = regionMesh().thisDb(); const auto& obr = regionMesh().thisDb();
auto& sigma = auto& sigma =
obr.lookupObjectRef<AreaFieldType>(typeName + ":sigma_" + regionName_); obr.lookupObjectRef<FieldType>
(
IOobject::scopedName(typeName, "sigma_" + regionName_)
);
if (!sigmaVsTPtr) if (!sigmaVsTPtr)
{ {

View File

@ -34,30 +34,23 @@ License
namespace Foam namespace Foam
{ {
namespace fv
{
static inline tmp<volScalarField> createField static inline tmp<volScalarField> createField
( (
const fvMesh& mesh, const fvMesh& mesh,
const scalar val const scalar val
) )
{ {
return tmp<volScalarField>::New return volScalarField::New
(
IOobject
( (
polyMesh::defaultRegion, polyMesh::defaultRegion,
mesh.time().timeName(), IOobject::NO_REGISTER,
mesh, mesh,
IOobjectOption::NO_READ, val,
IOobject::NO_WRITE, dimless
IOobject::NO_REGISTER
),
mesh,
dimensionedScalar(dimless, val)
); );
} }
} // End namespace fv
} // End namespace Foam } // End namespace Foam

View File

@ -87,16 +87,10 @@ Foam::tmp<Foam::volScalarField> Foam::fv::limitTurbulenceViscosity::nu() const
const auto* dictPtr = mesh_.cfindObject<dictionary>("transportProperties"); const auto* dictPtr = mesh_.cfindObject<dictionary>("transportProperties");
if (dictPtr) if (dictPtr)
{ {
return return volScalarField::New
tmp<volScalarField>::New
(
IOobject
( (
"nu", "nu",
mesh_.time().timeName(), IOobject::NO_REGISTER,
mesh_,
IOobject::NO_READ
),
mesh_, mesh_,
dimensionedScalar("nu", dimViscosity, *dictPtr) dimensionedScalar("nu", dimViscosity, *dictPtr)
); );

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2016-2021 OpenCFD Ltd. Copyright (C) 2016-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -87,23 +87,13 @@ Foam::fv::acousticDampingSource::acousticDampingSource
fv::cellSetOption(name, modelType, dict, mesh), fv::cellSetOption(name, modelType, dict, mesh),
blendFactor_ blendFactor_
( (
volScalarField mesh_.newIOobject(IOobject::scopedName(name_, "blend")),
(
IOobject
(
name_ + ":blend",
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_, mesh_,
scalar(1), scalar(1),
dimless, dimless,
fvPatchFieldBase::zeroGradientType() fvPatchFieldBase::zeroGradientType()
)
), ),
frequency_("frequency", dimless/dimTime, 0), frequency_("frequency", dimless/dimTime, Zero),
x0_(Zero), x0_(Zero),
r1_(0), r1_(0),
r2_(0), r2_(0),
@ -122,8 +112,15 @@ void Foam::fv::acousticDampingSource::addSup
const label fieldI const label fieldI
) )
{ {
auto tcoeff = volScalarField::New
(
IOobject::scopedName(name_, "coeff"),
IOobject::NO_REGISTER,
w_*frequency_*blendFactor_
);
const auto& coeff = tcoeff();
const volVectorField& U = eqn.psi(); const volVectorField& U = eqn.psi();
const volScalarField coeff(name_ + ":coeff", w_*frequency_*blendFactor_);
const auto& URef = mesh().lookupObject<volVectorField>(URefName_); const auto& URef = mesh().lookupObject<volVectorField>(URefName_);
fvMatrix<vector> dampingEqn fvMatrix<vector> dampingEqn
@ -141,8 +138,15 @@ void Foam::fv::acousticDampingSource::addSup
const label fieldI const label fieldI
) )
{ {
auto tcoeff = volScalarField::New
(
IOobject::scopedName(name_, "coeff"),
IOobject::NO_REGISTER,
w_*frequency_*blendFactor_
);
const auto& coeff = tcoeff();
const volVectorField& U = eqn.psi(); const volVectorField& U = eqn.psi();
const volScalarField coeff(name_ + ":coeff", w_*frequency_*blendFactor_);
const auto& URef = mesh().lookupObject<volVectorField>(URefName_); const auto& URef = mesh().lookupObject<volVectorField>(URefName_);
fvMatrix<vector> dampingEqn fvMatrix<vector> dampingEqn
@ -161,8 +165,15 @@ void Foam::fv::acousticDampingSource::addSup
const label fieldI const label fieldI
) )
{ {
auto tcoeff = volScalarField::New
(
IOobject::scopedName(name_, "coeff"),
IOobject::NO_REGISTER,
w_*frequency_*blendFactor_
);
const auto& coeff = tcoeff();
const volVectorField& U = eqn.psi(); const volVectorField& U = eqn.psi();
const volScalarField coeff(name_ + ":coeff", w_*frequency_*blendFactor_);
const auto& URef = mesh().lookupObject<volVectorField>(URefName_); const auto& URef = mesh().lookupObject<volVectorField>(URefName_);
fvMatrix<vector> dampingEqn fvMatrix<vector> dampingEqn

View File

@ -148,7 +148,8 @@ void Foam::fv::directionalPressureGradientExplicitSource::writeProps
"uniform", "uniform",
mesh_, mesh_,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE IOobject::NO_WRITE,
IOobject::NO_REGISTER
) )
); );
propsDict.add("gradient", gradP); propsDict.add("gradient", gradP);
@ -463,23 +464,18 @@ void Foam::fv::directionalPressureGradientExplicitSource::addSup
const label fieldI const label fieldI
) )
{ {
DimensionedField<vector, volMesh> Su auto tSu = DimensionedField<vector, volMesh>::New
(
IOobject
( (
name_ + fieldNames_[fieldI] + "Sup", name_ + fieldNames_[fieldI] + "Sup",
mesh_.time().timeName(), IOobject::NO_REGISTER,
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_, mesh_,
dimensionedVector(eqn.dimensions()/dimVolume, Zero) dimensionedVector(eqn.dimensions()/dimVolume, Zero)
); );
auto& Su = tSu.ref();
UIndirectList<vector>(Su, cells_) = gradP0_ + dGradP_ + gradPporous_; UIndirectList<vector>(Su, cells_) = gradP0_ + dGradP_ + gradPporous_;
eqn += Su; eqn += tSu;
} }
@ -506,14 +502,7 @@ void Foam::fv::directionalPressureGradientExplicitSource::constrain
( (
new volScalarField new volScalarField
( (
IOobject mesh_.newIOobject(IOobject::scopedName(name_, "invA")),
(
name_ + ":invA",
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
1.0/eqn.A() 1.0/eqn.A()
) )
); );

View File

@ -44,8 +44,6 @@ namespace fv
} }
} }
const Foam::word Foam::fv::jouleHeatingSource::sigmaName(typeName + ":sigma");
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -55,17 +53,10 @@ Foam::fv::jouleHeatingSource::transformSigma
const volVectorField& sigmaLocal const volVectorField& sigmaLocal
) const ) const
{ {
auto tsigma = tmp<volSymmTensorField>::New auto tsigma = volSymmTensorField::New
( (
IOobject IOobject::scopedName(typeName, "sigma"),
( IOobject::NO_REGISTER,
sigmaName,
mesh_.time().timeName(),
mesh_.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE,
IOobject::NO_REGISTER
),
mesh_, mesh_,
dimensionedSymmTensor(sigmaLocal.dimensions(), Zero), dimensionedSymmTensor(sigmaLocal.dimensions(), Zero),
fvPatchFieldBase::zeroGradientType() fvPatchFieldBase::zeroGradientType()
@ -115,11 +106,12 @@ Foam::fv::jouleHeatingSource::jouleHeatingSource
( (
IOobject IOobject
( (
typeName + ":V", IOobject::scopedName(typeName, "V"),
mesh.time().timeName(), mesh.time().timeName(),
mesh, mesh,
IOobject::MUST_READ, IOobject::MUST_READ,
IOobject::AUTO_WRITE IOobject::AUTO_WRITE,
IOobject::REGISTER
), ),
mesh mesh
), ),
@ -182,6 +174,10 @@ void Foam::fv::jouleHeatingSource::addSup
} }
// Add the Joule heating contribution // Add the Joule heating contribution
const word sigmaName
(
IOobject::scopedName(typeName, "sigma")
);
const volVectorField gradV(fvc::grad(V_)); const volVectorField gradV(fvc::grad(V_));
if (anisotropicElectricalConductivity_) if (anisotropicElectricalConductivity_)

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2016-2020 OpenCFD Ltd. Copyright (C) 2016-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -179,9 +179,6 @@ class jouleHeatingSource
{ {
// Private Data // Private Data
//- Name of electrical conductivity field
static const word sigmaName;
//- Name of temperature field //- Name of temperature field
word TName_; word TName_;

View File

@ -34,11 +34,11 @@ void Foam::fv::jouleHeatingSource::initialiseSigma
autoPtr<Function1<Type>>& sigmaVsTPtr autoPtr<Function1<Type>>& sigmaVsTPtr
) )
{ {
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType; typedef GeometricField<Type, fvPatchField, volMesh> FieldType;
IOobject io IOobject io
( (
typeName + ":sigma", IOobject::scopedName(typeName, "sigma"),
mesh_.time().timeName(), mesh_.time().timeName(),
mesh_.thisDb(), mesh_.thisDb(),
IOobject::NO_READ, IOobject::NO_READ,
@ -46,7 +46,7 @@ void Foam::fv::jouleHeatingSource::initialiseSigma
IOobject::REGISTER IOobject::REGISTER
); );
tmp<VolFieldType> tsigma; autoPtr<FieldType> tsigma;
if (dict.found("sigma")) if (dict.found("sigma"))
{ {
@ -55,7 +55,7 @@ void Foam::fv::jouleHeatingSource::initialiseSigma
tsigma.reset tsigma.reset
( (
new VolFieldType new FieldType
( (
io, io,
mesh_, mesh_,
@ -72,7 +72,7 @@ void Foam::fv::jouleHeatingSource::initialiseSigma
// Sigma to be defined by user input // Sigma to be defined by user input
io.readOpt(IOobject::MUST_READ); io.readOpt(IOobject::MUST_READ);
tsigma.reset(new VolFieldType(io, mesh_)); tsigma.reset(new FieldType(io, mesh_));
Info<< " Conductivity 'sigma' read from file" << nl << endl; Info<< " Conductivity 'sigma' read from file" << nl << endl;
} }
@ -88,9 +88,12 @@ Foam::fv::jouleHeatingSource::updateSigma
const autoPtr<Function1<Type>>& sigmaVsTPtr const autoPtr<Function1<Type>>& sigmaVsTPtr
) const ) const
{ {
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType; typedef GeometricField<Type, fvPatchField, volMesh> FieldType;
auto& sigma = mesh_.lookupObjectRef<VolFieldType>(typeName + ":sigma"); auto& sigma = mesh_.lookupObjectRef<FieldType>
(
IOobject::scopedName(typeName, "sigma")
);
if (!sigmaVsTPtr) if (!sigmaVsTPtr)
{ {

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018-2021 OpenCFD Ltd. Copyright (C) 2018-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -63,7 +63,8 @@ void Foam::fv::meanVelocityForce::writeProps
"uniform", "uniform",
mesh_, mesh_,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE IOobject::NO_WRITE,
IOobject::NO_REGISTER
) )
); );
propsDict.add("gradient", gradP); propsDict.add("gradient", gradP);
@ -192,25 +193,20 @@ void Foam::fv::meanVelocityForce::addSup
const label fieldi const label fieldi
) )
{ {
volVectorField::Internal Su auto tSu = volVectorField::Internal::New
(
IOobject
( (
name_ + fieldNames_[fieldi] + "Sup", name_ + fieldNames_[fieldi] + "Sup",
mesh_.time().timeName(), IOobject::NO_REGISTER,
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_, mesh_,
dimensionedVector(eqn.dimensions()/dimVolume, Zero) dimensionedVector(eqn.dimensions()/dimVolume, Zero)
); );
auto& Su = tSu.ref();
scalar gradP = gradP0_ + dGradP_; scalar gradP = gradP0_ + dGradP_;
UIndirectList<vector>(Su, cells_) = flowDir_*gradP; UIndirectList<vector>(Su, cells_) = flowDir_*gradP;
eqn += Su; eqn += tSu;
} }
@ -237,14 +233,7 @@ void Foam::fv::meanVelocityForce::constrain
( (
new volScalarField new volScalarField
( (
IOobject mesh_.newIOobject(IOobject::scopedName(name_, "rA")),
(
name_ + ":rA",
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
1.0/eqn.A() 1.0/eqn.A()
) )
); );

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018-2022 OpenCFD Ltd. Copyright (C) 2018-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -238,23 +238,19 @@ void Foam::fv::rotorDiskSource::setFaceArea(vector& axis, const bool correct)
if (debug) if (debug)
{ {
volScalarField area auto tarea = volScalarField::New
( (
IOobject IOobject::scopedName(name_, "area"),
( IOobject::NO_REGISTER,
name_ + ":area",
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_, mesh_,
dimensionedScalar(dimArea, Zero) dimensionedScalar(dimArea, Zero)
); );
UIndirectList<scalar>(area.primitiveField(), cells_) = area_; auto& area = tarea.ref();
Info<< type() << ": " << name_ << " writing field " << area.name() UIndirectList<scalar>(area.primitiveFieldRef(), cells_) = area_;
<< endl;
Info<< type() << ": " << name_
<< " writing field " << area.name() << endl;
area.write(); area.write();
} }
@ -480,17 +476,14 @@ void Foam::fv::rotorDiskSource::addSup
const label fieldi const label fieldi
) )
{ {
volVectorField force auto tforce = volVectorField::New
( (
IOobject IOobject::scopedName(name_, "rotorForce"),
( IOobject::NO_REGISTER,
name_ + ":rotorForce",
mesh_.time().timeName(),
mesh_
),
mesh_, mesh_,
dimensionedVector(eqn.dimensions()/dimVolume, Zero) dimensionedVector(eqn.dimensions()/dimVolume, Zero)
); );
auto& force = tforce.ref();
// Read the reference density for incompressible flow // Read the reference density for incompressible flow
coeffs_.readEntry("rhoRef", rhoRef_); coeffs_.readEntry("rhoRef", rhoRef_);
@ -516,17 +509,14 @@ void Foam::fv::rotorDiskSource::addSup
const label fieldi const label fieldi
) )
{ {
volVectorField force auto tforce = volVectorField::New
( (
IOobject IOobject::scopedName(name_, "rotorForce"),
( IOobject::NO_REGISTER,
name_ + ":rotorForce",
mesh_.time().timeName(),
mesh_
),
mesh_, mesh_,
dimensionedVector(eqn.dimensions()/dimVolume, Zero) dimensionedVector(eqn.dimensions()/dimVolume, Zero)
); );
auto& force = tforce.ref();
const vectorField Uin(inflowVelocity(eqn.psi())); const vectorField Uin(inflowVelocity(eqn.psi()));
trim_->correct(rho, Uin, force); trim_->correct(rho, Uin, force);

View File

@ -178,37 +178,28 @@ void Foam::fv::rotorDiskSource::writeField
const bool writeNow const bool writeNow
) const ) const
{ {
typedef GeometricField<Type, fvPatchField, volMesh> FieldType;
if (mesh_.time().writeTime() || writeNow) if (mesh_.time().writeTime() || writeNow)
{ {
auto tfield = tmp<FieldType>::New if (cells_.size() != values.size())
( {
IOobject FatalErrorInFunction
<< "Size mismatch. Number of cells "
<< cells_.size() << " != number of values "
<< values.size() << nl
<< abort(FatalError);
}
auto tfield = GeometricField<Type, fvPatchField, volMesh>::New
( (
name, name,
mesh_.time().timeName(), IOobject::NO_REGISTER,
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_, mesh_,
dimensioned<Type>(dimless, Zero) dimensioned<Type>(dimless, Zero)
); );
auto& field = tfield.ref().primitiveFieldRef(); auto& field = tfield.ref().primitiveFieldRef();
if (cells_.size() != values.size()) UIndirectList<Type>(field, cells_) = values;
{
FatalErrorInFunction
<< abort(FatalError);
}
forAll(cells_, i)
{
const label celli = cells_[i];
field[celli] = values[i];
}
tfield().write(); tfield().write();
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2014-2017 OpenFOAM Foundation Copyright (C) 2014-2017 OpenFOAM Foundation
Copyright (C) 2018-2021 OpenCFD Ltd. Copyright (C) 2018-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -78,16 +78,9 @@ Foam::fv::solidificationMeltingSource::Cp() const
{ {
const scalar CpRef = coeffs_.get<scalar>("CpRef"); const scalar CpRef = coeffs_.get<scalar>("CpRef");
return tmp<volScalarField>::New return volScalarField::New
( (
IOobject IOobject::scopedName(name_, "Cp"),
(
name_ + ":Cp",
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_, mesh_,
dimensionedScalar dimensionedScalar
( (
@ -184,11 +177,12 @@ Foam::fv::solidificationMeltingSource::solidificationMeltingSource
( (
IOobject IOobject
( (
name_ + ":alpha1", IOobject::scopedName(name_, "alpha1"),
mesh.time().timeName(), mesh.time().timeName(),
mesh, mesh,
IOobject::READ_IF_PRESENT, IOobject::READ_IF_PRESENT,
IOobject::AUTO_WRITE IOobject::AUTO_WRITE,
IOobject::REGISTER
), ),
mesh, mesh,
dimensionedScalar(dimless, Zero), dimensionedScalar(dimless, Zero),

View File

@ -47,16 +47,10 @@ namespace fv
Foam::tmp<Foam::volScalarField> Foam::fv::viscousDissipation::rho() const Foam::tmp<Foam::volScalarField> Foam::fv::viscousDissipation::rho() const
{ {
auto trho = tmp<volScalarField>::New auto trho = volScalarField::New
(
IOobject
( (
"trho", "trho",
mesh_.time().timeName(), IOobject::NO_REGISTER,
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_, mesh_,
rho_ rho_
); );
@ -177,16 +171,10 @@ void Foam::fv::viscousDissipation::addSup
const word gradUName("grad(" + UName_ + ')'); const word gradUName("grad(" + UName_ + ')');
auto tgradU = tmp<GradFieldType>::New auto tgradU = GradFieldType::New
(
IOobject
( (
"gradU", "gradU",
mesh_.time().timeName(), IOobject::NO_REGISTER,
mesh_.time(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_, mesh_,
dimensionedTensor(inv(dimTime), Zero) dimensionedTensor(inv(dimTime), Zero)
); );

View File

@ -336,6 +336,7 @@ void Foam::fv::SemiImplicitSource<Type>::addSup
tsu = DimensionedField<Type, volMesh>::New tsu = DimensionedField<Type, volMesh>::New
( (
name_ + fieldName + "Su", name_ + fieldName + "Su",
IOobject::NO_REGISTER,
mesh_, mesh_,
dimensioned<Type>(SuDims, Zero) dimensioned<Type>(SuDims, Zero)
); );
@ -375,6 +376,7 @@ void Foam::fv::SemiImplicitSource<Type>::addSup
tsu = DimensionedField<Type, volMesh>::New tsu = DimensionedField<Type, volMesh>::New
( (
name_ + fieldName + "Su", name_ + fieldName + "Su",
IOobject::NO_REGISTER,
mesh_, mesh_,
dimensioned<Type>(SuDims, Zero) dimensioned<Type>(SuDims, Zero)
); );
@ -462,6 +464,7 @@ void Foam::fv::SemiImplicitSource<Type>::addSup
tsp = DimensionedField<scalar, volMesh>::New tsp = DimensionedField<scalar, volMesh>::New
( (
name_ + fieldName + "Sp", name_ + fieldName + "Sp",
IOobject::NO_REGISTER,
mesh_, mesh_,
dimensioned<scalar>(SpDims, Zero) dimensioned<scalar>(SpDims, Zero)
); );
@ -501,6 +504,7 @@ void Foam::fv::SemiImplicitSource<Type>::addSup
tsp = DimensionedField<scalar, volMesh>::New tsp = DimensionedField<scalar, volMesh>::New
( (
name_ + fieldName + "Sp", name_ + fieldName + "Sp",
IOobject::NO_REGISTER,
mesh_, mesh_,
dimensioned<scalar>(SpDims, Zero) dimensioned<scalar>(SpDims, Zero)
); );

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd. Copyright (C) 2020-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -93,16 +93,16 @@ void Foam::fv::interRegionExplicitPorositySource::initialise()
<< abort(FatalError); << abort(FatalError);
} }
porosityPtr_.reset porosityPtr_.reset(nullptr);
(
porosityPtr_ =
porosityModel::New porosityModel::New
( (
name_, name_,
nbrMesh, nbrMesh,
coeffs_, coeffs_,
zoneName zoneName
).ptr() );
),
firstIter_ = false; firstIter_ = false;
} }
@ -146,19 +146,14 @@ void Foam::fv::interRegionExplicitPorositySource::addSup
const volVectorField& U = eqn.psi(); const volVectorField& U = eqn.psi();
volVectorField UNbr auto tUNbr = volVectorField::New
( (
IOobject IOobject::scopedName(name_, "UNbr"),
( IOobject::NO_REGISTER,
name_ + ":UNbr",
nbrMesh.time().timeName(),
nbrMesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
nbrMesh, nbrMesh,
dimensionedVector(U.dimensions(), Zero) dimensionedVector(U.dimensions(), Zero)
); );
auto& UNbr = tUNbr.ref();
// Map local velocity onto neighbour region // Map local velocity onto neighbour region
meshInterp().mapSrcToTgt meshInterp().mapSrcToTgt
@ -177,7 +172,7 @@ void Foam::fv::interRegionExplicitPorositySource::addSup
scalarField& Udiag = porosityEqn.diag(); scalarField& Udiag = porosityEqn.diag();
vectorField& Usource = porosityEqn.source(); vectorField& Usource = porosityEqn.source();
Udiag.setSize(eqn.diag().size(), 0.0); Udiag.setSize(eqn.diag().size(), Zero);
Usource.setSize(eqn.source().size(), Zero); Usource.setSize(eqn.source().size(), Zero);
meshInterp().mapTgtToSrc(nbrEqn.diag(), plusEqOp<scalar>(), Udiag); meshInterp().mapTgtToSrc(nbrEqn.diag(), plusEqOp<scalar>(), Udiag);
@ -200,19 +195,14 @@ void Foam::fv::interRegionExplicitPorositySource::addSup
const volVectorField& U = eqn.psi(); const volVectorField& U = eqn.psi();
volVectorField UNbr auto tUNbr = volVectorField::New
( (
IOobject IOobject::scopedName(name_, "UNbr"),
( IOobject::NO_REGISTER,
name_ + ":UNbr",
nbrMesh.time().timeName(),
nbrMesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
nbrMesh, nbrMesh,
dimensionedVector(U.dimensions(), Zero) dimensionedVector(U.dimensions(), Zero)
); );
auto& UNbr = tUNbr.ref();
// Map local velocity onto neighbour region // Map local velocity onto neighbour region
meshInterp().mapSrcToTgt meshInterp().mapSrcToTgt
@ -224,33 +214,23 @@ void Foam::fv::interRegionExplicitPorositySource::addSup
fvMatrix<vector> nbrEqn(UNbr, eqn.dimensions()); fvMatrix<vector> nbrEqn(UNbr, eqn.dimensions());
volScalarField rhoNbr auto trhoNbr = volScalarField::New
( (
IOobject IOobject::scopedName("rho", "UNbr"),
( IOobject::NO_REGISTER,
"rho:UNbr",
nbrMesh.time().timeName(),
nbrMesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
nbrMesh, nbrMesh,
dimensionedScalar(dimDensity, Zero) dimensionedScalar(dimDensity, Zero)
); );
auto& rhoNbr = trhoNbr.ref();
volScalarField muNbr auto tmuNbr = volScalarField::New
( (
IOobject IOobject::scopedName("mu", "UNbr"),
( IOobject::NO_REGISTER,
"mu:UNbr",
nbrMesh.time().timeName(),
nbrMesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
nbrMesh, nbrMesh,
dimensionedScalar(dimViscosity, Zero) dimensionedScalar(dimViscosity, Zero)
); );
auto& muNbr = tmuNbr.ref();
const auto& mu = mesh_.lookupObject<volScalarField>(muName_); const auto& mu = mesh_.lookupObject<volScalarField>(muName_);
@ -277,7 +257,7 @@ void Foam::fv::interRegionExplicitPorositySource::addSup
scalarField& Udiag = porosityEqn.diag(); scalarField& Udiag = porosityEqn.diag();
vectorField& Usource = porosityEqn.source(); vectorField& Usource = porosityEqn.source();
Udiag.setSize(eqn.diag().size(), 0.0); Udiag.setSize(eqn.diag().size(), Zero);
Usource.setSize(eqn.source().size(), Zero); Usource.setSize(eqn.source().size(), Zero);
meshInterp().mapTgtToSrc(nbrEqn.diag(), plusEqOp<scalar>(), Udiag); meshInterp().mapTgtToSrc(nbrEqn.diag(), plusEqOp<scalar>(), Udiag);