ENH: Release-notes-dev: updated for coded functionObject

This commit is contained in:
mattijs
2011-03-23 04:58:00 +00:00
parent 157d89f3de
commit 889b0a0488
4 changed files with 101 additions and 33 deletions

View File

@ -277,6 +277,26 @@
triSurfaceMesh). triSurfaceMesh).
+ =nearWallFields=: constructs field with on selected patches interpolated + =nearWallFields=: constructs field with on selected patches interpolated
internal field for further postprocessing. internal field for further postprocessing.
+ =coded=: uses the dynamic code compilation from =#codeStream=
to provide an in-line functionObject. E.g.
#+BEGIN_SRC c++
functions
(
pAverage
{
functionObjectLibs ("libutilityFunctionObjects.so");
type coded;
redirectType average;
code
#{
const volScalarField& p = obr().lookupObject<volScalarField>("p");
Info<<"p avg:" << average(p) << endl;
#};
}
);
#+END_SRC
See also [[./doc/changes/dynamicCode.org]]
* New tutorials * New tutorials
There is a large number of new tutorials for existing and new solvers in the There is a large number of new tutorials for existing and new solvers in the

View File

@ -8,7 +8,7 @@
# Copyright (c) 2011 OpenCFD Ltd. # Copyright (c) 2011 OpenCFD Ltd.
* Dictionary preprocessing directive: =#codeStream= * Dictionary preprocessing directive: =#codeStream=
This is a dictionary preprocessing directive ('=functionEntry=') which This is a dictionary preprocessing directive (=functionEntry=) which
provides a snippet of OpenFOAM C++ code which gets compiled and executed to provides a snippet of OpenFOAM C++ code which gets compiled and executed to
provide the actual dictionary entry. The snippet gets provided as three provide the actual dictionary entry. The snippet gets provided as three
sections of C++ code which just gets inserted into a template: sections of C++ code which just gets inserted into a template:
@ -17,8 +17,11 @@
=dict.lookup= to find current dictionary values. =dict.lookup= to find current dictionary values.
- optional =codeInclude= section: any #include statements to include OpenFOAM - optional =codeInclude= section: any #include statements to include OpenFOAM
files. files.
- optional 'codeOptions' section: any extra compilation flags to be added to - optional =codeOptions= section: any extra compilation flags to be added to
=EXE_INC= in =Make/options= =EXE_INC= in =Make/options=. These usually are =-I= include directory
options.
- optional =codeLibs= section: any extra compilation flags to be added to
=LIB_LIBS= in =Make/options=.
To ease inputting mulit-line code there is the =#{ #}= syntax. Anything in To ease inputting mulit-line code there is the =#{ #}= syntax. Anything in
between these two delimiters becomes a string with all newlines, quotes etc between these two delimiters becomes a string with all newlines, quotes etc
@ -27,9 +30,6 @@
Example: Look up dictionary entries and do some calculation Example: Look up dictionary entries and do some calculation
#+BEGIN_SRC c++ #+BEGIN_SRC c++
// For paraFoam's sake re-load in OpenFOAM library with exported symbols
libs ("libOpenFOAM.so");
startTime 0; startTime 0;
endTime 100; endTime 100;
.. ..
@ -47,30 +47,30 @@
* Implementation * Implementation
- the =#codeStream= entry reads the dictionary following it, extracts the - the =#codeStream= entry reads the dictionary following it, extracts the
=code=, =codeInclude=, =codeOptions= sections (these are just strings) and =code=, =codeInclude=, =codeOptions=, =codeLibs= sections (these are just strings) and
calculates the SHA1 checksum of the contents. calculates the SHA1 checksum of the contents.
- it copies a template file - it copies a template file
=(etc/codeTemplates/dynamicCode/codeStreamTemplate.C)= or =(etc/codeTemplates/dynamicCode/codeStreamTemplate.C)= or
=($FOAM_CODE_TEMPLATES/codeStreamTemplate.C)=, substituting all =($FOAM_CODE_TEMPLATES/codeStreamTemplate.C)=, substituting all
occurences of =code=, =codeInclude=, =codeOptions=. occurences of =code=, =codeInclude=, =codeOptions=, =codeLibs=.
- it writes library source files to =dynamicCode/<SHA1>= and compiles - it writes library source files to =dynamicCode/<SHA1>= and compiles
it using =wmake libso=. it using =wmake libso=.
- the resulting library is generated under - the resulting library is generated under
=dynamicCode/platforms/$WM_OPTIONS/lib= and is loaded (=dlopen=, =dlsym=) =dynamicCode/platforms/$WM_OPTIONS/lib= and is loaded (=dlopen=, =dlsym=)
and the function executed and the function executed.
- the function will have written its output into the Ostream which then gets - the function will have written its output into the Ostream which then gets
used to construct the entry to replace the whole =#codeStream= section. used to construct the entry to replace the whole =#codeStream= section.
- using the SHA1 means that same code will only be compiled and loaded once. - using the SHA1 means that same code will only be compiled and loaded once.
* Boundary condition: =codedFixedValue= * Boundary condition: =codedFixedValue=
This uses the code from codeStream to have an in-line specialised This uses the same framework as codeStream to have an in-line specialised
=fixedValueFvPatchField=. =fixedValueFvPatchField=.
#+BEGIN_SRC c++ #+BEGIN_SRC c++
outlet outlet
{ {
type codedFixedValue; type codedFixedValue;
value uniform 0; value uniform 0;
redirectType fixedValue10; redirectType ramp;
code code
#{ #{
@ -79,18 +79,16 @@
} }
#+END_SRC #+END_SRC
It by default always includes =fvCFD.H= and adds the =finiteVolume= library to It by default always includes =fvCFD.H= and adds the =finiteVolume= library to
the include search path. the include search path and the linked libraries. Any other libraries will
need
When postprocessing using paraFoam it requires one to add the used libraries to be added using the =codeInclude=, =codeLibs=, =codeOptions= section or provided through
to the libs entry so in the system/controlDict: the =libs= entry in the =system/controlDict=.
libs ("libOpenFOAM.so" "libfiniteVolume.so");
A special form is where the code is not supplied in-line but instead comes A special form is where the code is not supplied in-line but instead comes
from the =codeDict= dictionary in the =system= directory. It should contain from the =codeDict= dictionary in the =system= directory. It should contain
a =fixedValue10= entry: a =ramp= entry:
#+BEGIN_SRC c++ #+BEGIN_SRC c++
fixedValue10 ramp
{ {
code code
#{ #{
@ -99,7 +97,49 @@
} }
#+END_SRC #+END_SRC
The advantage of using this indirect way is that it supports The advantage of using this indirect way is that it supports
runTimeModifiable so any change of the code will be picked up next iteration. =runTimeModifiable= so any change of the code will be picked up next iteration.
* Function object: =coded=
This uses the same framework as codeStream to have an in-line specialised
=functionObject=.
#+BEGIN_SRC c++
functions
(
pAverage
{
functionObjectLibs ("libutilityFunctionObjects.so");
type coded;
redirectType average;
outputControl outputTime;
code
#{
const volScalarField& p = obr().lookupObject<volScalarField>("p");
Info<<"p avg:" << average(p) << endl;
#};
}
);
#+END_SRC
This dynamic code framework uses the following entries
+ =codeData=: declaration (in .H file) of local (null-constructable) data
+ =codeInclude=: (.C file) usual include section
+ =codeRead=: (.C file) executed upon dictionary read
+ =codeExecute=: (.C file) executed upon functionObject execute
+ =codeEnd=: (.C file) executed upon functionObject end
+ =code=: (.C file) executed upon functionObject write. This is the usual place
for simple functionObject.
+ =codeLibs=, =codeOptions=: usual
=coded= by default always includes =fvCFD.H= and adds the =finiteVolume= library to
the include search path and the linked libraries. Any other libraries will
need to be added explicitly (see =codeInclude=, =codeLibs=, =codeOptions= sections) or provided through
the =libs= entry in the =system/controlDict=.
=coded= is an =OutputFilter= type =functionObject= so supports the usual
+ =region=: non-default region
+ =enabled=: enable/disable
+ =outputControl=: =timeStep= or =outputTime=
+ =outputInterval=: in case of =timeStep=
entries.
* Security * Security
Allowing the case to execute C++ code does introduce security risks. A Allowing the case to execute C++ code does introduce security risks. A
@ -137,6 +177,11 @@
#{ #{
-I$(LIB_SRC)/finiteVolume/lnInclude -I$(LIB_SRC)/finiteVolume/lnInclude
#}; #};
codeLibs
#{
-lfiniteVolume
#};
}; };
#+END_SRC #+END_SRC
@ -153,7 +198,7 @@
prints 'uniform 12.34;'. Note the ';' at the end. It is advised to use the prints 'uniform 12.34;'. Note the ';' at the end. It is advised to use the
=writeEntry= as above to handle this and also e.g. binary streams (=codeStream= =writeEntry= as above to handle this and also e.g. binary streams (=codeStream=
inherits the stream type from the dictionary) inherits the stream type from the dictionary)
+ the =code=, =codeInclude=, =codeOptions= entries are just like any other + the =code=, =codeInclude=, =codeOptions=, =codeLibs= entries are just like any other
dictionary string entry so there has to be a ';' after the string dictionary string entry so there has to be a ';' after the string
+ the =#codeStream= entry (itself a dictionary) has to end in a ';' + the =#codeStream= entry (itself a dictionary) has to end in a ';'
@ -162,27 +207,25 @@
Following applications read Following applications read
the field as a dictionary, not as an =IOdictionary=: the field as a dictionary, not as an =IOdictionary=:
- =foamFormatConvert= - =foamFormatConvert=
- =changeDictionaryDict= - =changeDictionary=
- =foamUpgradeCyclics= - =foamUpgradeCyclics=
These applications will usually switch off all '#' processing which These applications will usually switch off all '#' processing which
just preserves the entries as strings (including all formatting). just preserves the entries as strings (including all
formatting). =changeDictionary= has the =-enableFunctionEntries= option for if
one does want to evaluate any preprocessing in the changeDictionaryDict.
* Other * Other
- paraFoam: paraview does not export symbols on loaded libraries - paraFoam: paraview currently does not export symbols on loaded libraries
(more specific : it does not add 'RTLD_GLOBAL' to the dlopen flags) so (more specific : it does not add 'RTLD_GLOBAL' to the dlopen flags) so
one will have to add the used libraries (libOpenFOAM, libfiniteVolume, one will have to add the used additional libraries (libfiniteVolume,
lib..) to the 'libs' entry in system/controlDict to prevent getting lib..) either to the =codeLibs= linkage section (preferred) or to the 'libs' entry in system/controlDict to prevent getting
an error of the form an error of the form
--> FOAM FATAL IO ERROR: --> FOAM FATAL IO ERROR:
Failed loading library "libcodeStream_3cd388ceb070a2f8b0ae61782adbc21c5687ce6f.so" Failed loading library "libcodeStream_3cd388ceb070a2f8b0ae61782adbc21c5687ce6f.so"
This will force re-loading By default =#codeStream= links in =libOpenFOAM= and =codedFixedValue= and =coded=
these libraries, this time exporting the symbols so the generated library functionObject link in both =libOpenFOAM= and =libfiniteVolume=.
can be loaded.
- parallel running not tested a lot. What about distributed data - parallel running not tested a lot. What about distributed data
(i.e. non-=NFS=) parallel? (i.e. non-=NFS=) parallel?
- paraview has been patched so it will pass in RTLD_GLOBAL when loading
the OpenFOAM reader module. This is necessary for above dictionary
processing to work.

View File

@ -25,7 +25,7 @@ License
#include "functionObjectTemplate.H" #include "functionObjectTemplate.H"
#include "Time.H" #include "Time.H"
//#include "pointFields.H" #include "fvCFD.H"
//{{{ begin codeInclude //{{{ begin codeInclude
${codeInclude} ${codeInclude}

View File

@ -67,6 +67,11 @@ class ${typeName}FunctionObject
// Private Member Functions // Private Member Functions
const objectRegistry& obr() const
{
return obr_;
}
//- Disallow default bitwise copy construct //- Disallow default bitwise copy construct
${typeName}FunctionObject(const ${typeName}FunctionObject&); ${typeName}FunctionObject(const ${typeName}FunctionObject&);