NonUniformTable1.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2020-2021 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::Function1s::NonUniformTable
26 
27 Description
28  Non-uniform tabulated property function that linearly interpolates between
29  the values.
30 
31  To speed-up the search of the non-uniform table a uniform jump-table is
32  created on construction which is used for fast indirect addressing into
33  the table.
34 
35 Usage
36  \table
37  Property | Description
38  values | List of value pairs
39  \endtable
40 
41  Example for the density of water between 280 and 350K
42  \verbatim
43  rho
44  {
45  type nonUniformTable;
46 
47  values
48  (
49  (280 999.87)
50  (300 995.1)
51  (350 973.7)
52  );
53  }
54  \endverbatim
55 
56 \*---------------------------------------------------------------------------*/
57 
58 #ifndef NonUniformTable1_H
59 #define NonUniformTable1_H
60 
61 #include "Function1.H"
62 #include "Tuple2.H"
63 #include "TableReader.H"
64 
65 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
66 
67 namespace Foam
68 {
69 namespace Function1s
70 {
71 
72 /*---------------------------------------------------------------------------*\
73  Class NonUniformTable Declaration
74 \*---------------------------------------------------------------------------*/
75 
76 template<class Type>
77 class NonUniformTable
78 :
79  public FieldFunction1<Type, NonUniformTable<Type>>
80 {
81  // Private member data
82 
83  //- Lowest value in the NonUniformTable
84  scalar low_;
85 
86  //- Highest value in the NonUniformTable
87  scalar high_;
88 
89  //- Table values
91 
92  //- Increment derived from low_, high_ and values_.size()
93  scalar delta_;
94 
95  List<label> jumpTable_;
96 
97  //- Table reader
99 
100 
101 protected:
102 
103  //- Return the lower index of the interval in the table
104  // corresponding to the given value
105  inline label index(scalar x) const;
106 
107 
108 public:
109 
110  //- Runtime type information
111  TypeName("nonUniformTable");
112 
113 
114  // Constructors
115 
116  //- Construct from name and dictionary
117  NonUniformTable(const word& name, const dictionary& dict);
118 
119  //- Copy constructor
121 
122 
123  // Member Functions
124 
125  //- Return the non-uniform table of values
126  const List<Tuple2<scalar, Type>>& values() const
127  {
128  return values_;
129  }
130 
131  //- Evaluate the function and return the result
132  virtual Type value(scalar x) const;
133 
134  //- Integrate between two scalar values
135  virtual Type integral(const scalar x1, const scalar x2) const;
136 
137  //- Evaluate the derivative of the function and return the result
138  Type dfdT(scalar T) const;
139 
140  //- Write the function coefficients
141  void write(Ostream& os) const;
142 
143 
144  // Member Operators
145 
146  //- Assignment
147  void operator=(const NonUniformTable<Type>&);
148 };
149 
150 
151 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
152 
153 } // End namespace Function1s
154 } // End namespace Foam
155 
156 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
157 
158 #include "NonUniformTable1I.H"
159 
160 #ifdef NoRepository
161  #include "NonUniformTable1.C"
162 #endif
163 
164 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
165 
166 #endif
167 
168 // ************************************************************************* //
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:59
const word const dictionary & dict
Definition: Function1.H:84
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
const word & name() const
Return the name of the entry.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
virtual Type integral(const scalar x1, const scalar x2) const
Integrate between two scalar values.
virtual Type value(scalar x) const
Evaluate the function and return the result.
label index(scalar x) const
Return the lower index of the interval in the table.
Type dfdT(scalar T) const
Evaluate the derivative of the function and return the result.
A class for handling words, derived from string.
Definition: word.H:59
void write(Ostream &os) const
Write the function coefficients.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Non-uniform tabulated property function that linearly interpolates between the values.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
const List< Tuple2< scalar, Type > > & values() const
Return the non-uniform table of values.
TypeName("nonUniformTable")
Runtime type information.
NonUniformTable(const word &name, const dictionary &dict)
Construct from name and dictionary.
scalar nut
Namespace for OpenFOAM.
void operator=(const NonUniformTable< Type > &)
Assignment.