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 "Field.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 // Forward declarations
51 class Time;
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  (
86  Function1,
87  dictionary,
88  (
89  const word& entryName,
90  const dictionary& dict
91  ),
92  (entryName, dict)
93  );
94 
95 
96  // Constructors
97 
98  //- Construct from entry name
99  Function1(const word& entryName);
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
109  static autoPtr<Function1<Type>> New
110  (
111  const word& entryName,
112  const dictionary& dict
113  );
114 
115 
116  //- Destructor
117  virtual ~Function1();
118 
119 
120  // Member Functions
121 
122  // Access
123 
124  //- Return the name of the entry
125  const word& name() const;
126 
127 
128  // Manipulation
129 
130  //- Convert time
131  virtual void convertTimeBase(const Time& t);
132 
133 
134  // Evaluation
135 
136  //- Return value as a function of (scalar) independent variable
137  virtual Type value(const scalar x) const;
138 
139  //- Return value as a function of (scalar) independent variable
140  virtual tmp<Field<Type>> value(const scalarField& x) const = 0;
141 
142  //- Integrate between two (scalar) values
143  virtual Type integrate(const scalar x1, const scalar x2) const;
144 
145  //- Integrate between two (scalar) values
146  virtual tmp<Field<Type>> integrate
147  (
148  const scalarField& x1,
149  const scalarField& x2
150  ) const = 0;
151 
152 
153  // I/O
154 
155  //- Ostream Operator
156  friend Ostream& operator<< <Type>
157  (
158  Ostream& os,
159  const Function1<Type>& func
160  );
161 
162  //- Write in dictionary format
163  virtual void writeData(Ostream& os) const;
164 
165 
166  // Member Operators
167 
168  //- Disallow default bitwise assignment
169  void operator=(const Function1<Type>&) = delete;
170 };
171 
172 
173 template<class Type>
174 void writeEntry(Ostream& os, const Function1<Type>& f1);
175 
176 
177 /*---------------------------------------------------------------------------*\
178  Class FieldFunction1 Declaration
179 \*---------------------------------------------------------------------------*/
180 
181 template<class Function1Type>
182 class FieldFunction1
183 :
184  public Function1Type
185 {
186 
187 public:
189  typedef typename Function1Type::returnType Type;
190 
191 
192  // Constructors
193 
194  //- Construct from entry name and dictionary
195  FieldFunction1(const word& entryName, const dictionary& dict);
196 
197  //- Construct and return a clone
198  virtual tmp<Function1<Type>> clone() const;
199 
200 
201  //- Destructor
202  virtual ~FieldFunction1()
203  {}
204 
205 
206  // Member Functions
207 
208  // Evaluation
209 
210  using Function1Type::value;
211  using Function1Type::integrate;
212 
213  //- Return value as a function of (scalar) independent variable
214  virtual tmp<Field<Type>> value(const scalarField& x) const;
215 
216  //- Integrate between two (scalar) values
217  virtual tmp<Field<Type>> integrate
218  (
219  const scalarField& x1,
220  const scalarField& x2
221  ) const;
222 };
223 
224 
225 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
226 
227 } // End namespace Foam
228 
229 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
231 #define makeFunction1(Type) \
232  \
233  defineNamedTemplateTypeNameAndDebug(Function1<Type>, 0); \
234  \
235  defineTemplateRunTimeSelectionTable \
236  ( \
237  Function1<Type>, \
238  dictionary \
239  );
240 
242 #define makeFunction1Type(SS, Type) \
243  \
244  defineNamedTemplateTypeNameAndDebug(Function1Types::SS<Type>, 0); \
245  \
246  Function1<Type>::adddictionaryConstructorToTable \
247  <FieldFunction1<Function1Types::SS<Type>>> \
248  add##SS##Type##ConstructorToTable_;
249 
251 #define makeScalarFunction1(SS) \
252  \
253  defineTypeNameAndDebug(SS, 0); \
254  \
255  Function1<scalar>::adddictionaryConstructorToTable<FieldFunction1<SS>> \
256  add##SS##ConstructorToTable_;
257 
258 
259 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
260 
261 #ifdef NoRepository
262  #include "Function1.C"
263  #include "Constant.H"
264 #endif
265 
266 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
267 
268 #endif
269 
270 // ************************************************************************* //
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: Function1.H:53
const word const dictionary & dict
Definition: Function1.H:85
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:56
const word & entryName
Definition: Function1.H:85
TypeName("Function1") declareRunTimeSelectionTable(autoPtr
Runtime type information.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
scalar f1
Definition: createFields.H:28
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: Function1.C:150
virtual Type value(const scalar x) const
Return value as a function of (scalar) independent variable.
Definition: Function1.C:68
friend Ostream & operator(Ostream &os, const Function1< Type > &func)
Ostream Operator.
Function1Type::returnType Type
Definition: Function1.H:188
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:71
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:53
virtual Type integrate(const scalar x1, const scalar x2) const
Integrate between two (scalar) values.
Definition: Function1.C:79
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
virtual void convertTimeBase(const Time &t)
Convert time.
Definition: Function1.C:63
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
static autoPtr< Function1< Type > > New(const word &entryName, const dictionary &dict)
Selector.
Definition: Function1New.C:32
Namespace for OpenFOAM.