OMPython
OMPython copied to clipboard
Enable the usage of a pre-built model executable when instantiating ModelicaSystem
Related Issues
This pull request was inspired from the discussion in issue #151
Purpose
- Enable the usage of a pre-built model executable when instantiating
ModelicaSystem
. This will gain some efficiency e.g. when only the parameters or the input data changes between different simulation runs. - Apply the customization (variableFilter or overrides in general) when calling the pre-built model executable (as an alternative to the variableFilter that can be passed to ModelicaSystem or buildModel that was introduced in issue #151).
Approach
ModelicaSystem will not to call buildModel when the xmlFileName
of the pre-built model is provided.
from OMPython import ModelicaSystem
mod = ModelicaSystem(
fileName=`BouncingBall.mo`, modelName='BouncingBall',
xmlFileName='BouncingBall_init.xml'
)
The simulation can be executed with a customized set of output variables and stopTime like this:
res_vars = ['h', 'v']
log_str = str(mod.simulate(
resultfile='/tmp/bouncingball_res.mat',
simflags=None,
overrideaux='stopTime={0},'.format(stopTime) + 'variableFilter="'+'|'.join(res_vars)+'"'
))
The log_str contains the models output from stdout and stderr.
Thanks to @Nobby-n and @arun3688 for contribution and inspiration.
I am happy to provide this PR @arun3688