@@ -132,8 +132,14 @@ def args_set(self, args: dict):
132132
133133 def run (self ):
134134
135- cmd = [self ._exe_file .as_posix ()] + [f"{ key } ={ self ._args [key ]} " for key in self ._args ]
136- self ._run_cmd (cmd = cmd , timeout = self ._timeout )
135+ cmdl = [self ._exe_file .as_posix ()]
136+ for key in self ._args :
137+ if self ._args [key ] is None :
138+ cmdl .append (f"-{ key } " )
139+ else :
140+ cmdl .append (f"-{ key } ={ self ._args [key ]} " )
141+
142+ self ._run_cmd (cmd = cmdl , timeout = self ._timeout )
137143
138144 return True
139145
@@ -687,7 +693,7 @@ def simulate(self, resultfile: Optional[str] = None, simflags: Optional[str] = N
687693 >>> simulate()
688694 >>> simulate(resultfile="a.mat")
689695 >>> simulate(simflags="-noEventEmit -noRestart -override=e=0.3,g=10") # set runtime simulation flags
690- >>> simulate(simargs={"- noEventEmit": None, "- noRestart": None, "- override": "e=0.3,g=10"}) # using simargs
696+ >>> simulate(simargs={"noEventEmit": None, "noRestart": None, "override": "e=0.3,g=10"}) # using simargs
691697 """
692698
693699 om_cmd = ModelicaSystemCmd (cmdpath = pathlib .Path (self .tempdir ), modelname = self .modelName , timeout = timeout )
@@ -700,7 +706,7 @@ def simulate(self, resultfile: Optional[str] = None, simflags: Optional[str] = N
700706 else :
701707 self .resultfile = (pathlib .Path (self .tempdir ) / resultfile ).as_posix ()
702708 # always define the resultfile to use
703- om_cmd .arg_set (key = "- r" , val = self .resultfile )
709+ om_cmd .arg_set (key = "r" , val = self .resultfile )
704710
705711 # allow runtime simulation flags from user input
706712 # TODO: merge into ModelicaSystemCmd?
@@ -711,6 +717,9 @@ def simulate(self, resultfile: Optional[str] = None, simflags: Optional[str] = N
711717
712718 args = [s for s in simflags .split (' ' ) if s ]
713719 for arg in args :
720+ if arg [0 ] != '-' :
721+ raise ModelicaSystemError (f"Invalid simulation flag: { arg } " )
722+ arg = arg [1 :]
714723 parts = arg .split ('=' )
715724 if len (parts ) == 1 :
716725 val = None
@@ -730,7 +739,7 @@ def simulate(self, resultfile: Optional[str] = None, simflags: Optional[str] = N
730739 for key , value in tmpdict .items ():
731740 file .write (f"{ key } ={ value } \n " )
732741
733- om_cmd .arg_set (key = "- overrideFile" , val = overrideFile .as_posix ())
742+ om_cmd .arg_set (key = "overrideFile" , val = overrideFile .as_posix ())
734743
735744 if self .inputFlag : # if model has input quantities
736745 for i in self .inputlist :
@@ -746,7 +755,7 @@ def simulate(self, resultfile: Optional[str] = None, simflags: Optional[str] = N
746755 raise ModelicaSystemError (f"stopTime not matched for Input { i } !" )
747756 self .csvFile = self .createCSVData () # create csv file
748757
749- om_cmd .arg_set (key = "- csvInput" , val = self .csvFile .as_posix ())
758+ om_cmd .arg_set (key = "csvInput" , val = self .csvFile .as_posix ())
750759
751760 self .simulationFlag = om_cmd .run ()
752761
@@ -1071,7 +1080,7 @@ def linearize(self, lintime: Optional[float] = None, simflags: Optional[str] = N
10711080 lintime: Override linearOptions["stopTime"] value.
10721081 simflags: A string of extra command line flags for the model
10731082 binary. - depreciated in favor of simargs
1074- simargs: A dict with command line flags and possible options
1083+ simargs: A dict with command line flags and possible options; example: "simargs={'csvInput': 'a.csv'}"
10751084 timeout: Possible timeout for the execution of OM.
10761085
10771086 Returns:
@@ -1098,7 +1107,7 @@ def linearize(self, lintime: Optional[float] = None, simflags: Optional[str] = N
10981107 for key , value in self .linearOptions .items ():
10991108 file .write (f"{ key } ={ value } \n " )
11001109
1101- om_cmd .arg_set (key = "- overrideFile" , val = overrideLinearFile .as_posix ())
1110+ om_cmd .arg_set (key = "overrideFile" , val = overrideLinearFile .as_posix ())
11021111
11031112 if self .inputFlag :
11041113 nameVal = self .getInputs ()
@@ -1109,9 +1118,9 @@ def linearize(self, lintime: Optional[float] = None, simflags: Optional[str] = N
11091118 if l [0 ] < float (self .simulateOptions ["startTime" ]):
11101119 raise ModelicaSystemError ('Input time value is less than simulation startTime' )
11111120 self .csvFile = self .createCSVData ()
1112- om_cmd .arg_set (key = "- csvInput" , val = self .csvFile .as_posix ())
1121+ om_cmd .arg_set (key = "csvInput" , val = self .csvFile .as_posix ())
11131122
1114- om_cmd .arg_set (key = "- l" , val = f"{ lintime or self .linearOptions ["stopTime" ]} " )
1123+ om_cmd .arg_set (key = "l" , val = f"{ lintime or self .linearOptions ["stopTime" ]} " )
11151124
11161125 # allow runtime simulation flags from user input
11171126 # TODO: merge into ModelicaSystemCmd?
@@ -1122,6 +1131,8 @@ def linearize(self, lintime: Optional[float] = None, simflags: Optional[str] = N
11221131
11231132 args = [s for s in simflags .split (' ' ) if s ]
11241133 for arg in args :
1134+ if arg [0 ] != '-' :
1135+ raise ModelicaSystemError (f"Invalid simulation flag: { arg } " )
11251136 parts = arg .split ('=' )
11261137 if len (parts ) == 1 :
11271138 val = None
0 commit comments