@@ -1205,36 +1205,39 @@ def setInputs(self, name: str | list[str] | dict[str, Any]) -> bool:
12051205 inputdata = self ._prepare_input_data (raw_input = name )
12061206
12071207 for key , val in inputdata .items ():
1208- if key in self .inputlist :
1209- if not isinstance (val , str ):
1210- raise ModelicaSystemError (f"Invalid data in input for { repr (key )} : { repr (val )} " )
1211-
1212- val_evaluated = ast .literal_eval (val )
1213-
1214- if isinstance (val_evaluated , (int , float )):
1215- self .inputlist [key ] = [(float (self .simulateOptions ["startTime" ]), float (val )),
1216- (float (self .simulateOptions ["stopTime" ]), float (val ))]
1217- elif isinstance (val_evaluated , list ):
1218- if not all ([isinstance (item , tuple ) for item in val_evaluated ]):
1219- raise ModelicaSystemError ("Value for setInput() must be in tuple format; "
1220- f"got { repr (val_evaluated )} " )
1221- if val_evaluated != sorted (val_evaluated , key = lambda x : x [0 ]):
1222- raise ModelicaSystemError ("Time value should be in increasing order; "
1223- f"got { repr (val_evaluated )} " )
1224-
1225- for item in val_evaluated :
1226- if item [0 ] < float (self .simulateOptions ["startTime" ]):
1227- raise ModelicaSystemError (f"Time value in { repr (item )} of { repr (val_evaluated )} is less "
1228- "than the simulation start time" )
1229- if len (item ) != 2 :
1230- raise ModelicaSystemError (f"Value { repr (item )} of { repr (val_evaluated )} "
1231- "is in incorrect format!" )
1232-
1233- self .inputlist [key ] = val_evaluated
1234- self .inputFlag = True
1235- else :
1208+ if key not in self .inputlist :
12361209 raise ModelicaSystemError (f"{ key } is not an input" )
12371210
1211+ if not isinstance (val , str ):
1212+ raise ModelicaSystemError (f"Invalid data in input for { repr (key )} : { repr (val )} " )
1213+
1214+ val_evaluated = ast .literal_eval (val )
1215+
1216+ if isinstance (val_evaluated , (int , float )):
1217+ self .inputlist [key ] = [(float (self .simulateOptions ["startTime" ]), float (val )),
1218+ (float (self .simulateOptions ["stopTime" ]), float (val ))]
1219+ elif isinstance (val_evaluated , list ):
1220+ if not all ([isinstance (item , tuple ) for item in val_evaluated ]):
1221+ raise ModelicaSystemError ("Value for setInput() must be in tuple format; "
1222+ f"got { repr (val_evaluated )} " )
1223+ if val_evaluated != sorted (val_evaluated , key = lambda x : x [0 ]):
1224+ raise ModelicaSystemError ("Time value should be in increasing order; "
1225+ f"got { repr (val_evaluated )} " )
1226+
1227+ for item in val_evaluated :
1228+ if item [0 ] < float (self .simulateOptions ["startTime" ]):
1229+ raise ModelicaSystemError (f"Time value in { repr (item )} of { repr (val_evaluated )} is less "
1230+ "than the simulation start time" )
1231+ if len (item ) != 2 :
1232+ raise ModelicaSystemError (f"Value { repr (item )} of { repr (val_evaluated )} "
1233+ "is in incorrect format!" )
1234+
1235+ self .inputlist [key ] = val_evaluated
1236+ else :
1237+ raise ModelicaSystemError (f"Data cannot be evaluated for { repr (key )} : { repr (val )} " )
1238+
1239+ self .inputFlag = True
1240+
12381241 return True
12391242
12401243 def createCSVData (self ) -> pathlib .Path :
0 commit comments