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-2018 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  // Private Member Functions
67 
68  //- Disallow default bitwise assignment
69  void operator=(const Function1<Type>&);
70 
71 
72 protected:
73 
74  // Protected data
75 
76  //- Name of entry
77  const word name_;
78 
79 
80 public:
81 
82  typedef Type returnType;
83 
84  //- Runtime type information
85  TypeName("Function1")
86 
87  //- Declare runtime constructor selection table
89  (
91  Function1,
92  dictionary,
93  (
94  const word& entryName,
95  const dictionary& dict
96  ),
97  (entryName, dict)
98  );
99 
100 
101  // Constructors
102 
103  //- Construct from entry name
104  Function1(const word& entryName);
105 
106  //- Copy constructor
107  Function1(const Function1<Type>& f1);
108 
109  //- Construct and return a clone
110  virtual tmp<Function1<Type>> clone() const = 0;
111 
112 
113  //- Selector
114  static autoPtr<Function1<Type>> New
115  (
116  const word& entryName,
117  const dictionary& dict
118  );
119 
120 
121  //- Destructor
122  virtual ~Function1();
123 
124 
125  // Member Functions
126 
127  // Access
128 
129  //- Return the name of the entry
130  const word& name() const;
131 
132 
133  // Manipulation
134 
135  //- Convert time
136  virtual void convertTimeBase(const Time& t);
137 
138 
139  // Evaluation
140 
141  //- Return value as a function of (scalar) independent variable
142  virtual Type value(const scalar x) const;
143 
144  //- Return value as a function of (scalar) independent variable
145  virtual tmp<Field<Type>> value(const scalarField& x) const = 0;
146 
147  //- Integrate between two (scalar) values
148  virtual Type integrate(const scalar x1, const scalar x2) const;
149 
150  //- Integrate between two (scalar) values
151  virtual tmp<Field<Type>> integrate
152  (
153  const scalarField& x1,
154  const scalarField& x2
155  ) const = 0;
156 
157 
158  // I/O
159 
160  //- Ostream Operator
161  friend Ostream& operator<< <Type>
162  (
163  Ostream& os,
164  const Function1<Type>& func
165  );
166 
167  //- Write in dictionary format
168  virtual void writeData(Ostream& os) const;
169 };
170 
171 
172 /*---------------------------------------------------------------------------*\
173  Class FieldFunction1 Declaration
174 \*---------------------------------------------------------------------------*/
175 
176 template<class Function1Type>
177 class FieldFunction1
178 :
179  public Function1Type
180 {
181 
182 public:
184  typedef typename Function1Type::returnType Type;
185 
186 
187  // Constructors
188 
189  //- Construct from entry name and dictionary
190  FieldFunction1(const word& entryName, const dictionary& dict);
191 
192  //- Construct and return a clone
193  virtual tmp<Function1<Type>> clone() const;
194 
195 
196  //- Destructor
197  virtual ~FieldFunction1()
198  {}
199 
200 
201  // Member Functions
202 
203  // Evaluation
204 
205  using Function1Type::value;
206  using Function1Type::integrate;
207 
208  //- Return value as a function of (scalar) independent variable
209  virtual tmp<Field<Type>> value(const scalarField& x) const;
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 \
231  ( \
232  Function1<Type>, \
233  dictionary \
234  );
235 
237 #define makeFunction1Type(SS, Type) \
238  \
239  defineNamedTemplateTypeNameAndDebug(Function1Types::SS<Type>, 0); \
240  \
241  Function1<Type>::adddictionaryConstructorToTable \
242  <FieldFunction1<Function1Types::SS<Type>>> \
243  add##SS##Type##ConstructorToTable_;
244 
246 #define makeScalarFunction1(SS) \
247  \
248  defineTypeNameAndDebug(SS, 0); \
249  \
250  Function1<scalar>::adddictionaryConstructorToTable<FieldFunction1<SS>> \
251  add##SS##ConstructorToTable_;
252 
253 
254 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
255 
256 #ifdef NoRepository
257  #include "Function1.C"
258  #include "Constant.H"
259 #endif
260 
261 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
262 
263 #endif
264 
265 // ************************************************************************* //
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
const word const dictionary & dict
Definition: Function1.H:90
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
const word & name() const
Return the name of the entry.
Definition: Function1.C:56
const word & entryName
Definition: Function1.H:90
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:146
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:183
Pre-declare SubField and related Field type.
Definition: Field.H:57
A class for handling words, derived from string.
Definition: word.H:59
const word name_
Name of entry.
Definition: Function1.H:76
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:77
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.