All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 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 class coded
85 {
86 public:
87 
88  ClassNameNoDebug("Function1");
89 };
90 
91 
92 /*---------------------------------------------------------------------------*\
93  Class Coded Declaration
94 \*---------------------------------------------------------------------------*/
95 
96 template<class Type>
97 class Coded
98 :
99  public Function1<Type>,
100  public CodedBase<coded>
101 {
102  // Private Data
103 
104  //- The dynamically generated Function1 pointer
105  mutable autoPtr<Function1<Type>> redirectFunction1Ptr_;
106 
107 
108  // Private Member Functions
109 
110  //- Adapt the context for the current object
111  virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
112 
113  //- Clear the ptr to the redirected object
114  virtual void clearRedirect() const;
115 
116  //- Compile, link and return the now coded Function1
117  autoPtr<Function1<Type>> compileNew();
118 
119 
120 public:
121 
122  // Runtime type information
123  TypeName("coded");
124 
125 
126  // Constructors
127 
128  //- Construct from entry name and dictionary
129  Coded
130  (
131  const word& entryName,
132  const dictionary& dict
133  );
134 
135  //- Copy constructor
136  Coded(const Coded<Type>& cf1);
137 
138  //- Construct and return a clone
139  virtual tmp<Function1<Type>> clone() const;
140 
141 
142  //- Destructor
143  virtual ~Coded();
144 
145 
146  // Member Functions
147 
148  //- Return value
149  virtual inline Type value(const scalar x) const;
150 
151  //- Return value as a function of (scalar) independent variable
152  virtual tmp<Field<Type>> value(const scalarField& x) const;
153 
154  //- Integrate between two values
155  virtual Type integrate(const scalar x1, const scalar x2) const;
156 
157  //- Integrate between two (scalar) values
158  virtual tmp<Field<Type>> integrate
159  (
160  const scalarField& x1,
161  const scalarField& x2
162  ) const;
163 
164  //- Write in dictionary format
165  virtual void writeData(Ostream& os) const;
166 
167 
168  // Member Operators
169 
170  //- Disallow default bitwise assignment
171  void operator=(const Coded<Type>&) = delete;
172 };
173 
174 
175 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
176 
177 } // End namespace Function1s
178 } // End namespace Foam
179 
180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
181 
182 #include "CodedFunction1I.H"
183 
184 #ifdef NoRepository
185  #include "CodedFunction1.C"
186 #endif
187 
188 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
189 
190 #endif
191 
192 // ************************************************************************* //
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: Function1.H:52
dictionary dict
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
Constructs a dynamically compiled Function1.
T clone(const T &t)
Definition: List.H:54
A class for handling words, derived from string.
Definition: word.H:59
Templated wrapper class to reduce code duplication and simplify maintenance of coded classes...
Definition: CodedBase.H:49
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:70
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
const bool writeData(readBool(pdfDictionary.lookup("writeData")))
Tools for handling dynamic code compilation.
Definition: dynamicCode.H:56
Encapsulation of dynamic code dictionaries.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
ClassNameNoDebug("Function1")
A class for managing temporary objects.
Definition: PtrList.H:53
Namespace for OpenFOAM.