Function1.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) 2011-2026 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::Function1
26 
27 Description
28  Run-time selectable general function of one variable
29 
30  with many options provided from simple constant values to complex
31  functions, interpolated tabulated data etc. etc.
32 
33 SourceFiles
34  Function1.C
35  Function1New.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef Function1_H
40 #define Function1_H
41 
42 #include "Function1UnitSets.H"
43 #include "Field.H"
44 #include "runTimeSelectionTables.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 // Forward declaration of friend functions and operators
52 template<class Type> class Function1;
53 template<class Type> Ostream& operator<<(Ostream&, const Function1<Type>&);
54 
55 /*---------------------------------------------------------------------------*\
56  Class Function1 Declaration
57 \*---------------------------------------------------------------------------*/
58 
59 template<class Type>
60 class Function1
61 :
62  public tmp<Function1<Type>>::refCount
63 {
64 
65 protected:
66 
67  // Protected Data
68 
69  //- Name of entry
70  const word name_;
71 
72 
73 public:
74 
75  typedef Type returnType;
76 
77 
78  //- Runtime type information
79  TypeName("Function1");
80 
81 
82  // Declare runtime constructor selection tables
83 
85  (
86  autoPtr,
87  Function1,
88  dictionary,
89  (
90  const word& name,
91  const Function1s::unitSets& units,
92  const dictionary& dict
93  ),
94  (name, units, dict)
95  );
96 
98  (
99  autoPtr,
100  Function1,
101  Istream,
102  (
103  const word& name,
104  const Function1s::unitSets& units,
105  Istream& is
106  ),
107  (name, units, is)
108  );
109 
110 
111  // Constructors
112 
113  //- Construct from name
114  Function1(const word& name);
115 
116  //- Copy constructor
117  Function1(const Function1<Type>& f1);
118 
119  //- Construct and return a clone
120  virtual tmp<Function1<Type>> clone() const = 0;
121 
122 
123  // Selectors
124 
125  //- Select from dictionary
127  (
128  const word& name,
129  const Function1s::unitSets& units,
130  const dictionary& dict
131  );
132 
133  //- Select from dictionary
135  (
136  const word& name,
137  const unitSet& xUnits,
138  const unitSet& valueUnits,
139  const dictionary& dict
140  );
141 
142  //- Select from an entry
144  (
145  const Function1s::unitSets& units,
146  const entry& e
147  );
148 
149  //- Select from an entry
151  (
152  const unitSet& xUnits,
153  const unitSet& valueUnits,
154  const entry& e
155  );
156 
157  //- Select from Istream
159  (
160  const word& name,
161  const Function1s::unitSets& units,
162  const word& Function1Type,
163  Istream& is
164  );
165 
166  //- Select from Istream
168  (
169  const word& name,
170  const unitSet& xUnits,
171  const unitSet& valueUnits,
172  const word& Function1Type,
173  Istream& is
174  );
175 
176 
177  //- Destructor
178  virtual ~Function1();
179 
180 
181  // Member Functions
182 
183  //- Return the name of the entry
184  const word& name() const;
185 
186  //- Return value as a function of scalar x
187  virtual Type value(const scalar x) const = 0;
188 
189  //- Return value as a function of a scalar field x
190  virtual tmp<Field<Type>> value(const scalarField& x) const = 0;
191 
192  //- Integrate between two scalars
193  virtual Type integral(const scalar x1, const scalar x2) const = 0;
194 
195  //- Integrate between two scalar fields
196  virtual tmp<Field<Type>> integral
197  (
198  const scalarField& x1,
199  const scalarField& x2
200  ) const = 0;
201 
202  //- Is this function guaranteed to be constant?
203  virtual bool constant() const;
204 
205  //- Write data to dictionary stream
206  virtual void write
207  (
208  Ostream& os,
209  const Function1s::unitSets&
210  ) const = 0;
211 
212 
213  // Member Operators
214 
215  //- Assignment
216  void operator=(const Function1<Type>&);
217 
218 
219  // IOstream Operators
220 
221  //- Ostream Operator
222  friend Ostream& operator<< <Type>
223  (
224  Ostream& os,
225  const Function1<Type>& func
226  );
227 };
228 
229 
230 template<class Type>
231 void writeEntry(Ostream& os, const Function1<Type>& f1);
232 
233 template<class Type>
234 void writeEntry
235 (
236  Ostream& os,
237  const Function1s::unitSets& units,
238  const Function1<Type>& f1
239 );
240 
241 template<class Type>
242 void writeEntry
243 (
244  Ostream& os,
245  const unitSet& xUnits,
246  const unitSet& valueUnits,
247  const Function1<Type>& f1
248 );
249 
250 
251 /*---------------------------------------------------------------------------*\
252  Class FieldFunction1 Declaration
253 \*---------------------------------------------------------------------------*/
254 
255 template<class Type, class Function1Type>
256 class FieldFunction1
257 :
258  public Function1<Type>
259 {
260 
261 public:
262 
263  // Constructors
264 
265  //- Construct from name
266  FieldFunction1(const word& name);
267 
268  //- Construct and return a clone
269  virtual tmp<Function1<Type>> clone() const;
270 
271 
272  //- Destructor
273  virtual ~FieldFunction1();
274 
275 
276  // Member Functions
277 
278  //- Return value as a function of one scalars
279  virtual Type value(const scalar x) const = 0;
280 
281  //- Return value as a function of one scalar field
282  virtual tmp<Field<Type>> value(const scalarField& x) const;
283 
284  //- Integrate between two scalar values
285  virtual Type integral(const scalar x1, const scalar x2) const = 0;
286 
287  //- Integrate between two scalar fields
288  virtual tmp<Field<Type>> integral
289  (
290  const scalarField& x1,
291  const scalarField& x2
292  ) const;
293 };
294 
295 
296 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
297 
298 } // End namespace Foam
299 
300 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
301 
302 #define defineFunction1(Type) \
303  \
304  defineNamedTemplateTypeNameAndDebug(Function1<Type>, 0); \
305  defineTemplateRunTimeSelectionTable(Function1<Type>, dictionary); \
306  defineTemplateRunTimeSelectionTable(Function1<Type>, Istream);
307 
308 
309 #define addFunction1(SS, Type) \
310  \
311  defineNamedTemplateTypeNameAndDebug(SS<Type>, 0); \
312  typedef Function1<Type> Type##Function1; \
313  typedef SS<Type> Type##SS##Function1; \
314  addToRunTimeSelectionTable \
315  ( \
316  Type##Function1, \
317  Type##SS##Function1, \
318  dictionary \
319  )
320 
321 
322 #define addStreamConstructableFunction1(SS, Type) \
323  \
324  addFunction1(SS, Type); \
325  addToRunTimeSelectionTable \
326  ( \
327  Type##Function1, \
328  Type##SS##Function1, \
329  Istream \
330  )
331 
332 
333 #define addNamedFunction1(SS, Type, Name) \
334  \
335  typedef Function1<Type> Type##Function1; \
336  typedef SS<Type> Type##SS##Function1; \
337  addNamedToRunTimeSelectionTable \
338  ( \
339  Type##Function1, \
340  Type##SS##Function1, \
341  dictionary, \
342  Name \
343  )
344 
345 
346 #define addScalarFunction1(SS) \
347  \
348  defineTypeNameAndDebug(SS, 0); \
349  typedef Function1<scalar> scalarFunction1; \
350  addToRunTimeSelectionTable(scalarFunction1, SS, dictionary)
351 
352 
353 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
354 
355 #ifdef NoRepository
356  #include "Function1.C"
357  #include "Constant.H"
358 #endif
359 
360 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
361 
362 #endif
363 
364 // ************************************************************************* //
virtual Type integral(const scalar x1, const scalar x2) const =0
Integrate between two scalar values.
FieldFunction1(const word &name)
Construct from name.
Definition: Function1.C:46
virtual Type value(const scalar x) const =0
Return value as a function of one scalars.
virtual tmp< Function1< Type > > clone() const
Construct and return a clone.
Definition: Function1.C:54
virtual ~FieldFunction1()
Destructor.
Definition: Function1.C:71
Run-time selectable general function of one variable.
Definition: Function1.H:62
virtual Type integral(const scalar x1, const scalar x2) const =0
Integrate between two scalars.
TypeName("Function1")
Runtime type information.
static autoPtr< Function1< Type > > New(const word &name, const Function1s::unitSets &units, const dictionary &dict)
Select from dictionary.
Definition: Function1New.C:32
virtual ~Function1()
Destructor.
Definition: Function1.C:66
virtual tmp< Function1< Type > > clone() const =0
Construct and return a clone.
declareRunTimeSelectionTable(autoPtr, Function1, dictionary,(const word &name, const Function1s::unitSets &units, const dictionary &dict),(name, units, dict))
Function1(const word &name)
Construct from name.
Definition: Function1.C:31
virtual Type value(const scalar x) const =0
Return value as a function of scalar x.
void operator=(const Function1< Type > &)
Assignment.
Definition: Function1.C:133
virtual bool constant() const
Is this function guaranteed to be constant?
Definition: Function1.C:85
const word & name() const
Return the name of the entry.
Definition: Function1.C:78
virtual void write(Ostream &os, const Function1s::unitSets &) const =0
Write data to dictionary stream.
const word name_
Name of entry.
Definition: Function1.H:69
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:68
Reference counter for various OpenFOAM components.
Definition: refCount.H:50
A class for managing temporary objects.
Definition: tmp.H:55
Unit conversion structure. Contains the associated dimensions and the multiplier with which to conver...
Definition: unitSet.H:68
A class for handling words, derived from string.
Definition: word.H:63
Namespace for OpenFOAM.
const doubleScalar e
Definition: doubleScalar.H:106
void func(FieldField< Field, Type > &f, const FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
void writeEntry(Ostream &os, const word &key, const DimensionedFieldFunction< DimensionedFieldType > &f)
Macros to ease declaration of run-time selection tables.
dictionary dict
Struct containing two unitSets for use in converting both the argument and the value of a Function1.