@@ -388,7 +388,6 @@ def __init__(
388388 self ._lmodel = lmodel # may be needed if model is derived from other model
389389 self ._model_name = modelName # Model class name
390390 self ._file_name = pathlib .Path (fileName ).resolve () if fileName is not None else None # Model file/package name
391- self ._has_inputs = False # for model with input quantity
392391 self ._simulated = False # True if the model has already been simulated
393392 self ._result_file : Optional [pathlib .Path ] = None # for storing result file
394393 self ._variable_filter = variableFilter
@@ -967,22 +966,20 @@ def simulate_cmd(
967966
968967 om_cmd .arg_set (key = "overrideFile" , val = overrideFile .as_posix ())
969968
970- if self ._has_inputs : # if model has input quantities
971- # csvfile is based on name used for result file
972- csvfile = result_file .parent / f"{ result_file .stem } .csv"
973-
974- for i in self ._inputs :
975- val = self ._inputs [i ]
969+ if self ._inputs : # if model has input quantities
970+ for key in self ._inputs :
971+ val = self ._inputs [key ]
976972 if val is None :
977973 val = [(float (self ._simulate_options ["startTime" ]), 0.0 ),
978974 (float (self ._simulate_options ["stopTime" ]), 0.0 )]
979- self ._inputs [i ] = [(float (self ._simulate_options ["startTime" ]), 0.0 ),
980- (float (self ._simulate_options ["stopTime" ]), 0.0 )]
975+ self ._inputs [key ] = val
981976 if float (self ._simulate_options ["startTime" ]) != val [0 ][0 ]:
982- raise ModelicaSystemError (f"startTime not matched for Input { i } !" )
977+ raise ModelicaSystemError (f"startTime not matched for Input { key } !" )
983978 if float (self ._simulate_options ["stopTime" ]) != val [- 1 ][0 ]:
984- raise ModelicaSystemError (f"stopTime not matched for Input { i } !" )
979+ raise ModelicaSystemError (f"stopTime not matched for Input { key } !" )
985980
981+ # csvfile is based on name used for result file
982+ csvfile = result_file .parent / f"{ result_file .stem } .csv"
986983 # write csv file and store the name
987984 csvfile = self ._createCSVData (csvfile = csvfile )
988985
@@ -1379,11 +1376,13 @@ def setInputs(
13791376 else :
13801377 raise ModelicaSystemError (f"Data cannot be evaluated for { repr (key )} : { repr (val )} " )
13811378
1382- self ._has_inputs = True
1383-
13841379 return True
13851380
1386- def _createCSVData (self ) -> pathlib .Path :
1381+ def _createCSVData (self , csvfile : Optional [pathlib .Path ] = None ) -> pathlib .Path :
1382+ """
1383+ Create a csv file with inputs for the simulation/optimization of the model. If csvfile is provided as argument,
1384+ this file is used; else a generic file name is created.
1385+ """
13871386 start_time : float = float (self ._simulate_options ["startTime" ])
13881387 stop_time : float = float (self ._simulate_options ["stopTime" ])
13891388
@@ -1567,13 +1566,13 @@ def load_module_from_path(module_name, file_path):
15671566
15681567 om_cmd .arg_set (key = "overrideFile" , val = overrideLinearFile .as_posix ())
15691568
1570- if self ._has_inputs :
1571- nameVal = self . getInputs ()
1572- for n in nameVal :
1573- tupleList = nameVal . get ( n )
1574- if tupleList is not None :
1575- for l in tupleList :
1576- if l [0 ] < float (self ._simulate_options ["startTime" ]):
1569+ inputs = self .getInputs ()
1570+ if inputs :
1571+ for key in inputs :
1572+ data = inputs [ key ]
1573+ if data is not None :
1574+ for value in data :
1575+ if value [0 ] < float (self ._simulate_options ["startTime" ]):
15771576 raise ModelicaSystemError ('Input time value is less than simulation startTime' )
15781577 csvfile = self ._createCSVData ()
15791578 om_cmd .arg_set (key = "csvInput" , val = csvfile .as_posix ())
0 commit comments