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-2017 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  (
88  autoPtr,
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 = 0;
109 
110 
111  //- Selector
112  static autoPtr<Function1<Type>> New
113  (
114  const word& entryName,
115  const dictionary& dict
116  );
117 
118 
119  //- Destructor
120  virtual ~Function1();
121 
122 
123  // Member Functions
124 
125  // Access
126 
127  //- Return the name of the entry
128  const word& name() const;
129 
130 
131  // Manipulation
132 
133  //- Convert time
134  virtual void convertTimeBase(const Time& t);
135 
136 
137  // Evaluation
138 
139  //- Return value as a function of (scalar) independent variable
140  virtual Type value(const scalar x) const;
141 
142  //- Return value as a function of (scalar) independent variable
143  virtual tmp<Field<Type>> value(const scalarField& x) const;
144 
145  //- Integrate between two (scalar) values
146  virtual Type integrate(const scalar x1, const scalar x2) const;
147 
148  //- Integrate between two (scalar) values
149  virtual tmp<Field<Type>> integrate
150  (
151  const scalarField& x1,
152  const scalarField& x2
153  ) const;
154 
155 
156  // I/O
157 
158  //- Ostream Operator
159  friend Ostream& operator<< <Type>
160  (
161  Ostream& os,
162  const Function1<Type>& func
163  );
164 
165  //- Write in dictionary format
166  virtual void writeData(Ostream& os) const;
167 };
168 
169 
170 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
171 
172 } // End namespace Foam
173 
174 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
176 #define makeFunction1(Type) \
177  \
178  defineNamedTemplateTypeNameAndDebug(Function1<Type>, 0); \
179  \
180  defineTemplateRunTimeSelectionTable \
181  ( \
182  Function1<Type>, \
183  dictionary \
184  );
185 
187 #define makeFunction1Type(SS, Type) \
188  \
189  defineNamedTemplateTypeNameAndDebug(Function1Types::SS<Type>, 0); \
190  \
191  Function1<Type>::adddictionaryConstructorToTable<Function1Types::SS<Type>> \
192  add##SS##Type##ConstructorToTable_;
193 
195 #define makeScalarFunction1(SS) \
196  \
197  defineTypeNameAndDebug(SS, 0); \
198  \
199  Function1<scalar>::adddictionaryConstructorToTable<SS> \
200  add##SS##ConstructorToTable_;
201 
202 
203 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
204 
205 #ifdef NoRepository
206  #include "Function1.C"
207  #include "Constant.H"
208 #endif
209 
210 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
211 
212 #endif
213 
214 // ************************************************************************* //
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: Function1.H:53
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
const word & name() const
Return the name of the entry.
Definition: Function1.C:56
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
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: Function1.C:121
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.
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
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.
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.