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-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 
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_.getOrDefault<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  const scalarField& T = thermo.T();
113 
114  scalar Tmin0 = min(T);
115  scalar Tmax0 = max(T);
116 
117  label nOverTmax = 0;
118  label nLowerTmin = 0;
119 
120  forAll(cells_, i)
121  {
122  const label celli = cells_[i];
123  if (hec[celli] < heMin[i])
124  {
125  nLowerTmin++;
126  }
127  else if (hec[celli] > heMax[i])
128  {
129  nOverTmax++;
130  }
131  hec[celli]= max(min(hec[celli], heMax[i]), heMin[i]);
132  }
133 
134  reduce(nOverTmax, sumOp<label>());
135  reduce(nLowerTmin, sumOp<label>());
136 
137  reduce(Tmin0, minOp<scalar>());
138  reduce(Tmax0, maxOp<scalar>());
139 
140  Info<< type() << " " << name_ << " Lower limited "
141  << nLowerTmin << " ("
142  << 100*scalar(nLowerTmin)/mesh_.globalData().nTotalCells()
143  << "%) of cells" << endl;
144 
145  Info<< type() << " " << name_ << " Upper limited "
146  << nOverTmax << " ("
147  << 100*scalar(nOverTmax)/mesh_.globalData().nTotalCells()
148  << "%) of cells" << endl;
149 
150  Info<< type() << " " << name_ << " Unlimited Tmax " << Tmax0 << nl
151  << "Unlimited Tmin " << Tmin0 << endl;
152 
153  // handle boundaries in the case of 'all'
154  if (selectionMode_ == smAll)
155  {
156  volScalarField::Boundary& bf = he.boundaryFieldRef();
157 
158  forAll(bf, patchi)
159  {
160  fvPatchScalarField& hep = bf[patchi];
161 
162  if (!hep.fixesValue())
163  {
164  const scalarField& pp = thermo.p().boundaryField()[patchi];
165 
166  scalarField Tminp(pp.size(), Tmin_);
167  scalarField Tmaxp(pp.size(), Tmax_);
168 
169  scalarField heMinp(thermo.he(pp, Tminp, patchi));
170  scalarField heMaxp(thermo.he(pp, Tmaxp, patchi));
171 
172  forAll(hep, facei)
173  {
174  hep[facei] =
175  max(min(hep[facei], heMaxp[facei]), heMinp[facei]);
176  }
177  }
178  }
179  }
180 
181  // We've changed internal values so give boundary conditions opportunity
182  // to correct.
183  he.correctBoundaryConditions();
184 }
185 
186 
187 // ************************************************************************* //
Foam::fvPatchField< scalar >
Foam::fv::limitTemperature::read
virtual bool read(const dictionary &dict)
Read dictionary.
Definition: limitTemperature.C:82
Foam::maxOp
Definition: ops.H:223
basicThermo.H
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
Foam::minOp
Definition: ops.H:224
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::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
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
Foam::sumOp
Definition: ops.H:213
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
limitTemperature.H
Foam::reduce
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Definition: PstreamReduceOps.H:51
Foam::Field< scalar >
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
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::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
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)
he
volScalarField & he
Definition: YEEqn.H:52
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::fv::limitTemperature::correct
virtual void correct(volScalarField &he)
Correct the energy field.
Definition: limitTemperature.C:96
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::fv::limitTemperature::Tmax_
scalar Tmax_
Maximum temperature limit [K].
Definition: limitTemperature.H:83
Foam::fv::defineTypeNameAndDebug
defineTypeNameAndDebug(atmAmbientTurbSource, 0)
Foam::IOobject::groupName
static word groupName(StringType base, const word &group)
Create dot-delimited name.group string.
Foam::fv::addToRunTimeSelectionTable
addToRunTimeSelectionTable(option, atmAmbientTurbSource, dictionary)
Foam::GeometricField< scalar, fvPatchField, volMesh >