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