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-------------------------------------------------------------------------------
11License
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
37namespace Foam
38{
39 namespace fv
40 {
43 (
44 option,
47 );
48 }
49}
50
51const 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
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
148{
150 {
151 if (coeffs_.found(Tuniform_->name()))
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// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: Enum.H:61
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: Function1.H:96
const Time & time() const
Return Time associated with the objectRegistry.
Definition: IOobject.C:506
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
virtual bool read()
Re-read model coefficients if they have changed.
Abstract base-class for fluid and solid thermodynamic properties.
Definition: basicThermo.H:66
static const word dictName
Definition: basicThermo.H:256
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
const Type & value() const
Return const reference to value.
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvMatrix.H:121
void setValues(const labelUList &cellLabels, const Type &value)
Definition: fvMatrix.C:969
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
Intermediate abstract class for handling cell-set options for the derived fvOptions.
Constrain temperature equation (i.e. T) with a given set of fixed values within a specified region.
autoPtr< Function1< scalar > > Tuniform_
Uniform temperature [K].
virtual void constrain(fvMatrix< scalar > &eqn, const label fieldi)
Constrain energy equation to fix the temperature.
static const Enum< temperatureMode > temperatureModeNames_
String representation of temperatureMode enums.
Base abstract class for handling finite volume options (i.e. fvOption).
Definition: fvOption.H:127
const fvMesh & mesh_
Reference to the mesh database.
Definition: fvOption.H:139
wordList fieldNames_
Field names to apply source to - populated by derived models.
Definition: fvOption.H:148
dictionary coeffs_
Dictionary containing source coefficients.
Definition: fvOption.H:145
void resetApplied()
Resize/reset applied flag list for all fieldNames_ entries.
Definition: fvOption.C:48
const Type & lookupObject(const word &name, const bool recursive=false) const
Basic thermodynamics type based on the use of fitting functions for cp, h, s obtained from the templa...
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
const volScalarField & T
dynamicFvMesh & mesh
A special matrix type and solver, designed for finite volume solutions of scalar equations.
Namespace for OpenFOAM.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
labelList fv(nPoints)
dictionary dict