codedFunctionObject.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) 2011-2019 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::codedFunctionObject
26 
27 Description
28  Provides a general interface to enable dynamic code compilation.
29 
30  The entries are:
31  \plaintable
32  codeInclude | include files
33  codeOptions | include paths; inserted into EXE_INC in Make/options
34  codeLibs | link line; inserted into LIB_LIBS in Make/options
35  codeData | c++; local member data (null constructed);
36  localCode | c++; local static functions;
37  codeRead | c++; upon functionObject::read();
38  codeExecute | c++; upon functionObject::execute();
39  codeWrite | c++; upon functionObject::write()
40  codeEnd | c++; upon functionObject::end();
41  \endplaintable
42 
43  Example of function object specification:
44  \verbatim
45  difference
46  {
47  libs ("libutilityFunctionObjects.so");
48 
49  type coded;
50  // Name of on-the-fly generated functionObject
51  name writeMagU;
52  codeWrite
53  #{
54  // Lookup U
55  const volVectorField& U = mesh().lookupObject<volVectorField>("U");
56  // Write
57  mag(U)().write();
58  #};
59  }
60  \endverbatim
61 
62 See also
63  Foam::functionObject
64  Foam::codedBase
65 
66 SourceFiles
67  codedFunctionObject.C
68 
69 \*---------------------------------------------------------------------------*/
70 
71 #ifndef functionObjects_codedFunctionObject_H
72 #define functionObjects_codedFunctionObject_H
73 
74 #include "functionObject.H"
75 #include "codedBase.H"
76 
77 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
78 
79 namespace Foam
80 {
81 
82 /*---------------------------------------------------------------------------*\
83  Class codedFunctionObject Declaration
84 \*---------------------------------------------------------------------------*/
85 
86 class codedFunctionObject
87 :
88  public functionObject,
89  public codedBase
90 {
91 protected:
92 
93  // Protected static data
94 
95  //- The keywords associated with source code
96  static const wordList codeKeys_;
97 
98 
99  // Protected data
100 
101  //- Reference to the time database
102  const Time& time_;
103 
104  //- Input dictionary
105  dictionary dict_;
106 
107  //- The name
108  word name_;
109 
110  //- Underlying functionObject
111  mutable autoPtr<functionObject> redirectFunctionObjectPtr_;
112 
113 
114  // Protected Member Functions
115 
116  //- Get the loaded dynamic libraries
117  virtual dlLibraryTable& libs() const;
118 
119  //- Adapt the context for the current object
120  virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
122  //- Return a description (type + name) for the output
123  virtual string description() const;
124 
125  //- Clear any redirected objects
126  virtual void clearRedirect() const;
127 
128  //- Get the dictionary to initialize the codeContext
129  virtual const dictionary& codeDict() const;
130 
131  //- Get the keywords associated with source code
132  virtual const wordList& codeKeys() const;
133 
134 
135 public:
136 
137  //- Runtime type information
138  TypeName("coded");
139 
141  // Constructors
142 
143  //- Construct from Time and dictionary
145  (
146  const word& name,
147  const Time& time,
148  const dictionary& dict
149  );
150 
151  //- Disallow default bitwise copy construction
152  codedFunctionObject(const codedFunctionObject&) = delete;
153 
154 
155  //- Destructor
156  virtual ~codedFunctionObject();
157 
158 
159  // Member Functions
160 
161  //- Dynamically compiled functionObject
163 
164  //- Called at each ++ or += of the time-loop.
165  // postProcess overrides the usual executeControl behaviour and
166  // forces execution (used in post-processing mode)
167  virtual bool execute();
168 
169  //- Called at each ++ or += of the time-loop.
170  // postProcess overrides the usual writeControl behaviour and
171  // forces writing always (used in post-processing mode)
172  virtual bool write();
173 
174  //- Called when Time::run() determines that the time-loop exits.
175  // By default it simply calls execute().
176  virtual bool end();
177 
178  //- Read and set the function object if its data have changed
179  virtual bool read(const dictionary&);
180 
181 
182  // Member Operators
183 
184  //- Disallow default bitwise assignment
185  void operator=(const codedFunctionObject&) = delete;
186 };
187 
188 
189 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
190 
191 } // End namespace Foam
192 
193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
194 
195 #endif
196 
197 // ************************************************************************* //
functionObject & redirectFunctionObject() const
Dynamically compiled functionObject.
dictionary dict
virtual bool read(const dictionary &)
Read and set the function object if its data have changed.
const word & name() const
Return the name of this functionObject.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
const Time & time_
Reference to the time database.
codedFunctionObject(const word &name, const Time &time, const dictionary &dict)
Construct from Time and dictionary.
virtual void clearRedirect() const
Clear any redirected objects.
virtual const wordList & codeKeys() const
Get the keywords associated with source code.
void operator=(const codedFunctionObject &)=delete
Disallow default bitwise assignment.
Abstract base-class for Time/database function objects.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
autoPtr< functionObject > redirectFunctionObjectPtr_
Underlying functionObject.
virtual const dictionary & codeDict() const
Get the dictionary to initialize the codeContext.
virtual dlLibraryTable & libs() const
Get the loaded dynamic libraries.
virtual void prepare(dynamicCode &, const dynamicCodeContext &) const
Adapt the context for the current object.
Provides a general interface to enable dynamic code compilation.
A class for handling words, derived from string.
Definition: word.H:59
virtual bool end()
Called when Time::run() determines that the time-loop exits.
static const wordList codeKeys_
The keywords associated with source code.
virtual ~codedFunctionObject()
Destructor.
List< word > wordList
A List of words.
Definition: fileName.H:54
TypeName("coded")
Runtime type information.
dictionary dict_
Input dictionary.
virtual bool execute()
Called at each ++ or += of the time-loop.
virtual bool write()
Called at each ++ or += of the time-loop.
virtual string description() const
Return a description (type + name) for the output.
Namespace for OpenFOAM.