@@ -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 ():
@@ -1144,7 +1148,11 @@ def checkValidInputs(self, name):
1144
1148
else :
1145
1149
raise ModelicaSystemError ('Error!!! Value must be in tuple format' )
1146
1150
1147
- def createCSVData (self ) -> pathlib .Path :
1151
+ def createCSVData (self , csvfile : Optional [pathlib .Path ] = None ) -> pathlib .Path :
1152
+ """
1153
+ Create a csv file with inputs for the simulation/optimization of the model. If csvfile is provided as argument,
1154
+ this file is used; else a generic file name is created.
1155
+ """
1148
1156
start_time : float = float (self .simulateOptions ["startTime" ])
1149
1157
stop_time : float = float (self .simulateOptions ["stopTime" ])
1150
1158
@@ -1185,13 +1193,14 @@ def createCSVData(self) -> pathlib.Path:
1185
1193
]
1186
1194
csv_rows .append (row )
1187
1195
1188
- csvFile = self .tempdir / f'{ self .modelName } .csv'
1196
+ if csvfile is None :
1197
+ csvfile = self .tempdir / f'{ self .modelName } .csv'
1189
1198
1190
- with open (file = csvFile , mode = "w" , encoding = "utf-8" , newline = "" ) as fh :
1199
+ with open (file = csvfile , mode = "w" , encoding = "utf-8" , newline = "" ) as fh :
1191
1200
writer = csv .writer (fh )
1192
1201
writer .writerows (csv_rows )
1193
1202
1194
- return csvFile
1203
+ return csvfile
1195
1204
1196
1205
# to convert Modelica model to FMU
1197
1206
def convertMo2Fmu (self , version = "2.0" , fmuType = "me_cs" , fileNamePrefix = "<default>" , includeResources = True ): # 19
@@ -1307,8 +1316,8 @@ def load_module_from_path(module_name, file_path):
1307
1316
for l in tupleList :
1308
1317
if l [0 ] < float (self .simulateOptions ["startTime" ]):
1309
1318
raise ModelicaSystemError ('Input time value is less than simulation startTime' )
1310
- self . csvFile = self .createCSVData ()
1311
- om_cmd .arg_set (key = "csvInput" , val = self . csvFile .as_posix ())
1319
+ csvfile = self .createCSVData ()
1320
+ om_cmd .arg_set (key = "csvInput" , val = csvfile .as_posix ())
1312
1321
1313
1322
om_cmd .arg_set (key = "l" , val = str (lintime or self .linearOptions ["stopTime" ]))
1314
1323
0 commit comments