All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CodedFunction2.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-2024 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::Function2s::Coded
26 
27 Description
28  Constructs a dynamically compiled function of two variables.
29 
30 See also
31  Foam::dynamicCode
32  Foam::functionEntries::codeStream
33 
34 SourceFiles
35  CodedFunction2I.H
36  CodedFunction2.C
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #ifndef CodedFunction2_H
41 #define CodedFunction2_H
42 
43 #include "Function2.H"
44 #include "codedBase.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 namespace Function2s
51 {
52 
53 /*---------------------------------------------------------------------------*\
54  Class coded Declaration
55 \*---------------------------------------------------------------------------*/
56 
57 class coded
58 {
59 public:
60 
61  ClassNameNoDebug("Function2");
62 };
63 
64 
65 /*---------------------------------------------------------------------------*\
66  Class Coded Declaration
67 \*---------------------------------------------------------------------------*/
68 
69 template<class Type>
70 class Coded
71 :
72  public Function2<Type>,
73  public codedBase
74 {
75  // Private Data
76 
77  //- The dynamically generated Function2 pointer
78  mutable autoPtr<Function2<Type>> redirectFunction2Ptr_;
79 
80  //- Cache of the unit conversions
81  const unitConversions units_;
82 
83 
84  // Private Member Functions
85 
86  //- Get the keywords associated with source code
87  virtual wordList codeKeys() const;
88 
89  //- Get the name of the dictionary variables in the source code
90  virtual wordList codeDictVars() const;
91 
92  //- Adapt the context for the current object
93  virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
94 
95  //- Clear the ptr to the redirected object
96  virtual void clearRedirect() const;
97 
98  //- Compile, link and return the now coded Function2
99  autoPtr<Function2<Type>> compileNew();
100 
101 
102 public:
103 
104  // Runtime type information
105  TypeName("coded");
106 
107 
108  // Constructors
109 
110  //- Construct from name and dictionary
111  Coded
112  (
113  const word& name,
114  const unitConversions& units,
115  const dictionary& dict
116  );
117 
118  //- Copy constructor
119  Coded(const Coded<Type>& cf1);
120 
121  //- Construct and return a clone
122  virtual tmp<Function2<Type>> clone() const;
123 
124 
125  //- Destructor
126  virtual ~Coded();
127 
128 
129  // Member Functions
130 
131  //- Return value as a function of two scalars
132  virtual inline Type value(const scalar x, const scalar y) const;
133 
134  //- Return value as a function of two scalar fields
135  virtual tmp<Field<Type>> value
136  (
137  const scalarField& x,
138  const scalarField& y
139  ) const;
140 
141  //- Write data to dictionary stream
142  virtual void write(Ostream& os, const unitConversions& units) const;
143 
144 
145  // Member Operators
146 
147  //- Disallow default bitwise assignment
148  void operator=(const Coded<Type>&) = delete;
149 };
150 
151 
152 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
153 
154 } // End namespace Function2s
155 } // End namespace Foam
156 
157 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
158 
159 #include "CodedFunction2I.H"
160 
161 #ifdef NoRepository
162  #include "CodedFunction2.C"
163 #endif
164 
165 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
166 
167 #endif
168 
169 // ************************************************************************* //
scalar y
Run-time selectable function of two variables.
Definition: Function2.H:98
const word & name() const
Return the name of the entry.
Definition: Function2.C:78
Constructs a dynamically compiled function of two variables.
virtual tmp< Function2< Type > > clone() const
Construct and return a clone.
virtual void write(Ostream &os, const unitConversions &units) const
Write data to dictionary stream.
Coded(const word &name, const unitConversions &units, const dictionary &dict)
Construct from name and dictionary.
virtual ~Coded()
Destructor.
virtual Type value(const scalar x, const scalar y) const
Return value as a function of two scalars.
void operator=(const Coded< Type > &)=delete
Disallow default bitwise assignment.
ClassNameNoDebug("Function2")
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
Base class for function objects and boundary conditions using dynamic code.
Definition: codedBase.H:54
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Encapsulation of dynamic code dictionaries.
Tools for handling dynamic code compilation.
Definition: dynamicCode.H:57
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.
const HashTable< unitConversion > & units()
Get the table of unit conversions.
dictionary dict