fixedTemperatureConstraint.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 
27 #include "fvMesh.H"
28 #include "fvMatrices.H"
29 #include "basicThermo.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  namespace fv
37  {
38  defineTypeNameAndDebug(fixedTemperatureConstraint, 0);
40  (
41  fvConstraint,
42  fixedTemperatureConstraint,
43  dictionary
44  );
45  }
46 
47  template<>
48  const char* NamedEnum<fv::fixedTemperatureConstraint::temperatureMode, 2>::
49  names[] =
50  {
51  "uniform",
52  "lookup"
53  };
54 }
55 
58 
59 
60 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
61 
62 void Foam::fv::fixedTemperatureConstraint::readCoeffs()
63 {
64  mode_ = modeNames_.read(coeffs().lookup("mode"));
65 
66  switch (mode_)
67  {
68  case temperatureMode::uniform:
69  {
70  TValue_.reset
71  (
72  Function1<scalar>::New("temperature", coeffs()).ptr()
73  );
74  break;
75  }
77  {
78  TName_ = coeffs().lookupOrDefault<word>("T", "T");
79  break;
80  }
81  }
82 
83  phaseName_ = coeffs().lookupOrDefault<word>("phase", word::null);
84 }
85 
86 
87 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
88 
90 (
91  const word& name,
92  const word& modelType,
93  const dictionary& dict,
94  const fvMesh& mesh
95 )
96 :
97  fvConstraint(name, modelType, dict, mesh),
98  set_(coeffs(), mesh),
99  mode_(temperatureMode::uniform),
100  TValue_(nullptr),
101  TName_(word::null),
102  phaseName_(word::null)
103 {
104  readCoeffs();
105 }
106 
107 
108 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
109 
111 {
112  const basicThermo& thermo =
113  mesh().lookupObject<basicThermo>
114  (
116  );
117 
118  return wordList(1, thermo.he().name());
119 }
120 
121 
123 (
124  fvMatrix<scalar>& eqn,
125  const word& fieldName
126 ) const
127 {
128  const labelList& cells = set_.cells();
129 
130  const basicThermo& thermo =
131  mesh().lookupObject<basicThermo>
132  (
134  );
135 
136  switch (mode_)
137  {
138  case temperatureMode::uniform:
139  {
140  const scalar t = mesh().time().value();
141  scalarField Tuni(cells.size(), TValue_->value(t));
142  eqn.setValues(cells, thermo.he(Tuni, cells));
143  break;
144  }
146  {
147  const volScalarField& T =
148  mesh().lookupObject<volScalarField>(TName_);
149  scalarField Tlkp(T, cells);
150  eqn.setValues(cells, thermo.he(Tlkp, cells));
151  break;
152  }
153  }
154 
155  return cells.size();
156 }
157 
158 
160 {
161  set_.updateMesh(mpm);
162 }
163 
164 
166 {
167  if (fvConstraint::read(dict))
168  {
169  set_.read(coeffs());
170  readCoeffs();
171  return true;
172  }
173  else
174  {
175  return false;
176  }
177 }
178 
179 
180 // ************************************************************************* //
virtual bool read(const dictionary &dict)
Read dictionary.
defineTypeNameAndDebug(fixedTemperatureConstraint, 0)
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
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
static const NamedEnum< temperatureMode, 2 > modeNames_
String representation of mode enums.
fixedTemperatureConstraint(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from components.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
virtual void updateMesh(const mapPolyMesh &)
Update for mesh changes.
virtual bool constrain(fvMatrix< scalar > &eqn, const word &fieldName) const
Constrain energy equation to fix the temperature.
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:51
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].
stressControl lookup("compactNormalStress") >> compactNormalStress
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)
void setValues(const labelUList &cells, const UList< Type > &values)
Set solution in given cells to the specified values.
Definition: fvMatrix.C:484
static const word null
An empty word.
Definition: word.H:77
A special matrix type and solver, designed for finite volume solutions of scalar equations. Face addressing is used to make all matrix assembly and solution loops vectorise.
Definition: fvPatchField.H:72
virtual wordList constrainedFields() const
Return the list of fields constrained by the fvConstraint.
static const word dictName
Name of the thermophysical properties dictionary.
Definition: basicThermo.H:129
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
addToRunTimeSelectionTable(fvConstraint, fixedTemperatureConstraint, dictionary)
List< word > wordList
A List of words.
Definition: fileName.H:54
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
A special matrix type and solver, designed for finite volume solutions of scalar equations.
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.
static autoPtr< Function1< scalar > > New(const word &name, const dictionary &dict)
Selector.
Definition: Function1New.C:32