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 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 SourceFiles
37  Function1.C
38  Function1New.C
39 
40 \*---------------------------------------------------------------------------*/
41 
42 #ifndef Function1_H
43 #define Function1_H
44 
45 #include "dictionary.H"
46 #include "Field.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 // Forward declarations
54 class Time;
55 
56 // Forward declaration of friend functions and operators
57 template<class Type> class Function1;
58 template<class Type> Ostream& operator<<(Ostream&, const Function1<Type>&);
59 
60 /*---------------------------------------------------------------------------*\
61  Class Function1 Declaration
62 \*---------------------------------------------------------------------------*/
63 
64 template<class Type>
65 class Function1
66 :
67  public refCount
68 {
69  // Private Member Functions
70 
71  //- No copy assignment
72  void operator=(const Function1<Type>&) = delete;
73 
74 
75 protected:
76 
77  // Protected data
78 
79  //- Name of entry
80  const word name_;
81 
82 
83 public:
84 
85  typedef Type returnType;
86 
87  //- Runtime type information
88  TypeName("Function1")
89 
90  //- Declare runtime constructor selection table
92  (
95  dictionary,
96  (
97  const word& entryName,
99  ),
101  );
102 
103 
104  // Constructors
105 
106  //- Construct from entry name
107  explicit Function1(const word& entryName);
108 
109  //- Copy constructor
110  explicit Function1(const Function1<Type>& f1);
111 
112  //- Construct and return a clone
113  virtual tmp<Function1<Type>> clone() const = 0;
114 
115 
116  //- Selector
117  static autoPtr<Function1<Type>> New
118  (
119  const word& entryName,
120  const dictionary& dict,
121  const word& redirectType = word::null
122  );
123 
124 
125  //- Destructor
126  virtual ~Function1() = default;
127 
128 
129  // Member Functions
130 
131  // Access
132 
133  //- Return the name of the entry
134  const word& name() const;
135 
136 
137  // Manipulation
138 
139  //- Convert time
140  virtual void convertTimeBase(const Time& t);
141 
142 
143  // Evaluation
144 
145  //- Return value as a function of (scalar) independent variable
146  virtual Type value(const scalar x) const;
147 
148  //- Return value as a function of (scalar) independent variable
149  virtual tmp<Field<Type>> value(const scalarField& x) const;
150 
151  //- Integrate between two (scalar) values
152  virtual Type integrate(const scalar x1, const scalar x2) const;
153 
154  //- Integrate between two (scalar) values
155  virtual tmp<Field<Type>> integrate
156  (
157  const scalarField& x1,
158  const scalarField& x2
159  ) const;
160 
161 
162  // I/O
163 
164  //- Ostream Operator
165  friend Ostream& operator<< <Type>
166  (
167  Ostream& os,
168  const Function1<Type>& func
169  );
170 
171  //- Write in dictionary format
172  virtual void writeData(Ostream& os) const;
173 };
174 
175 
176 /*---------------------------------------------------------------------------*\
177  Class FieldFunction1 Declaration
178 \*---------------------------------------------------------------------------*/
179 
180 template<class Function1Type>
181 class FieldFunction1
182 :
183  public Function1Type
184 {
185 
186 public:
187 
188  typedef typename Function1Type::returnType Type;
189 
190 
191  // Constructors
192 
193  //- Construct from entry name and dictionary
194  FieldFunction1(const word& entryName, const dictionary& dict);
195 
196  //- Construct and return a clone
197  virtual tmp<Function1<Type>> clone() const;
198 
199 
200  //- Destructor
201  virtual ~FieldFunction1() = default;
202 
203 
204  // Member Functions
205 
206  // Evaluation
207 
208  using Function1Type::value;
209  using Function1Type::integrate;
210 
211  //- Return value as a function of (scalar) independent variable
212  virtual tmp<Field<Type>> value(const scalarField& x) const;
213 
214  //- Integrate between two (scalar) values
215  virtual tmp<Field<Type>> integrate
216  (
217  const scalarField& x1,
218  const scalarField& x2
219  ) const;
220 };
221 
222 
223 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
224 
225 } // End namespace Foam
226 
227 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
228 
229 #define makeFunction1(Type) \
230  \
231  defineNamedTemplateTypeNameAndDebug(Function1<Type>, 0); \
232  \
233  defineTemplateRunTimeSelectionTable \
234  ( \
235  Function1<Type>, \
236  dictionary \
237  );
238 
239 
240 #define makeFunction1Type(SS, Type) \
241  \
242  defineNamedTemplateTypeNameAndDebug(Function1Types::SS<Type>, 0); \
243  \
244  Function1<Type>::adddictionaryConstructorToTable \
245  <FieldFunction1<Function1Types::SS<Type>>> \
246  add##SS##Type##ConstructorToTable_;
247 
248 
249 #define makeScalarFunction1(SS) \
250  \
251  defineTypeNameAndDebug(SS, 0); \
252  \
253  Function1<scalar>::adddictionaryConstructorToTable<FieldFunction1<SS>> \
254  add##SS##ConstructorToTable_;
255 
256 
257 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
258 
259 #ifdef NoRepository
260  #include "Function1.C"
261 #endif
262 
263 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
264 
265 #endif
266 
267 // ************************************************************************* //
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:96
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:98
Foam::Function1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: Function1.H:56
Foam::FieldFunction1
Definition: Function1.H:180
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:53
Foam::Function1::returnType
Type returnType
Definition: Function1.H:84
Field.H
Foam::Function1::writeData
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: Function1.C:165
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:65
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:79
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:187
x
x
Definition: LISASMDCalcMethod2.H:52
Function1.C
Foam::Function1::convertTimeBase
virtual void convertTimeBase(const Time &t)
Convert time.
Definition: Function1.C:60
Foam::Function1::integrate
virtual Type integrate(const scalar x1, const scalar x2) const
Integrate between two (scalar) values.
Definition: Function1.C:84
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.
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &)
Definition: boundaryPatch.C:102