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-2021 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 {
36  defineTypeNameAndDebug(limitTemperature, 0);
38  (
39  fvConstraint,
40  limitTemperature,
41  dictionary
42  );
43 }
44 }
45 
46 
47 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
48 
49 void Foam::fv::limitTemperature::readCoeffs()
50 {
51  Tmin_ = coeffs().lookup<scalar>("min");
52  Tmax_ = coeffs().lookup<scalar>("max");
53  phaseName_ = coeffs().lookupOrDefault<word>("phase", word::null);
54 }
55 
56 
57 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
58 
60 (
61  const word& name,
62  const word& modelType,
63  const dictionary& dict,
64  const fvMesh& mesh
65 )
66 :
67  fvConstraint(name, modelType, dict, mesh),
68  set_(coeffs(), mesh),
69  Tmin_(-vGreat),
70  Tmax_(vGreat),
71  phaseName_(word::null)
72 {
73  readCoeffs();
74 }
75 
76 
77 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
78 
80 {
81  const basicThermo& thermo =
82  mesh().lookupObject<basicThermo>
83  (
85  );
86 
87  return wordList(1, thermo.he().name());
88 }
89 
90 
92 {
93  const basicThermo& thermo =
94  mesh().lookupObject<basicThermo>
95  (
97  );
98 
99  const labelList& cells = set_.cells();
100 
101  scalarField Tmin(cells.size(), Tmin_);
102  scalarField Tmax(cells.size(), Tmax_);
103 
104  scalarField heMin(thermo.he(Tmin, cells));
105  scalarField heMax(thermo.he(Tmax, cells));
106 
107  scalarField& hec = he.primitiveFieldRef();
108 
109  forAll(cells, i)
110  {
111  const label celli = cells[i];
112  hec[celli]= max(min(hec[celli], heMax[i]), heMin[i]);
113  }
114 
115  // Handle boundaries in the case of 'all'
116  if (set_.selectionMode() == fvCellSet::selectionModeType::all)
117  {
118  volScalarField::Boundary& bf = he.boundaryFieldRef();
119 
120  forAll(bf, patchi)
121  {
122  fvPatchScalarField& hep = bf[patchi];
123 
124  if (!hep.fixesValue())
125  {
126  scalarField Tminp(hep.size(), Tmin_);
127  scalarField Tmaxp(hep.size(), Tmax_);
128 
129  scalarField heMinp(thermo.he(Tminp, patchi));
130  scalarField heMaxp(thermo.he(Tmaxp, patchi));
131 
132  forAll(hep, facei)
133  {
134  hep[facei] =
135  max(min(hep[facei], heMaxp[facei]), heMinp[facei]);
136  }
137  }
138  }
139  }
140 
141  return cells.size();
142 }
143 
144 
146 {
147  set_.updateMesh(mpm);
148 }
149 
150 
152 {
153  if (fvConstraint::read(dict))
154  {
155  set_.read(coeffs());
156  readCoeffs();
157  return true;
158  }
159  else
160  {
161  return false;
162  }
163 }
164 
165 
166 // ************************************************************************* //
limitTemperature(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from components.
defineTypeNameAndDebug(fixedTemperatureConstraint, 0)
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
const word & name() const
Return name.
Definition: IOobject.H:303
fluidReactionThermo & thermo
Definition: createFields.H:28
Base-class for fluid and solid thermodynamic properties.
Definition: basicThermo.H:77
virtual bool fixesValue() const
Return true if this patch field fixes a value.
Definition: fvPatchField.H:296
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:66
virtual bool constrain(volScalarField &he) const
Constrain the energy field.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
Macros for easy insertion into run-time selection tables.
virtual volScalarField & he()=0
Enthalpy/Internal energy [J/kg].
virtual void updateMesh(const mapPolyMesh &)
Update for mesh changes.
dynamicFvMesh & mesh
const cellShapeList & cells
A class for handling words, derived from string.
Definition: word.H:59
labelList fv(nPoints)
static word groupName(Name name, const word &group)
static const word null
An empty word.
Definition: word.H:77
static const word dictName
Name of the thermophysical properties dictionary.
Definition: basicThermo.H:129
Internal::FieldType & primitiveFieldRef()
Return a reference to the internal field.
thermo he()
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
virtual wordList constrainedFields() const
Return the list of fields constrained by the fvConstraint.
addToRunTimeSelectionTable(fvConstraint, fixedTemperatureConstraint, dictionary)
List< word > wordList
A List of words.
Definition: fileName.H:54
label patchi
Boundary & boundaryFieldRef()
Return a reference to the boundary field.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
virtual bool read(const dictionary &dict)
Read dictionary.
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: fvConstraint.C:143
Finite volume options abstract base class.
Definition: fvConstraint.H:54
Namespace for OpenFOAM.