1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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.
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
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/>.
25 Foam::codedFunctionObject
28 functionObject using dynamic code compilation.
33 \*---------------------------------------------------------------------------*/
35 #ifndef codedFunctionObject_H
36 #define codedFunctionObject_H
38 #include "pointFieldFwd.H"
39 #include "functionObject.H"
40 #include "dictionary.H"
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 // Forward declaration of classes
52 class dynamicCodeContext;
55 /*---------------------------------------------------------------------------*\
56 Class codedFunctionObject Declaration
57 \*---------------------------------------------------------------------------*/
59 class codedFunctionObject
67 //- Reference to the time database
79 //- Previously loaded library
80 mutable fileName oldLibPath_;
82 //- Underlying functionObject
83 mutable autoPtr<functionObject> redirectFunctionObjectPtr_;
85 // Private Member Functions
87 //- Global loader/unloader function type
88 typedef void (*loaderFunctionType)(bool);
90 //- Load specified library and execute globalFuncName(true)
93 const fileName& libPath,
94 const string& globalFuncName,
95 const dictionary& contextDict
98 //- Execute globalFuncName(false) and unload specified library
101 const fileName& libPath,
102 const string& globalFuncName,
103 const dictionary& contextDict
107 //- Create library based on the dynamicCodeContext
108 void createLibrary(dynamicCode&, const dynamicCodeContext&) const;
110 //- Update library as required
111 void updateLibrary() const;
113 //- Read relevant dictionary entries
116 //- Disallow default bitwise copy construct
117 codedFunctionObject(const codedFunctionObject&);
119 //- Disallow default bitwise assignment
120 void operator=(const codedFunctionObject&);
125 //- Runtime type information
131 //- Construct for given objectRegistry and dictionary.
132 // Allow the possibility to load fields from files
137 const dictionary& dict
142 virtual ~codedFunctionObject();
147 //- Dynamically compiled functionObject
148 functionObject& redirectFunctionObject() const;
150 //- Called at the start of the time-loop
151 virtual bool start();
153 //- Called at each ++ or += of the time-loop. forceWrite overrides the
154 // outputControl behaviour.
155 virtual bool execute(const bool forceWrite);
157 //- Called when Time::run() determines that the time-loop exits.
158 // By default it simply calls execute().
161 //- Read and set the function object if its data have changed
162 virtual bool read(const dictionary&);
166 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
168 } // End namespace Foam
170 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
174 // ************************************************************************* //