From fb53b915b2439f67fb88f6d46c671bbd18f70cb6 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Tue, 12 Oct 2021 12:28:27 +0100 Subject: [PATCH] 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; } --- .../limitTemperature/limitTemperature.C | 121 ++++++++++++------ .../limitTemperature/limitTemperature.H | 6 + 2 files changed, 87 insertions(+), 40 deletions(-) diff --git a/src/fvConstraints/limitTemperature/limitTemperature.C b/src/fvConstraints/limitTemperature/limitTemperature.C index 98415b7539..7a7a73feaa 100644 --- a/src/fvConstraints/limitTemperature/limitTemperature.C +++ b/src/fvConstraints/limitTemperature/limitTemperature.C @@ -50,6 +50,7 @@ void Foam::fv::limitTemperature::readCoeffs() { Tmin_ = coeffs().lookup("min"); Tmax_ = coeffs().lookup("max"); + fieldName_ = coeffs().lookupOrDefault("field", word::null); phaseName_ = coeffs().lookupOrDefault("phase", word::null); } @@ -68,6 +69,7 @@ Foam::fv::limitTemperature::limitTemperature set_(coeffs(), mesh), Tmin_(-vGreat), Tmax_(vGreat), + fieldName_(word::null), phaseName_(word::null) { readCoeffs(); @@ -78,61 +80,100 @@ Foam::fv::limitTemperature::limitTemperature Foam::wordList Foam::fv::limitTemperature::constrainedFields() const { - const basicThermo& thermo = - mesh().lookupObject - ( - IOobject::groupName(physicalProperties::typeName, phaseName_) - ); + if (fieldName_ != word::null) + { + return wordList(1, IOobject::groupName(fieldName_, phaseName_)); + } + else + { + const basicThermo& thermo = + mesh().lookupObject + ( + IOobject::groupName(physicalProperties::typeName, phaseName_) + ); - return wordList(1, thermo.he().name()); + return wordList(1, thermo.he().name()); + } } bool Foam::fv::limitTemperature::constrain(volScalarField& he) const { - const basicThermo& thermo = - mesh().lookupObject - ( - IOobject::groupName(physicalProperties::typeName, phaseName_) - ); - const labelList& cells = set_.cells(); - scalarField Tmin(cells.size(), Tmin_); - scalarField Tmax(cells.size(), Tmax_); - - scalarField heMin(thermo.he(Tmin, cells)); - scalarField heMax(thermo.he(Tmax, cells)); - - scalarField& hec = he.primitiveFieldRef(); - - forAll(cells, i) + if (he.dimensions() == dimTemperature) { - const label celli = cells[i]; - hec[celli]= max(min(hec[celli], heMax[i]), heMin[i]); - } + scalarField& Tc = he.primitiveFieldRef(); - // Handle boundaries in the case of 'all' - if (set_.selectionMode() == fvCellSet::selectionModeType::all) - { - volScalarField::Boundary& bf = he.boundaryFieldRef(); - - forAll(bf, patchi) + forAll(cells, i) { - fvPatchScalarField& hep = bf[patchi]; + const label celli = cells[i]; + Tc[celli] = max(min(Tc[celli], Tmax_), Tmin_); + } - if (!hep.fixesValue()) + // Handle boundaries in the case of 'all' + if (set_.selectionMode() == fvCellSet::selectionModeType::all) + { + volScalarField::Boundary& Tbf = he.boundaryFieldRef(); + + forAll(Tbf, patchi) { - scalarField Tminp(hep.size(), Tmin_); - scalarField Tmaxp(hep.size(), Tmax_); + fvPatchScalarField& Tp = Tbf[patchi]; - scalarField heMinp(thermo.he(Tminp, patchi)); - scalarField heMaxp(thermo.he(Tmaxp, patchi)); - - forAll(hep, facei) + if (!Tp.fixesValue()) { - hep[facei] = - max(min(hep[facei], heMaxp[facei]), heMinp[facei]); + forAll(Tp, facei) + { + Tp[facei] = max(min(Tp[facei], Tmax_), Tmin_); + } + } + } + } + } + else + { + const basicThermo& thermo = + mesh().lookupObject + ( + IOobject::groupName(physicalProperties::typeName, phaseName_) + ); + + const scalarField Tmin(cells.size(), Tmin_); + const scalarField Tmax(cells.size(), Tmax_); + + const scalarField heMin(thermo.he(Tmin, cells)); + const scalarField heMax(thermo.he(Tmax, cells)); + + scalarField& hec = he.primitiveFieldRef(); + + forAll(cells, i) + { + const label celli = cells[i]; + hec[celli] = max(min(hec[celli], heMax[i]), heMin[i]); + } + + // Handle boundaries in the case of 'all' + if (set_.selectionMode() == fvCellSet::selectionModeType::all) + { + volScalarField::Boundary& bf = he.boundaryFieldRef(); + + forAll(bf, patchi) + { + fvPatchScalarField& hep = bf[patchi]; + + if (!hep.fixesValue()) + { + const scalarField Tminp(hep.size(), Tmin_); + const scalarField Tmaxp(hep.size(), Tmax_); + + const scalarField heMinp(thermo.he(Tminp, patchi)); + const scalarField heMaxp(thermo.he(Tmaxp, patchi)); + + forAll(hep, facei) + { + hep[facei] = + max(min(hep[facei], heMaxp[facei]), heMinp[facei]); + } } } } diff --git a/src/fvConstraints/limitTemperature/limitTemperature.H b/src/fvConstraints/limitTemperature/limitTemperature.H index db493398db..ee53d73e4c 100644 --- a/src/fvConstraints/limitTemperature/limitTemperature.H +++ b/src/fvConstraints/limitTemperature/limitTemperature.H @@ -36,6 +36,9 @@ Usage selectionMode all; + // field T; // Optional energy/temperature field name + // Set to T for compressibleInterFoam + phase gas; // Optional phase name min 200; @@ -80,6 +83,9 @@ class limitTemperature //- Maximum temperature limit [K] scalar Tmax_; + //- Optional energy/temperature field name + word fieldName_; + //- Optional phase name word phaseName_;