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-2021 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  //- The dynamically generated Function1 pointer
93  mutable autoPtr<Function1<Type>> redirectFunction1Ptr_;
94 
95 
96  // Private Member Functions
97 
98  //- Get the keywords associated with source code
99  virtual wordList codeKeys() const;
100 
101  //- Adapt the context for the current object
102  virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
103 
104  //- Clear the ptr to the redirected object
105  virtual void clearRedirect() const;
106 
107  //- Compile, link and return the now coded Function1
108  autoPtr<Function1<Type>> compileNew();
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,
123  const dictionary& dict
124  );
125 
126  //- Copy constructor
127  Coded(const Coded<Type>& cf1);
128 
129  //- Construct and return a clone
130  virtual tmp<Function1<Type>> clone() const;
131 
132 
133  //- Destructor
134  virtual ~Coded();
135 
136 
137  // Member Functions
138 
139  //- Return value as a function of a scalar
140  virtual inline Type value(const scalar x) const;
141 
142  //- Return value as a function of a scalar field
143  virtual tmp<Field<Type>> value(const scalarField& x) const;
144 
145  //- Integrate between two scalars
146  virtual Type integral(const scalar x1, const scalar x2) const;
147 
148  //- Integrate between two scalar fields
149  virtual tmp<Field<Type>> integral
150  (
151  const scalarField& x1,
152  const scalarField& x2
153  ) const;
154 
155  //- Write data to dictionary stream
156  virtual void write(Ostream& os) const;
157 
158 
159  // Member Operators
160 
161  //- Disallow default bitwise assignment
162  void operator=(const Coded<Type>&) = delete;
163 };
164 
165 
166 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
167 
168 } // End namespace Function1s
169 } // End namespace Foam
170 
171 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
172 
173 #include "CodedFunction1I.H"
174 
175 #ifdef NoRepository
176  #include "CodedFunction1.C"
177 #endif
178 
179 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
180 
181 #endif
182 
183 // ************************************************************************* //
Run-time selectable general function of one variable.
Definition: Function1.H:64
const word & name() const
Return the name of the entry.
Definition: Function1.C:82
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
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.
Coded(const word &name, const dictionary &dict)
Construct from name and dictionary.
void operator=(const Coded< Type > &)=delete
Disallow default bitwise assignment.
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:160
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.
dictionary dict