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 
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 
147 bool Foam::fv::fixedTemperatureConstraint::read(const dictionary& dict)
148 {
150  {
151  if (Tuniform_ && coeffs_.found(Tuniform_->name(), keyType::LITERAL))
152  {
153  Tuniform_.reset
154  (
155  Function1<scalar>::New(Tuniform_->name(), dict, &mesh_)
156  );
157  }
158 
159  coeffs_.readIfPresent("T", TName_);
160 
161  return true;
162  }
163 
164  return false;
165 }
166 
167 
168 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
word dictName() const
The local dictionary name (final part of scoped name)
Definition: dictionaryI.H:53
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
const Type & value() const noexcept
Return const reference to value.
dictionary dict
virtual bool read(const dictionary &dict)
Read dictionary.
const Type & lookupObject(const word &name, const bool recursive=false) const
Lookup and return const reference to the object of the given Type. Fatal if not found or the wrong ty...
Abstract base-class for fluid and solid thermodynamic properties.
Definition: basicThermo.H:59
wordList fieldNames_
Field names to apply source to - populated by derived models.
Definition: fvOption.H:157
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:160
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
defineTypeNameAndDebug(atmAmbientTurbSource, 0)
const fvMesh & mesh_
Reference to the mesh database.
Definition: fvOption.H:142
autoPtr< Function1< scalar > > Tuniform_
Uniform temperature [K].
fixedTemperatureConstraint(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from components.
virtual bool read(const dictionary &dict)
Read source dictionary.
Macros for easy insertion into run-time selection tables.
psiReactionThermo & thermo
Definition: createFields.H:28
dynamicFvMesh & mesh
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
static const Enum< temperatureMode > temperatureModeNames_
String representation of temperatureMode enums.
virtual void constrain(fvMatrix< scalar > &eqn, const label fieldi)
Constrain energy equation to fix the temperature.
A class for handling words, derived from Foam::string.
Definition: word.H:63
labelList fv(nPoints)
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:64
String literal.
Definition: keyType.H:82
const Time & time() const noexcept
Return Time associated with the objectRegistry.
Definition: IOobject.C:456
Basic thermodynamics type based on the use of fitting functions for cp, h, s obtained from the templa...
addToRunTimeSelectionTable(option, atmAmbientTurbSource, dictionary)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: error.H:64
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
void resetApplied()
Resize/reset applied flag list for all fieldNames_ entries.
Definition: fvOption.C:41
A special matrix type and solver, designed for finite volume solutions of scalar equations.
void setValues(const labelUList &cellLabels, const Type &value)
Set solution in given cells to the specified value and eliminate the corresponding equations from the...
Definition: fvMatrix.C:978
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T, or return the given default value. FatalIOError if it is found and the number of...
dictionary coeffs_
Dictionary containing source coefficients.
Definition: fvOption.H:152
Namespace for OpenFOAM.