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  //- Keywords associated with source code
78  static const wordList codeKeys;
79 
80  //- Name of the dictionary variables in the source code
81  static const wordList codeDictVars;
82 
83  //- Cache of the unit conversions
84  const unitConversions units_;
85 
86  //- The dynamically generated Function2 pointer
87  mutable autoPtr<Function2<Type>> redirectFunction2Ptr_;
88 
89 
90  // Private Member Functions
91 
92  //- Adapt the context for the current object
93  virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
94 
95 
96 public:
97 
98  // Runtime type information
99  TypeName("coded");
100 
101 
102  // Constructors
103 
104  //- Construct from name and dictionary
105  Coded
106  (
107  const word& name,
108  const unitConversions& units,
109  const dictionary& dict
110  );
111 
112  //- Copy constructor
113  Coded(const Coded<Type>& cf1);
114 
115  //- Construct and return a clone
116  virtual tmp<Function2<Type>> clone() const;
117 
118 
119  //- Destructor
120  virtual ~Coded();
121 
122 
123  // Member Functions
124 
125  //- Return value as a function of two scalars
126  virtual inline Type value(const scalar x, const scalar y) const;
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;
134 
135  //- Write data to dictionary stream
136  virtual void write(Ostream& os, const unitConversions& units) const;
137 
138 
139  // Member Operators
140 
141  //- Disallow default bitwise assignment
142  void operator=(const Coded<Type>&) = delete;
143 };
144 
145 
146 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
147 
148 } // End namespace Function2s
149 } // End namespace Foam
150 
151 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
152 
153 #include "CodedFunction2I.H"
154 
155 #ifdef NoRepository
156  #include "CodedFunction2.C"
157 #endif
158 
159 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160 
161 #endif
162 
163 // ************************************************************************* //
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:52
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
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