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