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