Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

joewa
Copy link

@joewa joewa commented Sep 12, 2022

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 ModelicaSystem.simulate() does not handle 'outputFormat' and 'variableFilter' options correctly. #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.

@CLAassistant
Copy link

CLAassistant commented Sep 12, 2022

CLA assistant check
All committers have signed the CLA.

@joewa
Copy link
Author

joewa commented Sep 12, 2022

I am happy to provide this PR @arun3688

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants