ENH: avoid undefined method in temperatureCoupledBase

- old constructor interface allowed arbitrary strings to specify the
  method enumeration. If actually used at runtime, they could/would
  raise a FatalError (unknown enumeration).
  Define a simpler default constructor instead.
This commit is contained in:
Mark Olesen
2022-09-14 10:36:01 +02:00
parent 1695f2f5b9
commit a8057c4bc6
9 changed files with 168 additions and 152 deletions

View File

@ -108,14 +108,7 @@ filmPyrolysisRadiativeCoupledMixedFvPatchScalarField
)
:
mixedFvPatchScalarField(p, iF),
temperatureCoupledBase
(
patch(),
"undefined",
"undefined",
"undefined-K",
"undefined-alpha"
),
temperatureCoupledBase(patch()), // default method (fluidThermo)
filmRegionName_("surfaceFilmProperties"),
pyrolysisRegionName_("pyrolysisProperties"),
TnbrName_("undefined-Tnbr"),

View File

@ -58,14 +58,7 @@ externalWallHeatFluxTemperatureFvPatchScalarField
)
:
mixedFvPatchScalarField(p, iF),
temperatureCoupledBase
(
patch(),
"undefined",
"undefined",
"undefined-K",
"undefined-alpha"
),
temperatureCoupledBase(patch()), // default method (fluidThermo)
mode_(fixedHeatFlux),
Q_(nullptr),
q_(nullptr),

View File

@ -45,14 +45,7 @@ fixedIncidentRadiationFvPatchScalarField
)
:
fixedGradientFvPatchScalarField(p, iF),
temperatureCoupledBase
(
patch(),
"undefined",
"undefined",
"undefined-K",
"undefined-alpha"
),
temperatureCoupledBase(patch()), // default method (fluidThermo)
qrIncident_(p.size(), Zero)
{}

View File

@ -132,14 +132,7 @@ humidityTemperatureCoupledMixedFvPatchScalarField
)
:
mixedFvPatchScalarField(p, iF),
temperatureCoupledBase
(
patch(),
"fluidThermo",
"undefined",
"undefined-K",
"undefined-alpha"
),
temperatureCoupledBase(patch(), temperatureCoupledBase::mtFluidThermo),
mode_(mtConstantMass),
pName_("p"),
UName_("U"),

View File

@ -41,14 +41,7 @@ lumpedMassWallTemperatureFvPatchScalarField
)
:
mixedFvPatchScalarField(p, iF),
temperatureCoupledBase
(
patch(),
"undefined",
"undefined",
"undefined-K",
"undefined-alpha"
),
temperatureCoupledBase(patch()), // default method (fluidThermo)
Cp_(0.0),
mass_(0.0),
curTimeIndex_(-1)

View File

@ -54,18 +54,70 @@ Foam::temperatureCoupledBase::KMethodTypeNames_
Foam::temperatureCoupledBase::temperatureCoupledBase
(
const fvPatch& patch,
const word& calculationType,
const word& kappaName,
const word& alphaAniName,
const word& alphaName
const KMethodType method
)
:
patch_(patch),
method_(KMethodTypeNames_[calculationType]),
method_(method),
kappaName_(),
alphaName_(),
alphaAniName_(),
kappaFunction1_(nullptr),
alphaFunction1_(nullptr)
{
switch (method_)
{
case mtDirectionalSolidThermo:
case mtLookup:
case mtFunction:
{
FatalErrorInFunction
<< "Cannot construct kappaMethod: "
<< KMethodTypeNames_[method_] << " without a dictionary"
<< abort(FatalError);
break;
}
default:
{
break;
}
}
}
Foam::temperatureCoupledBase::temperatureCoupledBase
(
const fvPatch& patch,
const KMethodType method,
const word& kappaName,
const word& alphaName,
const word& alphaAniName
)
:
patch_(patch),
method_(method),
kappaName_(kappaName),
alphaName_(alphaName),
alphaAniName_(alphaAniName),
alphaName_(alphaName)
{}
kappaFunction1_(nullptr),
alphaFunction1_(nullptr)
{
switch (method_)
{
case mtFunction:
{
FatalErrorInFunction
<< "Cannot construct kappaMethod: "
<< KMethodTypeNames_[method_] << " without a dictionary"
<< abort(FatalError);
break;
}
default:
{
break;
}
}
}
Foam::temperatureCoupledBase::temperatureCoupledBase
@ -77,8 +129,10 @@ Foam::temperatureCoupledBase::temperatureCoupledBase
patch_(patch),
method_(KMethodTypeNames_.get("kappaMethod", dict)),
kappaName_(dict.getOrDefault<word>("kappa", word::null)),
alphaName_(dict.getOrDefault<word>("alpha", word::null)),
alphaAniName_(dict.getOrDefault<word>("alphaAni", word::null)),
alphaName_(dict.getOrDefault<word>("alpha", word::null))
kappaFunction1_(nullptr),
alphaFunction1_(nullptr)
{
switch (method_)
{
@ -89,7 +143,7 @@ Foam::temperatureCoupledBase::temperatureCoupledBase
FatalIOErrorInFunction(dict)
<< "Did not find entry 'alphaAni'"
" required for 'kappaMethod' "
<< KMethodTypeNames_[method_]
<< KMethodTypeNames_[method_] << nl
<< exit(FatalIOError);
}
@ -104,8 +158,8 @@ Foam::temperatureCoupledBase::temperatureCoupledBase
<< "Did not find entry 'kappa'"
" required for 'kappaMethod' "
<< KMethodTypeNames_[method_] << nl
<< " Please set 'kappa' to the name of a volScalarField"
" or volSymmTensorField"
<< "Please set 'kappa' to the name of"
" a volScalar or volSymmTensor field" << nl
<< exit(FatalIOError);
}
@ -116,16 +170,18 @@ Foam::temperatureCoupledBase::temperatureCoupledBase
{
kappaFunction1_ = PatchFunction1<scalar>::New
(
patch.patch(),
patch_.patch(),
"kappaValue",
dict
);
alphaFunction1_ = PatchFunction1<scalar>::New
(
patch.patch(),
patch_.patch(),
"alphaValue",
dict
);
break;
}
default:
@ -141,13 +197,7 @@ Foam::temperatureCoupledBase::temperatureCoupledBase
const temperatureCoupledBase& base
)
:
patch_(base.patch_),
method_(base.method_),
kappaName_(base.kappaName_),
alphaAniName_(base.alphaAniName_),
alphaName_(base.alphaName_),
kappaFunction1_(base.kappaFunction1_.clone(patch_.patch())),
alphaFunction1_(base.alphaFunction1_.clone(patch_.patch()))
temperatureCoupledBase(base.patch_, base)
{}
@ -160,8 +210,8 @@ Foam::temperatureCoupledBase::temperatureCoupledBase
patch_(patch),
method_(base.method_),
kappaName_(base.kappaName_),
alphaAniName_(base.alphaAniName_),
alphaName_(base.alphaName_),
alphaAniName_(base.alphaAniName_),
kappaFunction1_(base.kappaFunction1_.clone(patch_.patch())),
alphaFunction1_(base.alphaFunction1_.clone(patch_.patch()))
{}
@ -281,6 +331,7 @@ Foam::tmp<Foam::scalarField> Foam::temperatureCoupledBase::kappa
mesh.lookupObject<solidThermo>(basicThermo::dictName);
return thermo.kappa(patchi);
break;
}
@ -306,35 +357,42 @@ Foam::tmp<Foam::scalarField> Foam::temperatureCoupledBase::kappa
case mtLookup:
{
if (mesh.foundObject<volScalarField>(kappaName_))
{
return patch_.lookupPatchField<volScalarField, scalar>
(
kappaName_
);
}
else if (mesh.foundObject<volSymmTensorField>(kappaName_))
{
const symmTensorField& KWall =
patch_.lookupPatchField<volSymmTensorField, scalar>
(
kappaName_
);
const auto* ptr =
mesh.cfindObject<volScalarField>(kappaName_);
const vectorField n(patch_.nf());
if (ptr)
{
return patch_.patchField<volScalarField>(*ptr);
}
}
return n & KWall & n;
}
else
{
FatalErrorInFunction
<< "Did not find field " << kappaName_
<< " on mesh " << mesh.name() << " patch " << patch_.name()
<< nl
<< " Please set 'kappa' to the name of a volScalarField"
<< " or volSymmTensorField."
<< exit(FatalError);
const auto* ptr =
mesh.cfindObject<volSymmTensorField>(kappaName_);
if (ptr)
{
const symmTensorField& wallValues =
patch_.patchField<volSymmTensorField>(*ptr);
const vectorField n(patch_.nf());
return n & wallValues & n;
}
}
FatalErrorInFunction
<< "Did not find field '" << kappaName_
<< "' on mesh " << mesh.name()
<< " patch " << patch_.name() << nl
<< "Please set 'kappa' to the name of"
" a volScalar or volSymmTensor field"
", or use another method" << nl
<< " " << flatOutput(KMethodTypeNames_.sortedToc()) << nl
<< exit(FatalError);
break;
}
@ -351,8 +409,8 @@ Foam::tmp<Foam::scalarField> Foam::temperatureCoupledBase::kappa
<< "Unimplemented method " << KMethodTypeNames_[method_] << nl
<< "Please set 'kappaMethod' to one of "
<< flatOutput(KMethodTypeNames_.sortedToc()) << nl
<< "and 'kappa' to the name of the volScalar"
<< " or volSymmTensor field (if kappaMethod=lookup)"
<< "If kappaMethod=lookup, also set 'kappa' to the name of"
" a volScalar or volSymmTensor field" << nl
<< exit(FatalError);
break;
@ -452,39 +510,41 @@ Foam::tmp<Foam::scalarField> Foam::temperatureCoupledBase::alpha
case mtLookup:
{
if (mesh.foundObject<volScalarField>(alphaName_))
{
return
patch_.lookupPatchField<volScalarField, scalar>
(
alphaName_
);
}
else if (mesh.foundObject<volSymmTensorField>(alphaName_))
{
const symmTensorField& alphaWall =
patch_.lookupPatchField<volSymmTensorField, scalar>
(
alphaName_
);
const auto* ptr =
mesh.cfindObject<volScalarField>(alphaName_);
const vectorField n(patch_.nf());
if (ptr)
{
return patch_.patchField<volScalarField>(*ptr);
}
}
return n & alphaWall & n;
}
else
{
FatalErrorInFunction
<< "Did not find field " << alphaName_
<< " on mesh " << mesh.name() << " patch " << patch_.name()
<< nl
<< "Please set 'kappaMethod' to one of "
<< flatOutput(KMethodTypeNames_.sortedToc()) << nl
<< "and 'alpha' to the name of the volScalar"
<< " or volSymmTensor field (if kappaMethod=lookup)"
<< exit(FatalError);
const auto* ptr =
mesh.cfindObject<volSymmTensorField>(alphaName_);
if (ptr)
{
const symmTensorField& wallValues =
patch_.patchField<volSymmTensorField>(*ptr);
const vectorField n(patch_.nf());
return n & wallValues & n;
}
}
FatalErrorInFunction
<< "Did not find field '" << alphaName_
<< "' on mesh " << mesh.name()
<< " patch " << patch_.name() << nl
<< "Please set 'alpha' to the name of"
" a volScalar or volSymmTensor field"
", or use another method" << nl
<< " " << flatOutput(KMethodTypeNames_.sortedToc()) << nl
<< exit(FatalError);
break;
}
@ -501,8 +561,8 @@ Foam::tmp<Foam::scalarField> Foam::temperatureCoupledBase::alpha
<< "Unimplemented method " << KMethodTypeNames_[method_] << nl
<< "Please set 'kappaMethod' to one of "
<< flatOutput(KMethodTypeNames_.sortedToc()) << nl
<< "and 'alpha' to the name of the volScalar"
<< " or volSymmTensor field (if kappaMethod=lookup)"
<< "If kappaMethod=lookup, also set 'alpha' to the name of"
" a volScalar or volSymmTensor field" << nl
<< exit(FatalError);
break;

View File

@ -46,11 +46,11 @@ Description
\table
Property | Description | Required | Default
kappaMethod | Thermal conductivity method | yes |
kappa | Name of thermal conductivity field | no |
alpha | Name of thermal diffusivity field | no |
alphaAni | Name of non-isotropic alpha | no |
kappaValue | Function1 supplying kappa | no |
alphaValue | Function1 supplying alpha | no |
kappa | Name of thermal conductivity field | partly |
alpha | Name of thermal diffusivity field | partly |
alphaAni | Name of non-isotropic alpha | partly |
kappaValue | Function1 supplying kappa | partly |
alphaValue | Function1 supplying alpha | partly |
\endtable
Usage
@ -130,12 +130,12 @@ protected:
//- Name of thermal conductivity field (if looked up from database)
const word kappaName_;
//- Name of the non-Isotropic alpha (default: Anialpha)
const word alphaAniName_;
//- Name of thermal diffusivity
const word alphaName_;
//- Name of the non-isotropic alpha (for directional solidThermo)
const word alphaAniName_;
//- Function1 for kappa
autoPtr<PatchFunction1<scalar>> kappaFunction1_;
@ -147,14 +147,22 @@ public:
// Constructors
//- Construct from patch and K name
//- Default construct from patch, using fluidThermo (default)
//- or specified method
explicit temperatureCoupledBase
(
const fvPatch& patch,
const KMethodType method = KMethodType::mtFluidThermo
);
//- Construct from patch, method type and field names
temperatureCoupledBase
(
const fvPatch& patch,
const word& calculationMethod,
const KMethodType method,
const word& kappaName,
const word& alphaAniName,
const word& alphaName
const word& alphaName,
const word& alphaAniName
);
//- Construct from patch and dictionary
@ -171,18 +179,15 @@ public:
const temperatureCoupledBase& base
);
//- Construct as copy
temperatureCoupledBase
(
const temperatureCoupledBase&
);
//- Copy construct
temperatureCoupledBase(const temperatureCoupledBase& base);
//- Destructor
virtual ~temperatureCoupledBase() = default;
// Member functions
// Member Functions
//- Method to obtain K
word KMethod() const
@ -191,13 +196,13 @@ public:
}
//- Name of thermal conductivity field
const word& kappaName() const
const word& kappaName() const noexcept
{
return kappaName_;
}
//- Name of thermal diffusivity field
const word& alphaName() const
const word& alphaName() const noexcept
{
return alphaName_;
}

View File

@ -49,14 +49,7 @@ turbulentTemperatureCoupledBaffleMixedFvPatchScalarField
)
:
mixedFvPatchScalarField(p, iF),
temperatureCoupledBase
(
patch(),
"undefined",
"undefined",
"undefined-K",
"undefined-alpha"
),
temperatureCoupledBase(patch()), // default method (fluidThermo)
mappedPatchFieldBase<scalar>
(
mappedPatchFieldBase<scalar>::mapper(p, iF),

View File

@ -51,14 +51,7 @@ turbulentTemperatureRadCoupledMixedFvPatchScalarField
)
:
mixedFvPatchScalarField(p, iF),
temperatureCoupledBase
(
patch(),
"undefined",
"undefined",
"undefined-K",
"undefined-alpha"
),
temperatureCoupledBase(patch()), // default method (fluidThermo)
mappedPatchFieldBase<scalar>
(
mappedPatchFieldBase<scalar>::mapper(p, iF),