limitTemperature.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-2017 OpenFOAM Foundation
9  Copyright (C) 2018 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 
29 #include "limitTemperature.H"
30 #include "fvMesh.H"
31 #include "basicThermo.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 namespace fv
39 {
40  defineTypeNameAndDebug(limitTemperature, 0);
42  (
43  option,
44  limitTemperature,
45  dictionary
46  );
47 }
48 }
49 
50 
51 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
52 
53 Foam::fv::limitTemperature::limitTemperature
54 (
55  const word& name,
56  const word& modelType,
57  const dictionary& dict,
58  const fvMesh& mesh
59 )
60 :
61  cellSetOption(name, modelType, dict, mesh),
62  Tmin_(coeffs_.get<scalar>("min")),
63  Tmax_(coeffs_.get<scalar>("max")),
64  phase_(coeffs_.lookupOrDefault<word>("phase", word::null))
65 {
66  // Set the field name to that of the energy field from which the temperature
67  // is obtained
68  const basicThermo& thermo =
69  mesh_.lookupObject<basicThermo>
70  (
71  IOobject::groupName(basicThermo::dictName, phase_)
72  );
73 
74  fieldNames_.setSize(1, thermo.he().name());
75 
76  applied_.setSize(1, false);
77 }
78 
79 
80 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
81 
83 {
85  {
86  coeffs_.readEntry("min", Tmin_);
87  coeffs_.readEntry("max", Tmax_);
88 
89  return true;
90  }
91 
92  return false;
93 }
94 
95 
97 {
98  const basicThermo& thermo =
99  mesh_.lookupObject<basicThermo>
100  (
102  );
103 
104  scalarField Tmin(cells_.size(), Tmin_);
105  scalarField Tmax(cells_.size(), Tmax_);
106 
107  scalarField heMin(thermo.he(thermo.p(), Tmin, cells_));
108  scalarField heMax(thermo.he(thermo.p(), Tmax, cells_));
109 
110  scalarField& hec = he.primitiveFieldRef();
111 
112  forAll(cells_, i)
113  {
114  const label celli = cells_[i];
115  hec[celli]= max(min(hec[celli], heMax[i]), heMin[i]);
116  }
117 
118  // handle boundaries in the case of 'all'
119  if (selectionMode_ == smAll)
120  {
121  volScalarField::Boundary& bf = he.boundaryFieldRef();
122 
123  forAll(bf, patchi)
124  {
125  fvPatchScalarField& hep = bf[patchi];
126 
127  if (!hep.fixesValue())
128  {
129  const scalarField& pp = thermo.p().boundaryField()[patchi];
130 
131  scalarField Tminp(pp.size(), Tmin_);
132  scalarField Tmaxp(pp.size(), Tmax_);
133 
134  scalarField heMinp(thermo.he(pp, Tminp, patchi));
135  scalarField heMaxp(thermo.he(pp, Tmaxp, patchi));
136 
137  forAll(hep, facei)
138  {
139  hep[facei] =
140  max(min(hep[facei], heMaxp[facei]), heMinp[facei]);
141  }
142  }
143  }
144  }
145 
146  // We've changed internal values so give boundary conditions opportunity
147  // to correct.
148  he.correctBoundaryConditions();
149 }
150 
151 
152 // ************************************************************************* //
Foam::fvPatchField< scalar >
Foam::fv::limitTemperature::read
virtual bool read(const dictionary &dict)
Read dictionary.
Definition: limitTemperature.C:82
basicThermo.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::fv::cellSetOption
Cell-set options abtract base class. Provides a base set of controls, e.g.:
Definition: cellSetOption.H:72
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::fvPatchField::fixesValue
virtual bool fixesValue() const
Return true if this patch field fixes a value.
Definition: fvPatchField.H:318
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
limitTemperature.H
Foam::label
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:62
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::dictionary::readEntry
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, bool mandatory=true) const
Definition: dictionaryTemplates.C:314
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
Foam::dictionary::dictName
word dictName() const
The local dictionary name (final part of scoped name)
Definition: dictionary.H:458
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
Foam::fv::limitTemperature::Tmin_
scalar Tmin_
Minimum temperature limit [K].
Definition: limitTemperature.H:80
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
fv
labelList fv(nPoints)
Foam::fv::defineTypeNameAndDebug
defineTypeNameAndDebug(option, 0)
Foam::fv::addToRunTimeSelectionTable
addToRunTimeSelectionTable(option, fixedTemperatureConstraint, dictionary)
he
volScalarField & he
Definition: YEEqn.H:52
Foam::fv::limitTemperature::correct
virtual void correct(volScalarField &he)
Correct the energy field.
Definition: limitTemperature.C:96
Foam::IOobject::groupName
static word groupName(StringType name, const word &group)
Create dot-delimited name.group.
Foam::fv::limitTemperature::Tmax_
scalar Tmax_
Maximum temperature limit [K].
Definition: limitTemperature.H:83
Foam::GeometricField< scalar, fvPatchField, volMesh >