Skip to content

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

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

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

@adeas31
Copy link
Member

adeas31 commented Apr 25, 2025

@joewa please rebase this to the latest code.

@adeas31 adeas31 requested a review from arun3688 April 25, 2025 13:14
@syntron
Copy link
Contributor

syntron commented Apr 28, 2025

perhaps wait a moment - currently lots of changes are ongoing ;-)

@joewa
Copy link
Author

joewa commented Apr 30, 2025

Please let me know when you think that the time is right @adeas31 @syntron
Then I will rebase.

@syntron
Copy link
Contributor

syntron commented Apr 30, 2025

@joewa please check PR #275 - I will prepare the code in it as single PRs; however, you could check out what to expect:

Class ModelicaSystemCmd would handle the execution of commands / calling the model executable. That way, the options (simflags / new: simargs) can be handled dynamically. Thus, any option could be overwritten (override!) as needed. See especially commit 2bd6754 which was created for this usecase.

@syntron
Copy link
Contributor

syntron commented May 1, 2025

@joewa feel free to work based on PR #279

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.

4 participants