CodedFunction1.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::Function1s::Coded
26 
27 Description
28  Constructs a dynamically compiled Function1.
29 
30 Usage
31  Example of a cosine bell shaped pulse inlet:
32  \verbatim
33  inlet
34  {
35  type uniformFixedValue;
36  uniformValue coded;
37 
38  name pulse;
39 
40  codeInclude
41  #{
42  #include "mathematicalConstants.H"
43  #};
44 
45  code
46  #{
47  return vector
48  (
49  0.5*(1 - cos(constant::mathematical::twoPi*min(x/0.3, 1))),
50  0,
51  0
52  );
53  #};
54  }
55  \endverbatim
56 
57 See also
58  Foam::dynamicCode
59  Foam::functionEntries::codeStream
60 
61 SourceFiles
62  CodedFunction1I.H
63  CodedFunction1.C
64 
65 \*---------------------------------------------------------------------------*/
66 
67 #ifndef CodedFunction1_H
68 #define CodedFunction1_H
69 
70 #include "Function1.H"
71 #include "codedBase.H"
72 
73 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
74 
75 namespace Foam
76 {
77 namespace Function1s
78 {
79 
80 /*---------------------------------------------------------------------------*\
81  Class Coded Declaration
82 \*---------------------------------------------------------------------------*/
83 
84 template<class Type>
85 class Coded
86 :
87  public Function1<Type>,
88  public codedBase
89 {
90  // Private Data
91 
92  //- Keywords associated with source code
93  static const wordList codeKeys;
94 
95  //- Name of the dictionary variables in the source code
96  static const wordList codeDictVars;
97 
98  //- Cache of the unit conversions
99  const unitConversions units_;
100 
101  //- The dynamically generated Function1 pointer
102  mutable autoPtr<Function1<Type>> redirectFunction1Ptr_;
103 
104 
105  // Private Member Functions
106 
107  //- Adapt the context for the current object
108  virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
109 
110 
111 public:
112 
113  // Runtime type information
114  TypeName("coded");
115 
116 
117  // Constructors
118 
119  //- Construct from name and dictionary
120  Coded
121  (
122  const word& name,
124  const dictionary& dict
125  );
126 
127  //- Copy constructor
128  Coded(const Coded<Type>& cf1);
129 
130  //- Construct and return a clone
131  virtual tmp<Function1<Type>> clone() const;
132 
133 
134  //- Destructor
135  virtual ~Coded();
136 
137 
138  // Member Functions
139 
140  //- Return value as a function of a scalar
141  virtual inline Type value(const scalar x) const;
142 
143  //- Return value as a function of a scalar field
144  virtual tmp<Field<Type>> value(const scalarField& x) const;
145 
146  //- Integrate between two scalars
147  virtual Type integral(const scalar x1, const scalar x2) const;
148 
149  //- Integrate between two scalar fields
150  virtual tmp<Field<Type>> integral
151  (
152  const scalarField& x1,
153  const scalarField& x2
154  ) const;
155 
156  //- Write data to dictionary stream
157  virtual void write(Ostream& os, const unitConversions& units) const;
158 
159 
160  // Member Operators
161 
162  //- Disallow default bitwise assignment
163  void operator=(const Coded<Type>&) = delete;
164 };
165 
166 
167 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
168 
169 } // End namespace Function1s
170 } // End namespace Foam
171 
172 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
173 
174 #include "CodedFunction1I.H"
175 
176 #ifdef NoRepository
177  #include "CodedFunction1.C"
178 #endif
179 
180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
181 
182 #endif
183 
184 // ************************************************************************* //
Run-time selectable general function of one variable.
Definition: Function1.H:125
const word & name() const
Return the name of the entry.
Definition: Function1.C:78
Constructs a dynamically compiled Function1.
virtual Type integral(const scalar x1, const scalar x2) const
Integrate between two scalars.
virtual void write(Ostream &os, const unitConversions &units) const
Write data to dictionary stream.
virtual ~Coded()
Destructor.
virtual Type value(const scalar x) const
Return value as a function of a scalar.
virtual tmp< Function1< Type > > clone() const
Construct and return a clone.
void operator=(const Coded< Type > &)=delete
Disallow default bitwise assignment.
Coded(const word &name, const Function1s::unitConversions &units, const dictionary &dict)
Construct from name and dictionary.
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