codedFunctionObject.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2015 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 Group
28  grpUtilitiesFunctionObjects
29 
30 Description
31  This function object provides a general interface to enable dynamic code
32  compilation.
33 
34  The entries are
35  code : c++; upon functionObject::write()
36  codeInclude : include files
37  codeOptions : include paths; inserted into EXE_INC in Make/options
38  codeLibs : link line; inserted into LIB_LIBS in Make/options
39 
40  codeExecute : c++;upon functionObject::execute();
41  codeRead : c++; upon functionObject::read();
42  codeEnd : c++; upon functionObject::end();
43  codeData : c++; local member data (null constructed);
44  codeTimeSet : c++; upon functionObject::timeSet();
45  localCode : c++; local static functions
46 
47  Example of function object specification:
48  \verbatim
49  difference
50  {
51  functionObjectLibs ("libutilityFunctionObjects.so");
52 
53  type coded;
54  // Name of on-the-fly generated functionObject
55  redirectType writeMagU;
56  code
57  #{
58  // Lookup U
59  const volVectorField& U = mesh().lookupObject<volVectorField>("U");
60  // Write
61  mag(U).write();
62  }
63  }
64  \endverbatim
65 
66 
67 SeeAlso
68  Foam::functionObject
69  Foam::OutputFilterFunctionObject
70  Foam::codedBase
71 
72 SourceFiles
73  codedFunctionObject.C
74 
75 \*---------------------------------------------------------------------------*/
76 
77 #ifndef codedFunctionObject_H
78 #define codedFunctionObject_H
79 
80 #include "functionObject.H"
81 #include "codedBase.H"
82 
83 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
84 
85 namespace Foam
86 {
87 
88 /*---------------------------------------------------------------------------*\
89  Class codedFunctionObject Declaration
90 \*---------------------------------------------------------------------------*/
91 
93 :
94  public functionObject,
95  public codedBase
96 {
97 protected:
98 
99  // Protected data
100 
101  //- Reference to the time database
102  const Time& time_;
103 
104  //- Input dictionary
106 
108 
109  string codeData_;
110  string codeRead_;
111  string codeExecute_;
112  string codeEnd_;
113  string codeTimeSet_;
114 
115  //- Underlying functionObject
117 
118 
119  // Protected Member Functions
120 
121  //- Get the loaded dynamic libraries
122  virtual dlLibraryTable& libs() const;
123 
124  //- Adapt the context for the current object
125  virtual void prepare(dynamicCode &,const dynamicCodeContext&) const;
126 
127  // Return a description (type + name) for the output
128  virtual string description() const;
129 
130  // Clear any redirected objects
131  virtual void clearRedirect() const;
132 
133  // Get the dictionary to initialize the codeContext
134  virtual const dictionary& codeDict() const;
135 
136 
137 private:
138 
139  //- Disallow default bitwise copy construct
141 
142  //- Disallow default bitwise assignment
143  void operator=(const codedFunctionObject&);
144 
145 
146 public:
147 
148  //- Runtime type information
149  TypeName("coded");
150 
151 
152  // Constructors
153 
154  //- Construct for given objectRegistry and dictionary.
155  // Allow the possibility to load fields from files
157  (
158  const word& name,
159  const Time& time,
160  const dictionary& dict,
161  bool readNow=true // allow child-classes to avoid compilation
162  );
163 
164 
165  //- Destructor
166  virtual ~codedFunctionObject();
167 
168 
169  // Member Functions
170 
171  //- Dynamically compiled functionObject
173 
174  //- Called at the start of the time-loop
175  virtual bool start();
176 
177  //- Called at each ++ or += of the time-loop. forceWrite overrides the
178  // outputControl behaviour.
179  virtual bool execute(const bool forceWrite);
180 
181  //- Called when Time::run() determines that the time-loop exits.
182  // By default it simply calls execute().
183  virtual bool end();
184 
185  //- Called when time was set at the end of the Time::operator++
186  virtual bool timeSet();
187 
188  //- Read and set the function object if its data have changed
189  virtual bool read(const dictionary&);
190 
191  //- Update mesh
192  virtual void updateMesh(const mapPolyMesh&);
193 
194  //- Move points
195  virtual void movePoints(const polyMesh&);
196 };
197 
198 
199 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
200 
201 } // End namespace Foam
202 
203 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
204 
205 #endif
206 
207 // ************************************************************************* //
Foam::codedFunctionObject::timeSet
virtual bool timeSet()
Called when time was set at the end of the Time::operator++.
Definition: codedFunctionObject.C:191
Foam::codedFunctionObject::prepare
virtual void prepare(dynamicCode &, const dynamicCodeContext &) const
Adapt the context for the current object.
Definition: codedFunctionObject.C:53
Foam::codedFunctionObject::description
virtual string description() const
Definition: codedFunctionObject.C:103
Foam::dlLibraryTable
A table of dynamically loaded libraries.
Definition: dlLibraryTable.H:49
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::dynamicCode
Tools for handling dynamic code compilation.
Definition: dynamicCode.H:56
Foam::codedFunctionObject::codeDict
virtual const dictionary & codeDict() const
Definition: codedFunctionObject.C:115
Foam::codedFunctionObject::TypeName
TypeName("coded")
Runtime type information.
Foam::codedFunctionObject::libs
virtual dlLibraryTable & libs() const
Get the loaded dynamic libraries.
Definition: codedFunctionObject.C:97
Foam::codedFunctionObject::codeData_
string codeData_
Definition: codedFunctionObject.H:108
Foam::codedFunctionObject::codeExecute_
string codeExecute_
Definition: codedFunctionObject.H:110
Foam::dynamicCodeContext
Encapsulation of dynamic code dictionaries.
Definition: dynamicCodeContext.H:49
Foam::codedBase
Base class for function objects and boundary conditions using dynamic code.
Definition: codedBase.H:53
Foam::codedFunctionObject
This function object provides a general interface to enable dynamic code compilation.
Definition: codedFunctionObject.H:91
Foam::codedFunctionObject::redirectFunctionObject
functionObject & redirectFunctionObject() const
Dynamically compiled functionObject.
Definition: codedFunctionObject.C:152
Foam::codedFunctionObject::read
virtual bool read(const dictionary &)
Read and set the function object if its data have changed.
Definition: codedFunctionObject.C:198
Foam::codedFunctionObject::codeTimeSet_
string codeTimeSet_
Definition: codedFunctionObject.H:112
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::functionObject
Abstract base-class for Time/database function objects.
Definition: functionObject.H:58
Foam::codedFunctionObject::codeRead_
string codeRead_
Definition: codedFunctionObject.H:109
Foam::codedFunctionObject::codedFunctionObject
codedFunctionObject(const codedFunctionObject &)
Disallow default bitwise copy construct.
Foam::codedFunctionObject::start
virtual bool start()
Called at the start of the time-loop.
Definition: codedFunctionObject.C:170
Foam::codedFunctionObject::~codedFunctionObject
virtual ~codedFunctionObject()
Destructor.
Definition: codedFunctionObject.C:145
Foam::codedFunctionObject::movePoints
virtual void movePoints(const polyMesh &)
Move points.
Definition: codedFunctionObject.C:301
Foam::codedFunctionObject::clearRedirect
virtual void clearRedirect() const
Definition: codedFunctionObject.C:109
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::codedFunctionObject::codeEnd_
string codeEnd_
Definition: codedFunctionObject.H:111
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::codedFunctionObject::time_
const Time & time_
Reference to the time database.
Definition: codedFunctionObject.H:101
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::codedFunctionObject::operator=
void operator=(const codedFunctionObject &)
Disallow default bitwise assignment.
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
Foam::codedFunctionObject::redirectType_
word redirectType_
Definition: codedFunctionObject.H:106
Foam::functionObject::name
virtual const word & name() const
Name.
Definition: functionObject.C:105
Foam::codedFunctionObject::execute
virtual bool execute(const bool forceWrite)
Called at each ++ or += of the time-loop. forceWrite overrides the.
Definition: codedFunctionObject.C:177
Foam::codedFunctionObject::updateMesh
virtual void updateMesh(const mapPolyMesh &)
Update mesh.
Definition: codedFunctionObject.C:297
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
codedBase.H
Foam::codedFunctionObject::redirectFunctionObjectPtr_
autoPtr< functionObject > redirectFunctionObjectPtr_
Underlying functionObject.
Definition: codedFunctionObject.H:115
Foam::codedFunctionObject::dict_
dictionary dict_
Input dictionary.
Definition: codedFunctionObject.H:104
functionObject.H
Foam::codedFunctionObject::end
virtual bool end()
Called when Time::run() determines that the time-loop exits.
Definition: codedFunctionObject.C:184