Description
Overview
The argument '-override' of (model).exe has the following syntax
(model).exe -override=startTime=0,stopTime=5,stepSize=0.01,tolerance=1e-06,solver=dassl,mdl.param1=0.5,mdl.param2=2.0,outputFormat=csv,variableFilter=. *
ModelicaSystems.simulate() will give the '-override' option if parameters or simulation options are set using setParameters() or setSimulationOptions().
In this case, 'outputFormat' and 'variableFilter' cannot be specified.
To specify 'outputFormat' and 'variableFilter', I added options to the 'simflags' argument as below, but after using setParameters() or/and setSimulationOptions(), '-override' is double argument and simulate() does not work properly.
mod.simulate(simflags='-override=startTime=0,stopTime=5,stepSize=0.01,tolerance=1e-06,solver=dassl,outputFormat=csv,variableFilter=.*')
Operating Environment
Windows 10 Enterprise ver 20H2
OpenModelica 1.16.2 MSL3.2.3
Python 3.9.6
OMPython 3.3.0
Tentative measures
Do not use setParameters(), setSimulationOptions(), and specify all 'override' options using simFlags.
simulate() improvement suggestions
Add arguments to specify 'outputFormat' and 'variableFilter' and add code to append them to the '-override' statement.
The tested 'simulate()' modifications are as follows.
--- C:/venv39/jupyter-lab/Lib/site-packages/OMPython/__init__.py.org Thu Mar 17 15:14:01 2022
+++ C:/venv39/jupyter-lab/Lib/site-packages/OMPython/__init__patch.py Fri Apr 1 18:02:55 2022
@@ -1197,13 +1197,30 @@
return ([self.optimizeOptions.get(x,"NotExist") for x in names])
# to simulate or re-simulate model
- def simulate(self,resultfile=None,simflags=None): # 11
+ ## override option add
+ # -def simulate(self,resultfile=None,simflags=None): # 11
+ def simulate(self,resultfile=None,simflags=None,overrideaux=None): # 11
"""
This method simulates model according to the simulation options.
+
+ Parameters
+ ----------
+ resultfile : str or None
+ Output file name
+
+ simflags : str or None
+ Other simulation options not '-override' parameters
+
+ overrideaux : str or None
+ Specify 'outputFormat' and 'variableFilter
+
usage
+ -----
>>> simulate()
>>> simulate(resultfile="a.mat")
>>> simulate(simflags="-noEventEmit -noRestart -override=e=0.3,g=10) set runtime simulation flags
+ >>> simulate(simflags="-noEventEmit -noRestart" ,overrideaux="outputFormat=csv,variableFilter=.*") # set runtime simulation flags
"""
if(resultfile is None):
r=""
@@ -1225,6 +1242,13 @@
override =" -override=" + values1
else:
override =""
+
+ # add override flags not parameters or simulation options
+ if overrideaux:
+ if override:
+ override = override + "," + overrideaux
+ else:
+ override = " -override=" + overrideaux
if (self.inputFlag): # if model has input quantities
for i in self.inputlist: