@@ -410,7 +410,6 @@ def __init__(
410
410
self .inputFlag = False # for model with input quantity
411
411
self .simulationFlag = False # if the model is simulated?
412
412
self .outputFlag = False
413
- self .csvFile : Optional [pathlib .Path ] = None # for storing inputs condition
414
413
self .resultfile : Optional [pathlib .Path ] = None # for storing result file
415
414
self .variableFilter = variableFilter
416
415
@@ -911,6 +910,9 @@ def simulate_cmd(
911
910
om_cmd .arg_set (key = "overrideFile" , val = overrideFile .as_posix ())
912
911
913
912
if self .inputFlag : # if model has input quantities
913
+ # csvfile is based on name used for result file
914
+ csvfile = resultfile .parent / f"{ resultfile .stem } .csv"
915
+
914
916
for i in self .inputlist :
915
917
val = self .inputlist [i ]
916
918
if val is None :
@@ -922,9 +924,11 @@ def simulate_cmd(
922
924
raise ModelicaSystemError (f"startTime not matched for Input { i } !" )
923
925
if float (self .simulateOptions ["stopTime" ]) != val [- 1 ][0 ]:
924
926
raise ModelicaSystemError (f"stopTime not matched for Input { i } !" )
925
- self .csvFile = self .createCSVData () # create csv file
926
927
927
- om_cmd .arg_set (key = "csvInput" , val = self .csvFile .as_posix ())
928
+ # write csv file and store the name
929
+ csvfile = self .createCSVData (csvfile = csvfile )
930
+
931
+ om_cmd .arg_set (key = "csvInput" , val = csvfile .as_posix ())
928
932
929
933
return om_cmd
930
934
@@ -1169,7 +1173,11 @@ def checkValidInputs(self, name):
1169
1173
else :
1170
1174
raise ModelicaSystemError ('Error!!! Value must be in tuple format' )
1171
1175
1172
- def createCSVData (self ) -> pathlib .Path :
1176
+ def createCSVData (self , csvfile : Optional [pathlib .Path ] = None ) -> pathlib .Path :
1177
+ """
1178
+ Create a csv file with inputs for the simulation/optimization of the model. If csvfile is provided as argument,
1179
+ this file is used; else a generic file name is created.
1180
+ """
1173
1181
start_time : float = float (self .simulateOptions ["startTime" ])
1174
1182
stop_time : float = float (self .simulateOptions ["stopTime" ])
1175
1183
@@ -1210,13 +1218,14 @@ def createCSVData(self) -> pathlib.Path:
1210
1218
]
1211
1219
csv_rows .append (row )
1212
1220
1213
- csvFile = self .tempdir / f'{ self .modelName } .csv'
1221
+ if csvfile is None :
1222
+ csvfile = self .tempdir / f'{ self .modelName } .csv'
1214
1223
1215
- with open (file = csvFile , mode = "w" , encoding = "utf-8" , newline = "" ) as fh :
1224
+ with open (file = csvfile , mode = "w" , encoding = "utf-8" , newline = "" ) as fh :
1216
1225
writer = csv .writer (fh )
1217
1226
writer .writerows (csv_rows )
1218
1227
1219
- return csvFile
1228
+ return csvfile
1220
1229
1221
1230
# to convert Modelica model to FMU
1222
1231
def convertMo2Fmu (self , version = "2.0" , fmuType = "me_cs" , fileNamePrefix = "<default>" , includeResources = True ): # 19
@@ -1332,8 +1341,8 @@ def load_module_from_path(module_name, file_path):
1332
1341
for l in tupleList :
1333
1342
if l [0 ] < float (self .simulateOptions ["startTime" ]):
1334
1343
raise ModelicaSystemError ('Input time value is less than simulation startTime' )
1335
- self . csvFile = self .createCSVData ()
1336
- om_cmd .arg_set (key = "csvInput" , val = self . csvFile .as_posix ())
1344
+ csvfile = self .createCSVData ()
1345
+ om_cmd .arg_set (key = "csvInput" , val = csvfile .as_posix ())
1337
1346
1338
1347
om_cmd .arg_set (key = "l" , val = str (lintime or self .linearOptions ["stopTime" ]))
1339
1348
0 commit comments