Merge branch 'master' of github.com:OpenFOAM/OpenFOAM-2.0.x
[OpenFOAM-2.0.x.git] / src / postProcessing / functionObjects / utilities / codedFunctionObject / codedFunctionObject.H
blobc950ea2ab6fce7850d7a63ef9f0bb2731377fd59
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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/>.
24 Class
25     Foam::codedFunctionObject
27 Description
28     functionObject using dynamic code compilation.
30 SourceFiles
31     codedFunctionObject.C
33 \*---------------------------------------------------------------------------*/
35 #ifndef codedFunctionObject_H
36 #define codedFunctionObject_H
38 #include "pointFieldFwd.H"
39 #include "functionObject.H"
40 #include "dictionary.H"
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 namespace Foam
47 // Forward declaration of classes
48 class objectRegistry;
49 class dictionary;
50 class mapPolyMesh;
51 class dynamicCode;
52 class dynamicCodeContext;
53 class IOdictionary;
55 /*---------------------------------------------------------------------------*\
56                        Class codedFunctionObject Declaration
57 \*---------------------------------------------------------------------------*/
59 class codedFunctionObject
61     public functionObject
63 protected:
65     // Protected data
67         //- Reference to the time database
68         const Time& time_;
70         //- Input dictionary
71         dictionary dict_;
73         word redirectType_;
75         string codeRead_;
76         string codeExecute_;
77         string codeEnd_;
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)
91         void* loadLibrary
92         (
93             const fileName& libPath,
94             const string& globalFuncName,
95             const dictionary& contextDict
96         ) const;
98         //- Execute globalFuncName(false) and unload specified library
99         void unloadLibrary
100         (
101             const fileName& libPath,
102             const string& globalFuncName,
103             const dictionary& contextDict
104         ) const;
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
114         void readDict();
116         //- Disallow default bitwise copy construct
117         codedFunctionObject(const codedFunctionObject&);
119         //- Disallow default bitwise assignment
120         void operator=(const codedFunctionObject&);
123 public:
125     //- Runtime type information
126     TypeName("coded");
129     // Constructors
131         //- Construct for given objectRegistry and dictionary.
132         //  Allow the possibility to load fields from files
133         codedFunctionObject
134         (
135             const word& name,
136             const Time& time,
137             const dictionary& dict
138         );
141     //- Destructor
142     virtual ~codedFunctionObject();
145     // Member Functions
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().
159         virtual bool end();
161         //- Read and set the function object if its data have changed
162         virtual bool read(const dictionary&);
166 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
168 } // End namespace Foam
170 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
172 #endif
174 // ************************************************************************* //