Run a Python function from C++ code.
Example:
python_coupling::PythonCallback callback ( "atEndOfTimestep" );
callback.data().exposePtr("blockStorage", blocks );
callback.data().exposeValue("someInteger", 42);
callback();
int i = 0;
if ( callback.data().has<int>("integerSetInScript") ) {
i = callback.data().get<int>( "integerSetInScript" );
}
This example calls the python function "walberla_cpp.callbacks.atEndOfTimestep", which can be either set directly or using a decorator:
@waLBerla.callback( "atEndOfTimestep" )
The result of the function call will be stored in the data dictionary with the key "returnValue".
Depending on how many parameters the python function expects it is called in different ways:
- no parameters: the data is not passed
- multiple parameters: the data dictionary is unpacked i.e. yourFunction( **data )