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 | Copyright (C) 2011-2016 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  //- Runtime type information
83  TypeName("Function1")
84 
85  //- Declare runtime constructor selection table
87  (
89  Function1,
90  dictionary,
91  (
92  const word& entryName,
93  const dictionary& dict
94  ),
95  (entryName, dict)
96  );
97 
98 
99  // Constructor
100 
101  //- Construct from entry name
102  Function1(const word& entryName);
103 
104  //- Copy constructor
105  Function1(const Function1<Type>& de);
106 
107  //- Construct and return a clone
108  virtual tmp<Function1<Type>> clone() const
109  {
110  return tmp<Function1<Type>>(new Function1<Type>(*this));
111  }
112 
113 
114  //- Selector
116  (
117  const word& entryName,
118  const dictionary& dict
119  );
120 
121 
122  //- Destructor
123  virtual ~Function1();
124 
125 
126  // Member Functions
127 
128  // Access
129 
130  //- Return the name of the entry
131  const word& name() const;
132 
133 
134  // Manipulation
135 
136  //- Convert time
137  virtual void convertTimeBase(const Time& t);
138 
139 
140  // Evaluation
141 
142  //- Return value as a function of (scalar) independent variable
143  virtual Type value(const scalar x) const;
144 
145  //- Return value as a function of (scalar) independent variable
146  virtual tmp<Field<Type>> value(const scalarField& x) const;
147 
148  //- Integrate between two (scalar) values
149  virtual Type integrate(const scalar x1, const scalar x2) const;
150 
151  //- Integrate between two (scalar) values
152  virtual tmp<Field<Type>> integrate
153  (
154  const scalarField& x1,
155  const scalarField& x2
156  ) const;
157 
158 
159  // I/O
160 
161  //- Ostream Operator
162  friend Ostream& operator<< <Type>
163  (
164  Ostream& os,
165  const Function1<Type>& de
166  );
167 
168  //- Write in dictionary format
169  virtual void writeData(Ostream& os) const;
170 };
171 
172 
173 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
174 
175 } // End namespace Foam
176 
177 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
179 #define makeFunction1(Type) \
180  \
181  defineNamedTemplateTypeNameAndDebug(Function1<Type>, 0); \
182  \
183  defineTemplateRunTimeSelectionTable \
184  ( \
185  Function1<Type>, \
186  dictionary \
187  );
188 
190 #define makeFunction1Type(SS, Type) \
191  \
192  defineNamedTemplateTypeNameAndDebug(Function1Types::SS<Type>, 0); \
193  \
194  Function1<Type>::adddictionaryConstructorToTable<Function1Types::SS<Type>> \
195  add##SS##Type##ConstructorToTable_;
196 
197 
198 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
199 
200 #ifdef NoRepository
201  #include "Function1.C"
202  #include "Constant.H"
203 #endif
204 
205 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
206 
207 #endif
208 
209 // ************************************************************************* //
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 & name() const
Return the name of the entry.
Definition: Function1.C:56
const word const dictionary & dict
Definition: Function1.H:88
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:137
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: Function1.C:121
const word & entryName
Definition: Function1.H:88
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
A class for handling words, derived from string.
Definition: word.H:59
const word name_
Name of entry.
Definition: Function1.H:76
virtual Type integrate(const scalar x1, const scalar x2) const
Integrate between two (scalar) values.
Definition: Function1.C:77
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
virtual ~Function1()
Destructor.
Definition: Function1.C:49
virtual void convertTimeBase(const Time &t)
Convert time.
Definition: Function1.C:63
#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:53
virtual Type value(const scalar x) const
Return value as a function of (scalar) independent variable.
Definition: Function1.C:68
A class for managing temporary objects.
Definition: PtrList.H:54
virtual tmp< Function1< Type > > clone() const
Construct and return a clone.
Definition: Function1.H:107
static autoPtr< Function1< Type > > New(const word &entryName, const dictionary &dict)
Selector.
Definition: Function1New.C:32
Namespace for OpenFOAM.