fixedTemperatureConstraint.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2012-2016 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  option,
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 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
61 
62 Foam::fv::fixedTemperatureConstraint::fixedTemperatureConstraint
63 (
64  const word& name,
65  const word& modelType,
66  const dictionary& dict,
67  const fvMesh& mesh
68 )
69 :
70  cellSetOption(name, modelType, dict, mesh),
71  mode_(temperatureModeNames_.read(coeffs_.lookup("mode"))),
72  Tuniform_(NULL),
73  TName_("T")
74 {
75  switch (mode_)
76  {
77  case tmUniform:
78  {
79  Tuniform_.reset
80  (
81  Function1<scalar>::New("temperature", coeffs_).ptr()
82  );
83  break;
84  }
85  case tmLookup:
86  {
87  TName_ = coeffs_.lookupOrDefault<word>("T", "T");
88  break;
89  }
90  default:
91  {
92  // error handling done by NamedEnum
93  }
94  }
95 
96 
97  // Set the field name to that of the energy field from which the temperature
98  // is obtained
99 
100  const basicThermo& thermo =
101  mesh_.lookupObject<basicThermo>(basicThermo::dictName);
102 
103  fieldNames_.setSize(1, thermo.he().name());
104 
105  applied_.setSize(1, false);
106 }
107 
108 
109 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
110 
112 (
113  fvMatrix<scalar>& eqn,
114  const label
115 )
116 {
117  const basicThermo& thermo =
118  mesh_.lookupObject<basicThermo>(basicThermo::dictName);
119 
120  switch (mode_)
121  {
122  case tmUniform:
123  {
124  const scalar t = mesh_.time().value();
125  scalarField Tuni(cells_.size(), Tuniform_->value(t));
126  eqn.setValues(cells_, thermo.he(thermo.p(), Tuni, cells_));
127 
128  break;
129  }
130  case tmLookup:
131  {
132  const volScalarField& T =
133  mesh().lookupObject<volScalarField>(TName_);
134 
135  scalarField Tlkp(T, cells_);
136  eqn.setValues(cells_, thermo.he(thermo.p(), Tlkp, cells_));
137 
138  break;
139  }
140  default:
141  {
142  // error handling done by NamedEnum
143  }
144  }
145 }
146 
147 
149 {
150  if (cellSetOption::read(dict))
151  {
152  if (coeffs_.found(Tuniform_->name()))
153  {
154  Tuniform_.reset
155  (
156  Function1<scalar>::New(Tuniform_->name(), dict).ptr()
157  );
158  }
159 
160  coeffs_.readIfPresent("T", TName_);
161 
162  return true;
163  }
164  else
165  {
166  return false;
167  }
168 }
169 
170 
171 // ************************************************************************* //
defineTypeNameAndDebug(option, 0)
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: Function1.H:53
dictionary dict
virtual bool read(const dictionary &dict)
Read dictionary.
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
Abstract base-class for fluid and solid thermodynamic properties.
Definition: basicThermo.H:52
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
const word dictName() const
Return the local dictionary name (final part of scoped name)
Definition: dictionary.H:115
addToRunTimeSelectionTable(option, fixedTemperatureConstraint, dictionary)
virtual bool read(const dictionary &dict)
Read source dictionary.
const Type & value() const
Return const reference to value.
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:52
Macros for easy insertion into run-time selection tables.
static const NamedEnum< temperatureMode, 2 > temperatureModeNames_
String representation of temperatureMode enums.
virtual volScalarField & he()=0
Enthalpy/Internal energy [J/kg].
virtual volScalarField & p()
Pressure [Pa].
Definition: basicThermo.C:466
dynamicFvMesh & mesh
virtual void constrain(fvMatrix< scalar > &eqn, const label fieldi)
Constrain energy equation to fix the temperature.
A class for handling words, derived from string.
Definition: word.H:59
const Time & time() const
Return time.
Definition: IOobject.C:227
labelList fv(nPoints)
void setValues(const labelUList &cells, const UList< Type > &values)
Set solution in given cells to the specified values.
Definition: fvMatrix.C:474
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:71
Basic thermodynamics type based on the use of fitting functions for cp, h, s obtained from the templa...
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
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.
Cell-set options abtract base class. Provides a base set of controls, e.g.:
Definition: cellSetOption.H:72
const word & name() const
Return name.
Definition: IOobject.H:260
Namespace for OpenFOAM.