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-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 
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);
41  addToRunTimeSelectionTable(option, limitTemperature, dictionary);
42 }
43 }
44 
45 
46 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
47 
49 (
50  const word& name,
51  const word& modelType,
52  const dictionary& dict,
53  const fvMesh& mesh
54 )
55 :
56  fv::cellSetOption(name, modelType, dict, mesh),
57  Tmin_(coeffs_.get<scalar>("min")),
58  Tmax_(coeffs_.get<scalar>("max")),
59  phase_(coeffs_.getOrDefault<word>("phase", word::null))
60 {
61  // Set the field name to that of the energy
62  // field from which the temperature is obtained
63  const auto& thermo =
64  mesh_.lookupObject<basicThermo>
65  (
66  IOobject::groupName(basicThermo::dictName, phase_)
67  );
68 
69  fieldNames_.resize(1, thermo.he().name());
70 
71  fv::option::resetApplied();
72 }
73 
74 
75 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
76 
78 {
80  {
81  coeffs_.readEntry("min", Tmin_);
82  coeffs_.readEntry("max", Tmax_);
83 
84  if (Tmax_ < Tmin_)
85  {
87  << "Minimum temperature limit cannot exceed maximum limit" << nl
88  << "min = " << Tmin_ << nl
89  << "max = " << Tmax_
90  << exit(FatalIOError);
91  }
92 
93  if (Tmin_ < 0)
94  {
96  << "Minimum temperature limit cannot be negative" << nl
97  << "min = " << Tmin_
98  << exit(FatalIOError);
99  }
100 
101  return true;
102  }
103 
104  return false;
105 }
106 
107 
109 {
110  const auto& thermo =
111  mesh_.lookupObject<basicThermo>
112  (
114  );
115 
116  scalarField Tmin(cells_.size(), Tmin_);
117  scalarField Tmax(cells_.size(), Tmax_);
118 
119  scalarField heMin(thermo.he(thermo.p(), Tmin, cells_));
120  scalarField heMax(thermo.he(thermo.p(), Tmax, cells_));
121 
122  scalarField& hec = he.primitiveFieldRef();
123 
124  const scalarField& T = thermo.T();
125 
126  scalar Tmin0 = min(T);
127  scalar Tmax0 = max(T);
128 
129  label nOverTmax = 0;
130  label nLowerTmin = 0;
131 
132  forAll(cells_, i)
133  {
134  const label celli = cells_[i];
135  if (hec[celli] < heMin[i])
136  {
137  nLowerTmin++;
138  }
139  else if (hec[celli] > heMax[i])
140  {
141  nOverTmax++;
142  }
143  hec[celli]= max(min(hec[celli], heMax[i]), heMin[i]);
144  }
145 
146  reduce(nOverTmax, sumOp<label>());
147  reduce(nLowerTmin, sumOp<label>());
148 
149  reduce(Tmin0, minOp<scalar>());
150  reduce(Tmax0, maxOp<scalar>());
151 
152  Info<< type() << " " << name_ << " Lower limited "
153  << nLowerTmin << " ("
154  << 100*scalar(nLowerTmin)/mesh_.globalData().nTotalCells()
155  << "%) of cells" << endl;
156 
157  Info<< type() << " " << name_ << " Upper limited "
158  << nOverTmax << " ("
159  << 100*scalar(nOverTmax)/mesh_.globalData().nTotalCells()
160  << "%) of cells" << endl;
161 
162  Info<< type() << " " << name_ << " Unlimited Tmax " << Tmax0 << nl
163  << "Unlimited Tmin " << Tmin0 << endl;
164 
165  // Handle boundaries in the case of 'all'
167  {
168  volScalarField::Boundary& bf = he.boundaryFieldRef();
169 
170  forAll(bf, patchi)
171  {
172  fvPatchScalarField& hep = bf[patchi];
173 
174  if (!hep.fixesValue())
175  {
176  const scalarField& pp = thermo.p().boundaryField()[patchi];
177 
178  scalarField Tminp(pp.size(), Tmin_);
179  scalarField Tmaxp(pp.size(), Tmax_);
180 
181  scalarField heMinp(thermo.he(pp, Tminp, patchi));
182  scalarField heMaxp(thermo.he(pp, Tmaxp, patchi));
183 
184  forAll(hep, facei)
185  {
186  hep[facei] =
187  max(min(hep[facei], heMaxp[facei]), heMinp[facei]);
188  }
189  }
190  }
191  }
192 
193  // We've changed internal values so give
194  // boundary conditions opportunity to correct
195  he.correctBoundaryConditions();
196 }
197 
198 
199 // ************************************************************************* //
Foam::fvPatchField< scalar >
Foam::fv::limitTemperature::read
virtual bool read(const dictionary &dict)
Read dictionary.
Definition: limitTemperature.C:77
Foam::maxOp
Definition: ops.H:223
basicThermo.H
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
Foam::minOp
Definition: ops.H:224
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::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::fvPatchField::fixesValue
virtual bool fixesValue() const
Return true if this patch field fixes a value.
Definition: fvPatchField.H:332
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 (stdout output on master, null elsewhere)
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::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
Foam::fv::cellSetOption::useSubMesh
bool useSubMesh() const noexcept
True if sub-selection should be used.
Definition: cellSetOptionI.H:64
Foam::dictionary::readEntry
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, bool mandatory=true) const
Definition: dictionaryTemplates.C:302
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
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
Foam::fv::limitTemperature::Tmin_
scalar Tmin_
Minimum temperature limit [K].
Definition: limitTemperature.H:143
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
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
fv
labelList fv(nPoints)
he
volScalarField & he
Definition: YEEqn.H:52
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::fv::limitTemperature::correct
virtual void correct(volScalarField &he)
Correct the energy field.
Definition: limitTemperature.C:108
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:146
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)
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
Foam::fv::limitTemperature::limitTemperature
limitTemperature(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from components.
Definition: limitTemperature.C:49
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 >
Foam::dictionary::dictName
word dictName() const
The local dictionary name (final part of scoped name)
Definition: dictionaryI.H:60