nonUniformTableThermophysicalFunction.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) 2020 OpenFOAM Foundation
9  Copyright (C) 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 
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
37 
39  (
40  thermophysicalFunction,
42  dictionary
43  );
44 }
45 
46 
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 
50 (
51  const word& name,
52  const dictionary& dict
53 )
54 :
55  name_(name),
56  values_(),
57  Trange_(),
58  deltaT_(GREAT),
59  jumpTable_()
60 {
61  dict.readEntry(name_, values_);
62 
63  if (values_.size() < 2)
64  {
66  << "Table" << nl
67  << " " << name_ << nl
68  << " has fewer than 2 entries." << nl
69  << exit(FatalIOError);
70  }
71 
72  Trange_.min() = values_.first().first();
73  Trange_.max() = values_.last().first();
74 
75  for (label i = 1; i < values_.size(); ++i)
76  {
77  #ifdef FULLDEBUG
78  // Check list is monotonically increasing...
79  if (values_[i].first() <= values_[i-1].first())
80  {
82  << "Table" << nl
83  << " " << name_ << nl
84  << " out-of-order value: " << values_[i].first()
85  << " at index " << i << nl
86  << exit(FatalError);
87  }
88  #endif
89 
90  deltaT_ = min(deltaT_, values_[i].first() - values_[i-1].first());
91  }
92 
93  deltaT_ *= 0.9;
94 
95  jumpTable_.resize(Trange_.mag()/deltaT_ + 1);
96 
97  label i = 0;
98  forAll(jumpTable_, j)
99  {
100  const scalar T = Trange_.min() + j*deltaT_;
101 
102  if (T > values_[i+1].first())
103  {
104  ++i;
105  }
106 
107  jumpTable_[j] = i;
108  }
109 }
110 
111 
113 (
114  const dictionary& dict
115 )
116 :
117  nonUniformTable("values", dict)
118 {}
119 
120 
121 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
122 
123 Foam::scalar Foam::nonUniformTable::f
124 (
125  scalar p,
126  scalar T
127 ) const
128 {
129  const label i = index(p, T);
130  const scalar Ti = values_[i].first();
131  const scalar lambda = (T - Ti)/(values_[i + 1].first() - Ti);
132 
133  return
134  values_[i].second()
135  + lambda*(values_[i + 1].second() - values_[i].second());
136 }
137 
138 
139 Foam::scalar Foam::nonUniformTable::dfdT
140 (
141  scalar p,
142  scalar T
143 ) const
144 {
145  const label i = index(p, T);
146 
147  return
148  (values_[i + 1].second() - values_[i].second())
149  /(values_[i + 1].first() - values_[i].first());
150 }
151 
152 
154 {
155  os.writeEntry("values", values_);
156 }
157 
158 
159 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::nonUniformTable::nonUniformTable
nonUniformTable(const word &name, const dictionary &dict)
Construct from entry name and dictionary.
Definition: nonUniformTableThermophysicalFunction.C:50
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::nonUniformTable::writeData
void writeData(Ostream &os) const
Write the function coefficients.
Definition: nonUniformTableThermophysicalFunction.C:153
Foam::nonUniformTable::f
scalar f(scalar p, scalar T) const
Evaluate the function and return the result.
Definition: nonUniformTableThermophysicalFunction.C:124
Foam::FatalIOError
IOerror FatalIOError
nonUniformTable
Non-uniform tabulated property function that linearly interpolates between the values.
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::nonUniformTable::dfdT
scalar dfdT(scalar p, scalar T) const
Evaluate the derivative of the function and return the result.
Definition: nonUniformTableThermophysicalFunction.C:140
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
lambda
dimensionedScalar lambda("lambda", dimTime/sqr(dimLength), laminarTransport)
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
T
const volScalarField & T
Definition: createFieldRefs.H:2
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
Foam::nl
constexpr char nl
Definition: Ostream.H:385
nonUniformTableThermophysicalFunction.H
Foam::Ostream::writeEntry
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:232
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:401
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::nonUniformTable
Definition: nonUniformTableThermophysicalFunction.H:76
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)