@@ -419,7 +419,6 @@ def __init__(
419
419
self .inputFlag = False # for model with input quantity
420
420
self .simulationFlag = False # if the model is simulated?
421
421
self .outputFlag = False
422
- self .csvFile : Optional [pathlib .Path ] = None # for storing inputs condition
423
422
self .resultfile : Optional [pathlib .Path ] = None # for storing result file
424
423
self .variableFilter = variableFilter
425
424
@@ -910,6 +909,9 @@ def simulate(self, resultfile: Optional[str] = None, simflags: Optional[str] = N
910
909
om_cmd .arg_set (key = "overrideFile" , val = overrideFile .as_posix ())
911
910
912
911
if self .inputFlag : # if model has input quantities
912
+ # csvfile is based on name used for result file
913
+ csvfile = resultfile .parent / f"{ resultfile .stem } .csv"
914
+
913
915
for i in self .inputlist :
914
916
val = self .inputlist [i ]
915
917
if val is None :
@@ -921,9 +923,11 @@ def simulate(self, resultfile: Optional[str] = None, simflags: Optional[str] = N
921
923
raise ModelicaSystemError (f"startTime not matched for Input { i } !" )
922
924
if float (self .simulateOptions ["stopTime" ]) != val [- 1 ][0 ]:
923
925
raise ModelicaSystemError (f"stopTime not matched for Input { i } !" )
924
- self .csvFile = self .createCSVData () # create csv file
925
926
926
- om_cmd .arg_set (key = "csvInput" , val = self .csvFile .as_posix ())
927
+ # write csv file and store the name
928
+ csvfile = self .createCSVData (csvfile = csvfile )
929
+
930
+ om_cmd .arg_set (key = "csvInput" , val = csvfile .as_posix ())
927
931
928
932
# delete resultfile ...
929
933
if self .resultfile .is_file ():
@@ -1151,7 +1155,11 @@ def checkValidInputs(self, name):
1151
1155
else :
1152
1156
raise ModelicaSystemError ('Error!!! Value must be in tuple format' )
1153
1157
1154
- def createCSVData (self ) -> pathlib .Path :
1158
+ def createCSVData (self , csvfile : Optional [pathlib .Path ] = None ) -> pathlib .Path :
1159
+ """
1160
+ Create a csv file with inputs for the simulation/optimization of the model. If csvfile is provided as argument,
1161
+ this file is used; else a generic file name is created.
1162
+ """
1155
1163
start_time : float = float (self .simulateOptions ["startTime" ])
1156
1164
stop_time : float = float (self .simulateOptions ["stopTime" ])
1157
1165
@@ -1192,13 +1200,14 @@ def createCSVData(self) -> pathlib.Path:
1192
1200
]
1193
1201
csv_rows .append (row )
1194
1202
1195
- csvFile = self .tempdir / f'{ self .modelName } .csv'
1203
+ if csvfile is None :
1204
+ csvfile = self .tempdir / f'{ self .modelName } .csv'
1196
1205
1197
- with open (file = csvFile , mode = "w" , encoding = "utf-8" , newline = "" ) as fh :
1206
+ with open (file = csvfile , mode = "w" , encoding = "utf-8" , newline = "" ) as fh :
1198
1207
writer = csv .writer (fh )
1199
1208
writer .writerows (csv_rows )
1200
1209
1201
- return csvFile
1210
+ return csvfile
1202
1211
1203
1212
# to convert Modelica model to FMU
1204
1213
def convertMo2Fmu (self , version = "2.0" , fmuType = "me_cs" , fileNamePrefix = "<default>" , includeResources = True ): # 19
@@ -1314,8 +1323,8 @@ def load_module_from_path(module_name, file_path):
1314
1323
for l in tupleList :
1315
1324
if l [0 ] < float (self .simulateOptions ["startTime" ]):
1316
1325
raise ModelicaSystemError ('Input time value is less than simulation startTime' )
1317
- self . csvFile = self .createCSVData ()
1318
- om_cmd .arg_set (key = "csvInput" , val = self . csvFile .as_posix ())
1326
+ csvfile = self .createCSVData ()
1327
+ om_cmd .arg_set (key = "csvInput" , val = csvfile .as_posix ())
1319
1328
1320
1329
om_cmd .arg_set (key = "l" , val = str (lintime or self .linearOptions ["stopTime" ]))
1321
1330
0 commit comments