All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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-2019 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  Top level data entry class for use in dictionaries. Provides a mechanism
29  to specify a variable as a certain type, e.g. constant or table, and
30  provide functions to return the (interpolated) value, and integral between
31  limits.
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& entryName,
89  const dictionary& dict
90  ),
91  (entryName, dict)
92  );
93 
94 
95  // Constructors
96 
97  //- Construct from entry name
98  Function1(const word& entryName);
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& entryName,
111  const dictionary& dict
112  );
113 
114 
115  //- Destructor
116  virtual ~Function1();
117 
118 
119  // Member Functions
120 
121  // Access
122 
123  //- Return the name of the entry
124  const word& name() const;
125 
126 
127  // Evaluation
128 
129  //- Return value as a function of (scalar) independent variable
130  virtual Type value(const scalar x) const = 0;
131 
132  //- Return value as a function of (scalar) independent variable
133  virtual tmp<Field<Type>> value(const scalarField& x) const = 0;
134 
135  //- Integrate between two (scalar) values
136  virtual Type integrate(const scalar x1, const scalar x2) const = 0;
137 
138  //- Integrate between two (scalar) values
139  virtual tmp<Field<Type>> integrate
140  (
141  const scalarField& x1,
142  const scalarField& x2
143  ) const = 0;
144 
145 
146  // I/O
147 
148  //- Ostream Operator
149  friend Ostream& operator<< <Type>
150  (
151  Ostream& os,
152  const Function1<Type>& func
153  );
154 
155  //- Write in dictionary format
156  virtual void writeData(Ostream& os) const;
157 
158 
159  // Member Operators
160 
161  //- Disallow default bitwise assignment
162  void operator=(const Function1<Type>&) = delete;
163 };
164 
165 
166 template<class Type>
167 void writeEntry(Ostream& os, const Function1<Type>& f1);
168 
169 
170 /*---------------------------------------------------------------------------*\
171  Class FieldFunction1 Declaration
172 \*---------------------------------------------------------------------------*/
173 
174 template<class Type, class Function1Type>
175 class FieldFunction1
176 :
177  public Function1<Type>
178 {
179 
180 public:
181 
182  // Constructors
183 
184  //- Construct from entry name
185  FieldFunction1(const word& entryName);
186 
187  //- Copy constructor
189 
190  //- Construct and return a clone
191  virtual tmp<Function1<Type>> clone() const;
192 
193 
194  //- Destructor
195  virtual ~FieldFunction1();
196 
197 
198  // Member Functions
199 
200  // Evaluation
201 
202  //- Return value as a function of (scalar) independent variable
203  virtual Type value(const scalar x) const = 0;
204 
205  //- Return value as a function of (scalar) independent variable
206  virtual tmp<Field<Type>> value(const scalarField& x) const;
207 
208  //- Integrate between two (scalar) values
209  virtual Type integrate(const scalar x1, const scalar x2) const = 0;
210 
211  //- Integrate between two (scalar) values
212  virtual tmp<Field<Type>> integrate
213  (
214  const scalarField& x1,
215  const scalarField& x2
216  ) const;
217 };
218 
219 
220 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
221 
222 } // End namespace Foam
223 
224 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
226 #define makeFunction1(Type) \
227  \
228  defineNamedTemplateTypeNameAndDebug(Function1<Type>, 0); \
229  \
230  defineTemplateRunTimeSelectionTable(Function1<Type>, dictionary);
231 
233 #define makeFunction1Type(SS, Type) \
234  \
235  defineNamedTemplateTypeNameAndDebug(Function1s::SS<Type>, 0); \
236  \
237  Function1<Type>::adddictionaryConstructorToTable<Function1s::SS<Type>> \
238  add##SS##Type##ConstructorToTable_;
239 
241 #define makeScalarFunction1(SS) \
242  \
243  defineTypeNameAndDebug(SS, 0); \
244  \
245  Function1<scalar>::adddictionaryConstructorToTable<SS> \
246  add##SS##ConstructorToTable_;
247 
248 
249 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
250 
251 #ifdef NoRepository
252  #include "Function1.C"
253  #include "Constant.H"
254 #endif
255 
256 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
257 
258 #endif
259 
260 // ************************************************************************* //
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: Function1.H:52
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:158
const word & name() const
Return the name of the entry.
Definition: Function1.C:91
const word & entryName
Definition: Function1.H:84
TypeName("Function1") declareRunTimeSelectionTable(autoPtr
Runtime type information.
scalar f1
Definition: createFields.H:28
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: Function1.C:98
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) independent variable.
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.
virtual Type integrate(const scalar x1, const scalar x2) const =0
Integrate between two (scalar) 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
A class for managing temporary objects.
Definition: PtrList.H:53
static autoPtr< Function1< Type > > New(const word &entryName, const dictionary &dict)
Selector.
Definition: Function1New.C:32
Namespace for OpenFOAM.