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-2021 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 
65 (
66  const word& name,
67  const word& modelType,
68  const dictionary& dict,
69  const fvMesh& mesh
70 )
71 :
72  fv::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_, &mesh_)
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
100  // field from which the temperature is obtained
101 
102  const auto& thermo = mesh_.lookupObject<basicThermo>(basicThermo::dictName);
103 
104  fieldNames_.resize(1, thermo.he().name());
105 
106  fv::option::resetApplied();
107 }
108 
109 
110 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
111 
113 (
114  fvMatrix<scalar>& eqn,
115  const label
116 )
117 {
118  const auto& thermo = 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 auto& T = mesh().lookupObject<volScalarField>(TName_);
133 
134  scalarField Tlkp(T, cells_);
135  eqn.setValues(cells_, thermo.he(thermo.p(), Tlkp, cells_));
136 
137  break;
138  }
139  default:
140  {
141  // Error handling already done by Enum
142  }
143  }
144 }
145 
146 
148 {
150  {
151  if (coeffs_.found(Tuniform_->name()))
152  {
153  Tuniform_.reset
154  (
156  );
157  }
158 
160 
161  return true;
162  }
163 
164  return false;
165 }
166 
167 
168 // ************************************************************************* //
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:163
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fv::cellSetOption
Intermediate abstract class for handling cell-set options for the derived fvOptions.
Definition: cellSetOption.H:163
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: dictionaryI.H:87
dictName
const word dictName("faMeshDefinition")
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 associated with the objectRegistry.
Definition: IOobject.C:493
Foam::Function1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: propellerInfo.H:291
Foam::fv::option::mesh_
const fvMesh & mesh_
Reference to the mesh database.
Definition: fvOption.H:139
fvMatrices.H
A special matrix type and solver, designed for finite volume solutions of scalar equations.
Foam::Field< scalar >
Foam::fv::option::coeffs_
dictionary coeffs_
Dictionary containing source coefficients.
Definition: fvOption.H:145
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:147
Foam::fv::fixedTemperatureConstraint::fixedTemperatureConstraint
fixedTemperatureConstraint(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from components.
Definition: fixedTemperatureConstraint.C:65
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:123
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:85
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
T
const volScalarField & T
Definition: createFieldRefs.H:2
Foam::fvMatrix::setValues
void setValues(const labelUList &cellLabels, const Type &value)
Definition: fvMatrix.C:1059
fv
labelList fv(nPoints)
Foam::fv::fixedTemperatureConstraint::TName_
word TName_
Temperature field name.
Definition: fixedTemperatureConstraint.H:177
Foam::fv::fixedTemperatureConstraint::Tuniform_
autoPtr< Function1< scalar > > Tuniform_
Uniform temperature [K].
Definition: fixedTemperatureConstraint.H:174
Foam::fvMatrix
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvPatchField.H:68
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
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:113
Foam::fv::fixedTemperatureConstraint::temperatureMode
temperatureMode
Temperature mode.
Definition: fixedTemperatureConstraint.H:156
Foam::dictionary::readIfPresent
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:405