fvConstraints::limitTemperature: Added options energy/temperature field name

The energy field limited to limit the temperature is obtained automatically from
the thermo package for the phase except for compressibleInterFoam which uniquely
solves for mixture temperature directly rather than energy.  To limit this
temperature rather than the energy the optional 'field' entry should be set to
'T', e.g.:

    limitT
    {
        type limitTemperature;
        selectionMode all;
        field T;
        min 310;
        max 500;
    }
This commit is contained in:
Henry Weller
2021-10-12 12:28:27 +01:00
parent 12dc41d0fb
commit fb53b915b2
2 changed files with 87 additions and 40 deletions

View File

@ -50,6 +50,7 @@ void Foam::fv::limitTemperature::readCoeffs()
{ {
Tmin_ = coeffs().lookup<scalar>("min"); Tmin_ = coeffs().lookup<scalar>("min");
Tmax_ = coeffs().lookup<scalar>("max"); Tmax_ = coeffs().lookup<scalar>("max");
fieldName_ = coeffs().lookupOrDefault<word>("field", word::null);
phaseName_ = coeffs().lookupOrDefault<word>("phase", word::null); phaseName_ = coeffs().lookupOrDefault<word>("phase", word::null);
} }
@ -68,6 +69,7 @@ Foam::fv::limitTemperature::limitTemperature
set_(coeffs(), mesh), set_(coeffs(), mesh),
Tmin_(-vGreat), Tmin_(-vGreat),
Tmax_(vGreat), Tmax_(vGreat),
fieldName_(word::null),
phaseName_(word::null) phaseName_(word::null)
{ {
readCoeffs(); readCoeffs();
@ -78,6 +80,12 @@ Foam::fv::limitTemperature::limitTemperature
Foam::wordList Foam::fv::limitTemperature::constrainedFields() const Foam::wordList Foam::fv::limitTemperature::constrainedFields() const
{ {
if (fieldName_ != word::null)
{
return wordList(1, IOobject::groupName(fieldName_, phaseName_));
}
else
{
const basicThermo& thermo = const basicThermo& thermo =
mesh().lookupObject<basicThermo> mesh().lookupObject<basicThermo>
( (
@ -85,31 +93,63 @@ Foam::wordList Foam::fv::limitTemperature::constrainedFields() const
); );
return wordList(1, thermo.he().name()); return wordList(1, thermo.he().name());
}
} }
bool Foam::fv::limitTemperature::constrain(volScalarField& he) const bool Foam::fv::limitTemperature::constrain(volScalarField& he) const
{ {
const labelList& cells = set_.cells();
if (he.dimensions() == dimTemperature)
{
scalarField& Tc = he.primitiveFieldRef();
forAll(cells, i)
{
const label celli = cells[i];
Tc[celli] = max(min(Tc[celli], Tmax_), Tmin_);
}
// Handle boundaries in the case of 'all'
if (set_.selectionMode() == fvCellSet::selectionModeType::all)
{
volScalarField::Boundary& Tbf = he.boundaryFieldRef();
forAll(Tbf, patchi)
{
fvPatchScalarField& Tp = Tbf[patchi];
if (!Tp.fixesValue())
{
forAll(Tp, facei)
{
Tp[facei] = max(min(Tp[facei], Tmax_), Tmin_);
}
}
}
}
}
else
{
const basicThermo& thermo = const basicThermo& thermo =
mesh().lookupObject<basicThermo> mesh().lookupObject<basicThermo>
( (
IOobject::groupName(physicalProperties::typeName, phaseName_) IOobject::groupName(physicalProperties::typeName, phaseName_)
); );
const labelList& cells = set_.cells(); const scalarField Tmin(cells.size(), Tmin_);
const scalarField Tmax(cells.size(), Tmax_);
scalarField Tmin(cells.size(), Tmin_); const scalarField heMin(thermo.he(Tmin, cells));
scalarField Tmax(cells.size(), Tmax_); const scalarField heMax(thermo.he(Tmax, cells));
scalarField heMin(thermo.he(Tmin, cells));
scalarField heMax(thermo.he(Tmax, cells));
scalarField& hec = he.primitiveFieldRef(); scalarField& hec = he.primitiveFieldRef();
forAll(cells, i) forAll(cells, i)
{ {
const label celli = cells[i]; const label celli = cells[i];
hec[celli]= max(min(hec[celli], heMax[i]), heMin[i]); hec[celli] = max(min(hec[celli], heMax[i]), heMin[i]);
} }
// Handle boundaries in the case of 'all' // Handle boundaries in the case of 'all'
@ -123,11 +163,11 @@ bool Foam::fv::limitTemperature::constrain(volScalarField& he) const
if (!hep.fixesValue()) if (!hep.fixesValue())
{ {
scalarField Tminp(hep.size(), Tmin_); const scalarField Tminp(hep.size(), Tmin_);
scalarField Tmaxp(hep.size(), Tmax_); const scalarField Tmaxp(hep.size(), Tmax_);
scalarField heMinp(thermo.he(Tminp, patchi)); const scalarField heMinp(thermo.he(Tminp, patchi));
scalarField heMaxp(thermo.he(Tmaxp, patchi)); const scalarField heMaxp(thermo.he(Tmaxp, patchi));
forAll(hep, facei) forAll(hep, facei)
{ {
@ -137,6 +177,7 @@ bool Foam::fv::limitTemperature::constrain(volScalarField& he) const
} }
} }
} }
}
return cells.size(); return cells.size();
} }

View File

@ -36,6 +36,9 @@ Usage
selectionMode all; selectionMode all;
// field T; // Optional energy/temperature field name
// Set to T for compressibleInterFoam
phase gas; // Optional phase name phase gas; // Optional phase name
min 200; min 200;
@ -80,6 +83,9 @@ class limitTemperature
//- Maximum temperature limit [K] //- Maximum temperature limit [K]
scalar Tmax_; scalar Tmax_;
//- Optional energy/temperature field name
word fieldName_;
//- Optional phase name //- Optional phase name
word phaseName_; word phaseName_;