@@ -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
@@ -692,7 +698,7 @@ def simulate(self, resultfile: Optional[str] = None, simflags: Optional[str] = N
692698 >>> simulate()
693699 >>> simulate(resultfile="a.mat")
694700 >>> simulate(simflags="-noEventEmit -noRestart -override=e=0.3,g=10") # set runtime simulation flags
695- >>> simulate(simargs={"- noEventEmit": None, "- noRestart": None, "- override": "e=0.3,g=10"}) # using simargs
701+ >>> simulate(simargs={"noEventEmit": None, "noRestart": None, "override": "e=0.3,g=10"}) # using simargs
696702 """
697703
698704 om_cmd = ModelicaSystemCmd (cmdpath = pathlib .Path (self .tempdir ), modelname = self .modelName , timeout = timeout )
@@ -705,7 +711,7 @@ def simulate(self, resultfile: Optional[str] = None, simflags: Optional[str] = N
705711 else :
706712 self .resultfile = (pathlib .Path (self .tempdir ) / resultfile ).as_posix ()
707713 # always define the resultfile to use
708- om_cmd .arg_set (key = "- r" , val = self .resultfile )
714+ om_cmd .arg_set (key = "r" , val = self .resultfile )
709715
710716 # allow runtime simulation flags from user input
711717 # TODO: merge into ModelicaSystemCmd?
@@ -716,6 +722,9 @@ def simulate(self, resultfile: Optional[str] = None, simflags: Optional[str] = N
716722
717723 args = [s for s in simflags .split (' ' ) if s ]
718724 for arg in args :
725+ if arg [0 ] != '-' :
726+ raise ModelicaSystemError (f"Invalid simulation flag: { arg } " )
727+ arg = arg [1 :]
719728 parts = arg .split ('=' )
720729 if len (parts ) == 1 :
721730 val = None
@@ -735,7 +744,7 @@ def simulate(self, resultfile: Optional[str] = None, simflags: Optional[str] = N
735744 for key , value in tmpdict .items ():
736745 file .write (f"{ key } ={ value } \n " )
737746
738- om_cmd .arg_set (key = "- overrideFile" , val = overrideFile .as_posix ())
747+ om_cmd .arg_set (key = "overrideFile" , val = overrideFile .as_posix ())
739748
740749 if self .inputFlag : # if model has input quantities
741750 for i in self .inputlist :
@@ -751,7 +760,7 @@ def simulate(self, resultfile: Optional[str] = None, simflags: Optional[str] = N
751760 raise ModelicaSystemError (f"stopTime not matched for Input { i } !" )
752761 self .csvFile = self .createCSVData () # create csv file
753762
754- om_cmd .arg_set (key = "- csvInput" , val = self .csvFile .as_posix ())
763+ om_cmd .arg_set (key = "csvInput" , val = self .csvFile .as_posix ())
755764
756765 self .simulationFlag = om_cmd .run ()
757766
@@ -1076,7 +1085,7 @@ def linearize(self, lintime: Optional[float] = None, simflags: Optional[str] = N
10761085 lintime: Override linearOptions["stopTime"] value.
10771086 simflags: A string of extra command line flags for the model
10781087 binary. - depreciated in favor of simargs
1079- simargs: A dict with command line flags and possible options
1088+ simargs: A dict with command line flags and possible options; example: "simargs={'csvInput': 'a.csv'}"
10801089 timeout: Possible timeout for the execution of OM.
10811090
10821091 Returns:
@@ -1103,7 +1112,7 @@ def linearize(self, lintime: Optional[float] = None, simflags: Optional[str] = N
11031112 for key , value in self .linearOptions .items ():
11041113 file .write (f"{ key } ={ value } \n " )
11051114
1106- om_cmd .arg_set (key = "- overrideFile" , val = overrideLinearFile .as_posix ())
1115+ om_cmd .arg_set (key = "overrideFile" , val = overrideLinearFile .as_posix ())
11071116
11081117 if self .inputFlag :
11091118 nameVal = self .getInputs ()
@@ -1114,9 +1123,9 @@ def linearize(self, lintime: Optional[float] = None, simflags: Optional[str] = N
11141123 if l [0 ] < float (self .simulateOptions ["startTime" ]):
11151124 raise ModelicaSystemError ('Input time value is less than simulation startTime' )
11161125 self .csvFile = self .createCSVData ()
1117- om_cmd .arg_set (key = "- csvInput" , val = self .csvFile .as_posix ())
1126+ om_cmd .arg_set (key = "csvInput" , val = self .csvFile .as_posix ())
11181127
1119- om_cmd .arg_set (key = "- l" , val = f"{ lintime or self .linearOptions ["stopTime" ]} " )
1128+ om_cmd .arg_set (key = "l" , val = f"{ lintime or self .linearOptions ["stopTime" ]} " )
11201129
11211130 # allow runtime simulation flags from user input
11221131 # TODO: merge into ModelicaSystemCmd?
@@ -1127,6 +1136,8 @@ def linearize(self, lintime: Optional[float] = None, simflags: Optional[str] = N
11271136
11281137 args = [s for s in simflags .split (' ' ) if s ]
11291138 for arg in args :
1139+ if arg [0 ] != '-' :
1140+ raise ModelicaSystemError (f"Invalid simulation flag: { arg } " )
11301141 parts = arg .split ('=' )
11311142 if len (parts ) == 1 :
11321143 val = None
0 commit comments