@@ -389,7 +389,6 @@ def __init__(
389
389
self ._file_name = pathlib .Path (fileName ).resolve () if fileName is not None else None # Model file/package name
390
390
self ._has_inputs = False # for model with input quantity
391
391
self ._simulated = False # True if the model has already been simulated
392
- self ._csvFile : Optional [pathlib .Path ] = None # for storing inputs condition
393
392
self ._result_file : Optional [pathlib .Path ] = None # for storing result file
394
393
self ._variable_filter = variableFilter
395
394
@@ -969,6 +968,9 @@ def simulate(self,
969
968
om_cmd .arg_set (key = "overrideFile" , val = overrideFile .as_posix ())
970
969
971
970
if self ._has_inputs : # if model has input quantities
971
+ # csvfile is based on name used for result file
972
+ csvfile = self ._result_file .parent / f"{ self ._result_file .stem } .csv"
973
+
972
974
for i in self ._inputs :
973
975
val = self ._inputs [i ]
974
976
if val is None :
@@ -980,9 +982,11 @@ def simulate(self,
980
982
raise ModelicaSystemError (f"startTime not matched for Input { i } !" )
981
983
if float (self ._simulate_options ["stopTime" ]) != val [- 1 ][0 ]:
982
984
raise ModelicaSystemError (f"stopTime not matched for Input { i } !" )
983
- self ._csvFile = self ._createCSVData () # create csv file
984
985
985
- om_cmd .arg_set (key = "csvInput" , val = self ._csvFile .as_posix ())
986
+ # write csv file and store the name
987
+ csvfile = self ._createCSVData (csvfile = csvfile )
988
+
989
+ om_cmd .arg_set (key = "csvInput" , val = csvfile .as_posix ())
986
990
987
991
# delete resultfile ...
988
992
if self ._result_file .is_file ():
@@ -1231,7 +1235,11 @@ def _checkValidInputs(self, name):
1231
1235
else :
1232
1236
raise ModelicaSystemError ('Error!!! Value must be in tuple format' )
1233
1237
1234
- def _createCSVData (self ) -> pathlib .Path :
1238
+ def _createCSVData (self , csvfile : Optional [pathlib .Path ] = None ) -> pathlib .Path :
1239
+ """
1240
+ Create a csv file with inputs for the simulation/optimization of the model. If csvfile is provided as argument,
1241
+ this file is used; else a generic file name is created.
1242
+ """
1235
1243
start_time : float = float (self ._simulate_options ["startTime" ])
1236
1244
stop_time : float = float (self ._simulate_options ["stopTime" ])
1237
1245
@@ -1272,13 +1280,14 @@ def _createCSVData(self) -> pathlib.Path:
1272
1280
]
1273
1281
csv_rows .append (row )
1274
1282
1275
- csvFile = self ._tempdir / f'{ self ._model_name } .csv'
1283
+ if csvfile is None :
1284
+ csvFile = self ._tempdir / f'{ self ._model_name } .csv'
1276
1285
1277
- with open (file = csvFile , mode = "w" , encoding = "utf-8" , newline = "" ) as fh :
1286
+ with open (file = csvfile , mode = "w" , encoding = "utf-8" , newline = "" ) as fh :
1278
1287
writer = csv .writer (fh )
1279
1288
writer .writerows (csv_rows )
1280
1289
1281
- return csvFile
1290
+ return csvfile
1282
1291
1283
1292
def convertMo2Fmu (self , version : str = "2.0" , fmuType : str = "me_cs" ,
1284
1293
fileNamePrefix : str = "<default>" ,
@@ -1422,8 +1431,8 @@ def load_module_from_path(module_name, file_path):
1422
1431
for l in tupleList :
1423
1432
if l [0 ] < float (self ._simulate_options ["startTime" ]):
1424
1433
raise ModelicaSystemError ('Input time value is less than simulation startTime' )
1425
- self . _csvFile = self ._createCSVData ()
1426
- om_cmd .arg_set (key = "csvInput" , val = self . _csvFile .as_posix ())
1434
+ csvfile = self ._createCSVData ()
1435
+ om_cmd .arg_set (key = "csvInput" , val = csvfile .as_posix ())
1427
1436
1428
1437
om_cmd .arg_set (key = "l" , val = str (lintime or self ._linearization_options ["stopTime" ]))
1429
1438
0 commit comments