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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2012-2016 OpenFOAM Foundation
9  Copyright (C) 2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
30 #include "fvMesh.H"
31 #include "fvMatrices.H"
32 #include "basicThermo.H"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39  namespace fv
40  {
41  defineTypeNameAndDebug(fixedTemperatureConstraint, 0);
43  (
44  option,
45  fixedTemperatureConstraint,
46  dictionary
47  );
48  }
49 }
50 
51 const Foam::Enum
52 <
54 >
56 ({
57  { temperatureMode::tmUniform, "uniform" },
58  { temperatureMode::tmLookup, "lookup" },
59 });
60 
61 
62 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
63 
64 Foam::fv::fixedTemperatureConstraint::fixedTemperatureConstraint
65 (
66  const word& name,
67  const word& modelType,
68  const dictionary& dict,
69  const fvMesh& mesh
70 )
71 :
72  cellSetOption(name, modelType, dict, mesh),
73  mode_(temperatureModeNames_.get("mode", coeffs_)),
74  Tuniform_(nullptr),
75  TName_("T")
76 {
77  switch (mode_)
78  {
79  case tmUniform:
80  {
81  Tuniform_.reset
82  (
83  Function1<scalar>::New("temperature", coeffs_).ptr()
84  );
85  break;
86  }
87  case tmLookup:
88  {
89  TName_ = coeffs_.getOrDefault<word>("T", "T");
90  break;
91  }
92  default:
93  {
94  // Error handling already done by Enum
95  }
96  }
97 
98 
99  // Set the field name to that of the energy field from which the temperature
100  // is obtained
101 
102  const basicThermo& thermo =
103  mesh_.lookupObject<basicThermo>(basicThermo::dictName);
104 
105  fieldNames_.setSize(1, thermo.he().name());
106 
107  applied_.setSize(1, false);
108 }
109 
110 
111 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
112 
114 (
115  fvMatrix<scalar>& eqn,
116  const label
117 )
118 {
119  const basicThermo& thermo =
120  mesh_.lookupObject<basicThermo>(basicThermo::dictName);
121 
122  switch (mode_)
123  {
124  case tmUniform:
125  {
126  const scalar t = mesh_.time().value();
127  scalarField Tuni(cells_.size(), Tuniform_->value(t));
128  eqn.setValues(cells_, thermo.he(thermo.p(), Tuni, cells_));
129 
130  break;
131  }
132  case tmLookup:
133  {
134  const volScalarField& T =
135  mesh().lookupObject<volScalarField>(TName_);
136 
137  scalarField Tlkp(T, cells_);
138  eqn.setValues(cells_, thermo.he(thermo.p(), Tlkp, cells_));
139 
140  break;
141  }
142  default:
143  {
144  // Error handling already done by Enum
145  }
146  }
147 }
148 
149 
151 {
153  {
154  if (coeffs_.found(Tuniform_->name()))
155  {
156  Tuniform_.reset
157  (
158  Function1<scalar>::New(Tuniform_->name(), dict).ptr()
159  );
160  }
161 
163 
164  return true;
165  }
166 
167  return false;
168 }
169 
170 
171 // ************************************************************************* //
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:57
basicThermo.H
Foam::fv::fixedTemperatureConstraint::temperatureModeNames_
static const Enum< temperatureMode > temperatureModeNames_
String representation of temperatureMode enums.
Definition: fixedTemperatureConstraint.H:93
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::fv::cellSetOption
Cell-set options abstract base class. Provides a base set of controls, e.g.:
Definition: cellSetOption.H:72
fixedTemperatureConstraint.H
Foam::dictionary::found
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for an entry (const access) with the given keyword.
Definition: dictionary.C:364
dictName
const word dictName("blockMeshDict")
thermo
Basic thermodynamics type based on the use of fitting functions for cp, h, s obtained from the templa...
Foam::basicThermo
Abstract base-class for fluid and solid thermodynamic properties.
Definition: basicThermo.H:63
Foam::dimensioned::value
const Type & value() const
Return const reference to value.
Definition: dimensionedType.C:434
Foam::IOobject::time
const Time & time() const
Return time.
Definition: IOobject.C:449
Foam::Function1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: Function1.H:86
fvMatrices.H
A special matrix type and solver, designed for finite volume solutions of scalar equations.
Foam::fvMatrix::setValues
void setValues(const labelUList &cells, const UList< Type > &values)
Set solution in given cells to the specified values.
Definition: fvMatrix.C:473
Foam::Field< scalar >
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::fv::option::coeffs_
dictionary coeffs_
Dictionary containing source coefficients.
Definition: fvOption.H:88
Foam::fv::cellSetOption::read
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: cellSetOption.C:255
Foam::fv::fixedTemperatureConstraint::read
virtual bool read(const dictionary &dict)
Read dictionary.
Definition: fixedTemperatureConstraint.C:150
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:84
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
T
const volScalarField & T
Definition: createFieldRefs.H:2
fv
labelList fv(nPoints)
Foam::fv::fixedTemperatureConstraint::TName_
word TName_
Temperature field name.
Definition: fixedTemperatureConstraint.H:107
Foam::fv::fixedTemperatureConstraint::Tuniform_
autoPtr< Function1< scalar > > Tuniform_
Uniform temperature [K].
Definition: fixedTemperatureConstraint.H:104
Foam::fvMatrix
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvPatchField.H:76
Foam::fv::defineTypeNameAndDebug
defineTypeNameAndDebug(atmAmbientTurbSource, 0)
Foam::fv::addToRunTimeSelectionTable
addToRunTimeSelectionTable(option, atmAmbientTurbSource, dictionary)
Foam::GeometricField< scalar, fvPatchField, volMesh >
Foam::fv::fixedTemperatureConstraint::constrain
virtual void constrain(fvMatrix< scalar > &eqn, const label fieldi)
Constrain energy equation to fix the temperature.
Definition: fixedTemperatureConstraint.C:114
Foam::fv::fixedTemperatureConstraint::temperatureMode
temperatureMode
Temperature mode.
Definition: fixedTemperatureConstraint.H:85
Foam::dictionary::readIfPresent
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:417