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-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::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  writeMagU
46  {
47  libs ("libutilityFunctionObjects.so");
48 
49  type coded;
50 
51  codeWrite
52  #{
53  // Lookup U
54  const volVectorField& U = mesh().lookupObject<volVectorField>("U");
55  // Write
56  mag(U)().write();
57  #};
58  }
59  \endverbatim
60 
61 See also
62  Foam::functionObject
63  Foam::codedBase
64 
65 SourceFiles
66  codedFunctionObject.C
67 
68 \*---------------------------------------------------------------------------*/
69 
70 #ifndef functionObjects_codedFunctionObject_H
71 #define functionObjects_codedFunctionObject_H
72 
73 #include "functionObject.H"
74 #include "codedBase.H"
75 
76 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
77 
78 namespace Foam
79 {
80 
81 /*---------------------------------------------------------------------------*\
82  Class codedFunctionObject Declaration
83 \*---------------------------------------------------------------------------*/
84 
85 class codedFunctionObject
86 :
87  public functionObject,
88  public codedBase
89 {
90  // Private Data
91 
92  //- Reference to the time database
93  const Time& time_;
94 
95  //- The dynamically generated functionObject pointer
96  mutable autoPtr<functionObject> redirectFunctionObjectPtr_;
97 
98 
99  // Private Member Functions
100 
101  //- Get the keywords associated with source code
102  virtual wordList codeKeys() const;
103 
104  //- Adapt the context for the current object
105  virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
106 
107  //- Clear any redirected objects
108  virtual void clearRedirect() const;
109 
110  //- Compile, link and return the now coded functionObject
111  functionObject& redirectFunctionObject() const;
112 
113 
114 public:
115 
116  //- Runtime type information
117  TypeName("coded");
118 
119 
120  // Constructors
121 
122  //- Construct from Time and dictionary
124  (
125  const word& name,
126  const Time& time,
127  const dictionary& dict
128  );
129 
130  //- Disallow default bitwise copy construction
131  codedFunctionObject(const codedFunctionObject&) = delete;
132 
133 
134  //- Destructor
135  virtual ~codedFunctionObject();
136 
137 
138  // Member Functions
139 
140  //- Called at each ++ or += of the time-loop.
141  // postProcess overrides the usual executeControl behaviour and
142  // forces execution (used in post-processing mode)
143  virtual bool execute();
144 
145  //- Called at each ++ or += of the time-loop.
146  // postProcess overrides the usual writeControl behaviour and
147  // forces writing always (used in post-processing mode)
148  virtual bool write();
149 
150  //- Called when Time::run() determines that the time-loop exits.
151  // By default it simply calls execute().
152  virtual bool end();
153 
154  //- Read and set the function object if its data have changed
155  virtual bool read(const dictionary&);
156 
157 
158  // Member Operators
159 
160  //- Disallow default bitwise assignment
161  void operator=(const codedFunctionObject&) = delete;
162 };
163 
164 
165 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
166 
167 } // End namespace Foam
168 
169 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
170 
171 #endif
172 
173 // ************************************************************************* //
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:156
codedFunctionObject(const word &name, const Time &time, const dictionary &dict)
Construct from Time and dictionary.
void operator=(const codedFunctionObject &)=delete
Disallow default bitwise assignment.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
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.
functionObject(const word &name)
Construct from components.
virtual ~codedFunctionObject()
Destructor.
List< word > wordList
A List of words.
Definition: fileName.H:54
TypeName("coded")
Runtime type information.
virtual bool execute()
Called at each ++ or += of the time-loop.
virtual bool write()
Called at each ++ or += of the time-loop.
Namespace for OpenFOAM.