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-2023 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 "dictionary.H"
43 #include "tmp.H"
44 #include "typeInfo.H"
45 #include "Field.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 // Forward declaration of friend functions and operators
54 template<class Type> class Function1;
55 template<class Type> Ostream& operator<<(Ostream&, const Function1<Type>&);
56 
57 /*---------------------------------------------------------------------------*\
58  Class Function1 Declaration
59 \*---------------------------------------------------------------------------*/
60 
61 template<class Type>
62 class Function1
63 :
64  public tmp<Function1<Type>>::refCount
65 {
66 
67 protected:
68 
69  // Protected data
70 
71  //- Name of entry
72  const word name_;
73 
74 
75 public:
76 
77  typedef Type returnType;
78 
79  //- Runtime type information
80  TypeName("Function1");
81 
82  //- Declare runtime constructor selection table
84  (
85  autoPtr,
86  Function1,
87  dictionary,
88  (
89  const word& name,
90  const dictionary& dict
91  ),
92  (name, dict)
93  );
94 
95 
96  // Constructors
97 
98  //- Construct from name
99  Function1(const word& name);
100 
101  //- Copy constructor
102  Function1(const Function1<Type>& f1);
103 
104  //- Construct and return a clone
105  virtual tmp<Function1<Type>> clone() const = 0;
106 
107 
108  //- Selector
110  (
111  const word& name,
112  const dictionary& dict
113  );
114 
115 
116  //- Destructor
117  virtual ~Function1();
118 
119 
120  // Member Functions
121 
122  //- Return the name of the entry
123  const word& name() const;
124 
125  //- Return value as a function of scalar x
126  virtual Type value(const scalar x) const = 0;
127 
128  //- Return value as a function of a scalar field x
129  virtual tmp<Field<Type>> value(const scalarField& x) const = 0;
130 
131  //- Integrate between two scalars
132  virtual Type integral(const scalar x1, const scalar x2) const = 0;
133 
134  //- Integrate between two scalar fields
135  virtual tmp<Field<Type>> integral
136  (
137  const scalarField& x1,
138  const scalarField& x2
139  ) const = 0;
140 
141  //- Write data to dictionary stream
142  virtual void write(Ostream& os) const = 0;
143 
144 
145  // Member Operators
146 
147  //- Assignment
148  void operator=(const Function1<Type>&);
149 
150 
151  // IOstream Operators
152 
153  //- Ostream Operator
154  friend Ostream& operator<< <Type>
155  (
156  Ostream& os,
157  const Function1<Type>& func
158  );
159 };
160 
161 
162 template<class Type>
163 void writeEntry(Ostream& os, const Function1<Type>& f1);
164 
165 
166 /*---------------------------------------------------------------------------*\
167  Class FieldFunction1 Declaration
168 \*---------------------------------------------------------------------------*/
169 
170 template<class Type, class Function1Type>
171 class FieldFunction1
172 :
173  public Function1<Type>
174 {
175 
176 public:
177 
178  // Constructors
179 
180  //- Construct from name
181  FieldFunction1(const word& name);
182 
183  //- Construct and return a clone
184  virtual tmp<Function1<Type>> clone() const;
185 
186 
187  //- Destructor
188  virtual ~FieldFunction1();
189 
190 
191  // Member Functions
192 
193  //- Return value as a function of one scalars
194  virtual Type value(const scalar x) const = 0;
195 
196  //- Return value as a function of one scalar field
197  virtual tmp<Field<Type>> value(const scalarField& x) const;
198 
199  //- Integrate between two scalar values
200  virtual Type integral(const scalar x1, const scalar x2) const = 0;
201 
202  //- Integrate between two scalar fields
203  virtual tmp<Field<Type>> integral
204  (
205  const scalarField& x1,
206  const scalarField& x2
207  ) const;
208 };
209 
210 
211 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
212 
213 } // End namespace Foam
214 
215 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
216 
217 #define makeFunction1(Type) \
218  \
219  defineNamedTemplateTypeNameAndDebug(Function1<Type>, 0); \
220  defineTemplateRunTimeSelectionTable(Function1<Type>, dictionary);
221 
222 
223 #define makeFunction1Type(SS, Type) \
224  \
225  defineNamedTemplateTypeNameAndDebug(SS<Type>, 0); \
226  typedef Function1<Type> Type##Function1; \
227  typedef SS<Type> Type##SS##Function1; \
228  addToRunTimeSelectionTable \
229  ( \
230  Type##Function1, \
231  Type##SS##Function1, \
232  dictionary \
233  )
234 
235 
236 #define makeNamedFunction1Type(SS, Type, Name) \
237  \
238  typedef Function1<Type> Type##Function1; \
239  typedef SS<Type> Type##SS##Function1; \
240  addNamedToRunTimeSelectionTable \
241  ( \
242  Type##Function1, \
243  Type##SS##Function1, \
244  dictionary, \
245  Name \
246  )
247 
248 
249 #define makeScalarFunction1(SS) \
250  \
251  defineTypeNameAndDebug(SS, 0); \
252  typedef Function1<scalar> scalarFunction1; \
253  addToRunTimeSelectionTable(scalarFunction1, SS, dictionary)
254 
255 
256 #define makeFunction1s(Type, nullArg) \
257  \
258  template<> \
259  const char* const Foam::Tuple2<Foam::scalar, Type>::typeName \
260  ( \
261  "Tuple2<scalar," #Type ">" \
262  ); \
263  \
264  makeFunction1(Type); \
265  \
266  namespace Function1s \
267  { \
268  makeFunction1Type(None, Type); \
269  makeFunction1Type(Constant, Type); \
270  makeFunction1Type(Uniform, Type); \
271  makeFunction1Type(ZeroConstant, Type); \
272  makeFunction1Type(OneConstant, Type); \
273  makeFunction1Type(Polynomial, Type); \
274  makeFunction1Type(Sine, Type); \
275  makeFunction1Type(Square, Type); \
276  makeFunction1Type(Table, Type); \
277  makeFunction1Type(UniformTable, Type); \
278  makeFunction1Type(NonUniformTable, Type); \
279  makeNamedFunction1Type(Table, Type, tableFile); \
280  makeFunction1Type(Scale, Type); \
281  makeFunction1Type(Coded, Type); \
282  }
283 
284 
285 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
286 
287 #ifdef NoRepository
288  #include "Function1.C"
289  #include "Constant.H"
290 #endif
291 
292 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
293 
294 #endif
295 
296 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
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:48
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:58
virtual ~FieldFunction1()
Destructor.
Definition: Function1.C:75
Run-time selectable general function of one variable.
Definition: Function1.H:64
virtual Type integral(const scalar x1, const scalar x2) const =0
Integrate between two scalars.
TypeName("Function1")
Runtime type information.
virtual ~Function1()
Destructor.
Definition: Function1.C:70
virtual tmp< Function1< Type > > clone() const =0
Construct and return a clone.
Function1(const word &name)
Construct from name.
Definition: Function1.C:32
virtual Type value(const scalar x) const =0
Return value as a function of scalar x.
declareRunTimeSelectionTable(autoPtr, Function1, dictionary,(const word &name, const dictionary &dict),(name, dict))
Declare runtime constructor selection table.
void operator=(const Function1< Type > &)
Assignment.
Definition: Function1.C:130
const word & name() const
Return the name of the entry.
Definition: Function1.C:82
static autoPtr< Function1< Type > > New(const word &name, const dictionary &dict)
Selector.
Definition: Function1New.C:32
virtual void write(Ostream &os) const =0
Write data to dictionary stream.
const word name_
Name of entry.
Definition: Function1.H:71
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 keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
Reference counter for various OpenFOAM components.
Definition: refCount.H:50
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
void func(FieldField< Field, Type > &f, const FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
Ostream & operator<<(Ostream &, const ensightPart &)
dictionary dict