limitTemperature.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2012-2026 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "limitTemperature.H"
27 #include "basicThermo.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace fv
35 {
38  (
42  );
43 }
44 }
45 
46 
47 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
48 
49 void Foam::fv::limitTemperature::readCoeffs(const dictionary& dict)
50 {
51  Tmin_ = dict.lookup<scalar>("min");
52  Tmax_ = dict.lookup<scalar>("max");
53  fieldName_ = dict.lookupOrDefault<word>("field", word::null);
54  phaseName_ = dict.lookupOrDefault<word>("phase", word::null);
55 }
56 
57 
58 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
59 
61 (
62  const word& name,
63  const word& modelType,
64  const fvMesh& mesh,
65  const dictionary& dict
66 )
67 :
68  fvConstraint(name, modelType, mesh, dict),
69  zone_(mesh, coeffs(dict)),
70  Tmin_(-vGreat),
71  Tmax_(vGreat),
72  fieldName_(word::null),
73  phaseName_(word::null)
74 {
75  readCoeffs(coeffs(dict));
76 }
77 
78 
79 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
80 
82 {
83  if (fieldName_ != word::null)
84  {
85  return wordList(1, IOobject::groupName(fieldName_, phaseName_));
86  }
87  else
88  {
89  const basicThermo& thermo =
91  (
93  );
94 
95  return wordList(1, thermo.he().name());
96  }
97 }
98 
99 
101 {
102  zone_.regenerate();
103  const labelList& cells = zone_.zone();
104 
105  if (he.dimensions() == dimTemperature)
106  {
107  scalarField& Tc = he.primitiveFieldRef();
108 
109  forAll(cells, i)
110  {
111  const label celli = cells[i];
112  Tc[celli] = max(min(Tc[celli], Tmax_), Tmin_);
113  }
114 
115  // Handle boundaries in the case of 'all'
116  if (zone_.all())
117  {
119 
120  forAll(Tbf, patchi)
121  {
122  fvPatchScalarField& Tp = Tbf[patchi];
123 
124  if (!Tp.fixesValue())
125  {
126  forAll(Tp, facei)
127  {
128  Tp[facei] = max(min(Tp[facei], Tmax_), Tmin_);
129  }
130  }
131  }
132  }
133  }
134  else
135  {
136  const basicThermo& thermo =
138  (
140  );
141 
142  const scalarField Tmin(cells.size(), Tmin_);
143  const scalarField Tmax(cells.size(), Tmax_);
144 
145  const scalarField heMin(thermo.he(Tmin, cells));
146  const scalarField heMax(thermo.he(Tmax, cells));
147 
148  scalarField& hec = he.primitiveFieldRef();
149 
150  forAll(cells, i)
151  {
152  const label celli = cells[i];
153  hec[celli] = max(min(hec[celli], heMax[i]), heMin[i]);
154  }
155 
156  // Handle boundaries in the case of 'all'
157  if (zone_.all())
158  {
160 
161  forAll(bf, patchi)
162  {
163  fvPatchScalarField& hep = bf[patchi];
164 
165  if (!hep.fixesValue())
166  {
167  const scalarField Tminp(hep.size(), Tmin_);
168  const scalarField Tmaxp(hep.size(), Tmax_);
169 
170  const scalarField heMinp(thermo.he(Tminp, patchi));
171  const scalarField heMaxp(thermo.he(Tmaxp, patchi));
172 
173  forAll(hep, facei)
174  {
175  hep[facei] =
176  max(min(hep[facei], heMaxp[facei]), heMinp[facei]);
177  }
178  }
179  }
180  }
181  }
182 
183  return cells.size();
184 }
185 
186 
188 {
189  zone_.movePoints();
190  return true;
191 }
192 
193 
195 {
196  zone_.topoChange(map);
197 }
198 
199 
201 {
202  zone_.mapMesh(map);
203 }
204 
205 
207 {
208  zone_.distribute(map);
209 }
210 
211 
213 {
215  {
216  zone_.read(coeffs(dict));
217  readCoeffs(coeffs(dict));
218  return true;
219  }
220  else
221  {
222  return false;
223  }
224 }
225 
226 
227 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Macros for easy insertion into run-time selection tables.
const dimensionSet & dimensions() const
Return dimensions.
Generic GeometricBoundaryField class.
Generic GeometricField class.
Internal::FieldType & primitiveFieldRef()
Return a reference to the primitive field.
Boundary & boundaryFieldRef()
Return a reference to the boundary field.
static word groupName(Name name, const word &group)
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Base-class for fluid and solid thermodynamic properties.
Definition: basicThermo.H:78
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Finite volume options abstract base class.
Definition: fvConstraint.H:57
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: fvConstraint.C:163
const dictionary & coeffs(const dictionary &) const
Return the coefficients sub-dictionary.
Definition: fvConstraintI.H:41
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:98
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:90
virtual bool fixesValue() const
Return true if this patch field fixes a value.
Definition: fvPatchField.H:326
Limits the temperature to be between minimum and maximum values.
virtual bool movePoints()
Update for mesh motion.
virtual void topoChange(const polyTopoChangeMap &)
Update topology using the given map.
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
virtual bool read(const dictionary &dict)
Read dictionary.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
virtual bool constrain(volScalarField &he) const
Constrain the energy field.
limitTemperature(const word &name, const word &modelType, const fvMesh &mesh, const dictionary &dict)
Construct from components.
virtual wordList constrainedFields() const
Return the list of fields constrained by the fvConstraint.
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type and name.
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:51
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
A class for handling words, derived from string.
Definition: word.H:63
static const word null
An empty word.
Definition: word.H:78
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
label patchi
const cellShapeList & cells
addToRunTimeSelectionTable(fvConstraint, bound, dictionary)
defineTypeNameAndDebug(bound, 0)
Namespace for OpenFOAM.
List< word > wordList
A List of words.
Definition: fileName.H:54
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
String typeName(const std::type_info &info)
Return the un-mangled name given the standard type info.
dimensioned< Type > min(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
const dimensionSet & dimTemperature
Definition: dimensions.C:143
dimensioned< Type > max(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
labelList fv(nPoints)
dictionary dict
fluidMulticomponentThermo & thermo
Definition: createFields.H:15