Function2.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) 2020-2023 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::Function2
26 
27 Description
28  Run-time selectable function of two variables
29 
30  with many options provided from simple constant values to complex
31  functions, interpolated tabulated data etc. etc.
32 
33 SourceFiles
34  Function2.C
35  Function2New.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef Function2_H
40 #define Function2_H
41 
42 #include "dictionary.H"
43 #include "tmp.H"
44 #include "typeInfo.H"
45 #include "Field.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 // Forward declaration of friend functions and operators
54 template<class Type> class Function2;
55 template<class Type> Ostream& operator<<(Ostream&, const Function2<Type>&);
56 
57 /*---------------------------------------------------------------------------*\
58  Class Function2 Declaration
59 \*---------------------------------------------------------------------------*/
60 
61 template<class Type>
62 class Function2
63 :
64  public tmp<Function2<Type>>::refCount
65 {
66 
67 protected:
68 
69  // Protected data
70 
71  //- Name of entry
72  const word name_;
73 
74 
75 public:
76 
77  typedef Type returnType;
78 
79  //- Runtime type information
80  TypeName("Function2");
81 
82  //- Declare runtime constructor selection table
84  (
85  autoPtr,
86  Function2,
87  dictionary,
88  (
89  const word& name,
90  const dictionary& dict
91  ),
92  (name, dict)
93  );
94 
95 
96  // Constructors
97 
98  //- Construct from name
99  Function2(const word& name);
100 
101  //- Copy constructor
102  Function2(const Function2<Type>& f1);
103 
104  //- Construct and return a clone
105  virtual tmp<Function2<Type>> clone() const = 0;
106 
107 
108  //- Selector
110  (
111  const word& name,
112  const dictionary& dict
113  );
114 
115 
116  //- Destructor
117  virtual ~Function2();
118 
119 
120  // Member Functions
121 
122  //- Return the name of the entry
123  const word& name() const;
124 
125  //- Return value as a function of two scalars
126  virtual Type value(const scalar x, const scalar y) const = 0;
127 
128  //- Return value as a function of two scalar fields
129  virtual tmp<Field<Type>> value
130  (
131  const scalarField& x,
132  const scalarField& y
133  ) const = 0;
134 
135  //- Write in dictionary format
136  virtual void write(Ostream& os) const = 0;
137 
138 
139  // Member Operators
140 
141  //- Assignment
142  void operator=(const Function2<Type>&);
143 
144 
145  // IOstream Operators
146 
147  //- Ostream Operator
148  friend Ostream& operator<< <Type>
149  (
150  Ostream& os,
151  const Function2<Type>& func
152  );
153 };
154 
155 
156 template<class Type>
157 void writeEntry(Ostream& os, const Function2<Type>& f1);
158 
159 
160 /*---------------------------------------------------------------------------*\
161  Class FieldFunction2 Declaration
162 \*---------------------------------------------------------------------------*/
163 
164 template<class Type, class Function2Type>
165 class FieldFunction2
166 :
167  public Function2<Type>
168 {
169 
170 public:
171 
172  // Constructors
173 
174  //- Construct from name
175  FieldFunction2(const word& name);
176 
177  //- Construct and return a clone
178  virtual tmp<Function2<Type>> clone() const;
179 
180 
181  //- Destructor
182  virtual ~FieldFunction2();
183 
184 
185  // Member Functions
186 
187  //- Return value as a function of two scalars
188  virtual Type value(const scalar x, const scalar y) const = 0;
189 
190  //- Return value as a function of two scalar fields
191  virtual tmp<Field<Type>> value
192  (
193  const scalarField& x,
194  const scalarField& y
195  ) const;
196 };
197 
198 
199 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
200 
201 } // End namespace Foam
202 
203 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
204 
205 #define makeFunction2(Type) \
206  \
207  defineNamedTemplateTypeNameAndDebug(Function2<Type>, 0); \
208  defineTemplateRunTimeSelectionTable(Function2<Type>, dictionary);
209 
210 
211 #define makeFunction2Type(SS, Type) \
212  \
213  defineNamedTemplateTypeNameAndDebug(SS<Type>, 0); \
214  typedef Function2<Type> Type##Function2; \
215  typedef SS<Type> Type##SS##Function2; \
216  addToRunTimeSelectionTable \
217  ( \
218  Type##Function2, \
219  Type##SS##Function2, \
220  dictionary \
221  )
222 
223 
224 #define makeScalarFunction2(SS) \
225  \
226  defineTypeNameAndDebug(SS, 0); \
227  typedef Function2<scalar> scalarFunction2; \
228  addToRunTimeSelectionTable(scalarFunction2, SS, dictionary)
229 
230 
231 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
232 
233 #ifdef NoRepository
234  #include "Function2.C"
235  #include "Constant2.H"
236 #endif
237 
238 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
239 
240 #endif
241 
242 // ************************************************************************* //
scalar y
Macros for easy insertion into run-time selection tables.
virtual tmp< Function2< Type > > clone() const
Construct and return a clone.
Definition: Function2.C:57
FieldFunction2(const word &name)
Construct from name.
Definition: Function2.C:47
virtual ~FieldFunction2()
Destructor.
Definition: Function2.C:74
virtual Type value(const scalar x, const scalar y) const =0
Return value as a function of two scalars.
Run-time selectable function of two variables.
Definition: Function2.H:64
static autoPtr< Function2< Type > > New(const word &name, const dictionary &dict)
Selector.
Definition: Function2New.C:32
declareRunTimeSelectionTable(autoPtr, Function2, dictionary,(const word &name, const dictionary &dict),(name, dict))
Declare runtime constructor selection table.
virtual tmp< Function2< Type > > clone() const =0
Construct and return a clone.
virtual ~Function2()
Destructor.
Definition: Function2.C:69
Function2(const word &name)
Construct from name.
Definition: Function2.C:31
void operator=(const Function2< Type > &)
Assignment.
Definition: Function2.C:109
const word & name() const
Return the name of the entry.
Definition: Function2.C:81
TypeName("Function2")
Runtime type information.
virtual Type value(const scalar x, const scalar y) const =0
Return value as a function of two scalars.
virtual void write(Ostream &os) const =0
Write in dictionary format.
const word name_
Name of entry.
Definition: Function2.H:71
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
Reference counter for various OpenFOAM components.
Definition: refCount.H:50
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
void func(FieldField< Field, Type > &f, const FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
Ostream & operator<<(Ostream &, const ensightPart &)
dictionary dict