Function1.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2018-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::Function1
29 
30 Description
31  Top level data entry class for use in dictionaries. Provides a mechanism
32  to specify a variable as a certain type, e.g. constant or table, and
33  provide functions to return the (interpolated) value, and integral between
34  limits.
35 
36  The New factory method attempts to deal with varying types of input.
37  It accepts primitive or dictionary entries for dispatching to different
38  function types, but wraps unspecified types as "constant".
39 
40  In the dictionary form, the coefficents are the dictionary itself.
41  This is arguably the more readable form.
42  For example,
43  \verbatim
44  <entryName>
45  {
46  type linearRamp;
47  start 10;
48  duration 20;
49  }
50  \endverbatim
51 
52  In the primitive form, the coefficents are provided separately.
53  For example,
54  \verbatim
55  <entryName> linearRamp;
56  <entryName>Coeffs
57  {
58  start 10;
59  duration 20;
60  }
61  \endverbatim
62  The coeffs dictionary is optional, since it is not required by all types.
63  For example,
64  \verbatim
65  <entryName> zero;
66  \endverbatim
67 
68 SourceFiles
69  Function1.C
70  Function1New.C
71 
72 \*---------------------------------------------------------------------------*/
73 
74 #ifndef Function1_H
75 #define Function1_H
76 
77 #include "dictionary.H"
78 #include "Field.H"
79 
80 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
81 
82 namespace Foam
83 {
84 
85 // Forward Declarations
86 class Time;
87 template<class Type> class Function1;
88 template<class Type> Ostream& operator<<(Ostream&, const Function1<Type>&);
89 
90 /*---------------------------------------------------------------------------*\
91  Class Function1 Declaration
92 \*---------------------------------------------------------------------------*/
93 
94 template<class Type>
95 class Function1
96 :
97  public refCount
98 {
99 protected:
100 
101  // Protected Data
102 
103  //- Name of entry
104  const word name_;
105 
106  // Protected Member Functions
107 
108  //- No copy assignment
109  void operator=(const Function1<Type>&) = delete;
110 
111 
112 public:
113 
114  typedef Type returnType;
115 
116  //- Runtime type information
117  TypeName("Function1")
118 
119  //- Declare runtime constructor selection table
121  (
124  dictionary,
125  (
126  const word& entryName,
128  ),
130  );
131 
132 
133  // Constructors
134 
135  //- Construct from entry name
136  explicit Function1(const word& entryName);
137 
138  //- Copy constructor
139  explicit Function1(const Function1<Type>& rhs);
140 
141  //- Construct and return a clone
142  virtual tmp<Function1<Type>> clone() const = 0;
143 
144 
145  //- Selector
146  static autoPtr<Function1<Type>> New
147  (
148  const word& entryName,
149  const dictionary& dict,
150  const word& redirectType = word::null
151  );
152 
153 
154  //- Destructor
155  virtual ~Function1() = default;
156 
157 
158  // Member Functions
159 
160  // Access
161 
162  //- Return the name of the entry
163  const word& name() const;
164 
165 
166  // Manipulation
167 
168  //- Convert time
169  virtual void convertTimeBase(const Time& t);
170 
171 
172  // Evaluation
173 
174  //- Return value as a function of (scalar) independent variable
175  virtual Type value(const scalar x) const;
176 
177  //- Return value as a function of (scalar) independent variable
178  virtual tmp<Field<Type>> value(const scalarField& x) const;
179 
180  //- Integrate between two (scalar) values
181  virtual Type integrate(const scalar x1, const scalar x2) const;
182 
183  //- Integrate between two (scalar) values
184  virtual tmp<Field<Type>> integrate
185  (
186  const scalarField& x1,
187  const scalarField& x2
188  ) const;
189 
190 
191  // I/O
192 
193  //- Ostream Operator
194  friend Ostream& operator<< <Type>
195  (
196  Ostream& os,
197  const Function1<Type>& func
198  );
199 
200  //- Write in dictionary format
201  virtual void writeData(Ostream& os) const;
202 };
203 
204 
205 /*---------------------------------------------------------------------------*\
206  Class FieldFunction1 Declaration
207 \*---------------------------------------------------------------------------*/
208 
209 template<class Function1Type>
210 class FieldFunction1
211 :
212  public Function1Type
213 {
214 
215 public:
216 
217  typedef typename Function1Type::returnType Type;
218 
219 
220  // Constructors
221 
222  //- Construct from entry name and dictionary
223  FieldFunction1(const word& entryName, const dictionary& dict);
224 
225  //- Construct and return a clone
226  virtual tmp<Function1<Type>> clone() const;
227 
228 
229  //- Destructor
230  virtual ~FieldFunction1() = default;
231 
232 
233  // Member Functions
234 
235  // Evaluation
236 
237  using Function1Type::value;
238  using Function1Type::integrate;
239 
240  //- Return value as a function of (scalar) independent variable
241  virtual tmp<Field<Type>> value(const scalarField& x) const;
242 
243  //- Integrate between two (scalar) values
244  virtual tmp<Field<Type>> integrate
245  (
246  const scalarField& x1,
247  const scalarField& x2
248  ) const;
249 };
250 
251 
252 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
253 
254 } // End namespace Foam
255 
256 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
257 
258 #define makeFunction1(Type) \
259  \
260  defineNamedTemplateTypeNameAndDebug(Function1<Type>, 0); \
261  \
262  defineTemplateRunTimeSelectionTable \
263  ( \
264  Function1<Type>, \
265  dictionary \
266  );
267 
268 
269 #define makeFunction1Type(SS, Type) \
270  \
271  defineNamedTemplateTypeNameAndDebug(Function1Types::SS<Type>, 0); \
272  \
273  Function1<Type>::adddictionaryConstructorToTable \
274  <FieldFunction1<Function1Types::SS<Type>>> \
275  add##SS##Type##ConstructorToTable_;
276 
277 
278 #define makeScalarFunction1(SS) \
279  \
280  defineTypeNameAndDebug(SS, 0); \
281  \
282  Function1<scalar>::adddictionaryConstructorToTable<FieldFunction1<SS>> \
283  add##SS##ConstructorToTable_;
284 
285 
286 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
287 
288 #ifdef NoRepository
289  #include "Function1.C"
290 #endif
291 
292 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
293 
294 #endif
295 
296 // ************************************************************************* //
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::refCount
Reference counter for various OpenFOAM components.
Definition: refCount.H:50
Foam::Function1::entryName
const word & entryName
Definition: Function1.H:125
Foam::Function1::operator
friend Ostream & operator(Ostream &os, const Function1< Type > &func)
Ostream Operator.
Foam::Function1::dict
const word const dictionary & dict
Definition: Function1.H:127
Foam::Function1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: Function1.H:86
Foam::FieldFunction1
Definition: Function1.H:209
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::Function1::TypeName
TypeName("Function1") declareRunTimeSelectionTable(autoPtr
Runtime type information.
Foam::Function1::name
const word & name() const
Return the name of the entry.
Definition: Function1.C:54
Foam::Function1::returnType
Type returnType
Definition: Function1.H:113
Field.H
Foam::Function1::writeData
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: Function1.C:165
Foam::Function1::operator=
void operator=(const Function1< Type > &)=delete
No copy assignment.
Foam::func
void func(FieldField< Field, Type > &f, const FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Foam::Function1::value
virtual Type value(const scalar x) const
Return value as a function of (scalar) independent variable.
Definition: Function1.C:66
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::Function1::name_
const word name_
Name of entry.
Definition: Function1.H:103
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
dictionary.H
declareRunTimeSelectionTable
#define declareRunTimeSelectionTable(autoPtr, baseType, argNames, argList, parList)
Declare a run-time selection.
Definition: runTimeSelectionTables.H:49
Foam::FieldFunction1::Type
Function1Type::returnType Type
Definition: Function1.H:216
x
x
Definition: LISASMDCalcMethod2.H:52
Function1.C
Foam::Function1::convertTimeBase
virtual void convertTimeBase(const Time &t)
Convert time.
Definition: Function1.C:61
Foam::Function1::integrate
virtual Type integrate(const scalar x1, const scalar x2) const
Integrate between two (scalar) values.
Definition: Function1.C:85
Foam::Function1::New
static autoPtr< Function1< Type > > New(const word &entryName, const dictionary &dict, const word &redirectType=word::null)
Selector.
Definition: Function1New.C:35
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::Function1::clone
virtual tmp< Function1< Type > > clone() const =0
Construct and return a clone.