OMPython icon indicating copy to clipboard operation
OMPython copied to clipboard

Enable the usage of a pre-built model executable when instantiating ModelicaSystem

Open joewa opened this issue 2 years ago • 2 comments

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.

joewa avatar Sep 12 '22 21:09 joewa

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Sep 12 '22 21:09 CLAassistant

I am happy to provide this PR @arun3688

joewa avatar Sep 12 '22 22:09 joewa