I am trying to perform several simulations in a sequence using a for loop in a script. From simulation to simulation, the only variable to change is the file path of a Combitimetable.
I propagated the variable fileName in order to assign a new path in each iteration. However, when the model reads the extension, changes the timeScale and the resolution is lower than needed. I tried to propagate timeScale too, but without changes. Is there a function to define the Combitimetable variables? Is my only alternative to merge all tables and split the results manually?
Example of the script on a single run (without the for loop):
filePath="RL_30_200g";
dymolaPath = "modelica://customTILComponents/Combitables/Combitimetable_"+filePath+".txt";
fileName= ModelicaServices.ExternalReferences.loadResource(dymolaPath);
result ="Full_Year_Simulation_"+filePath;
timeScale = 1/3600;
translateModel ("customTILComponents.MA_Santoro.FullModels.OptiHorst_FullModel_New_Year_Simulation_Batch");
simulateModel(startTime=0,stopTime=8860,numberOfIntervals=300,method="Dassl",tolerance=0.000001,resultFile=result);
I am not sure where your problem is and how you change
fileName. In your questiontimeScaleis also not used anywhere. Anyway, here is how I would do it: add a parameter to your model forfileName. Since it is a string, the only way to change it is via a modifier which can be included in the model name of thesimulateModelcommand.Here is an example: In your model with the time table, propagate the parameter
fileName:Then change the value of
fileNamein every loop. Here we assume that there are three .mat files available in the workspace, namedFirst.mat,Second.matandThird.mat.This works quite well, but the downside is that the model will be recompiled in every iteration of the for loop, as the modifier has changed. If this is a big problem, define all file paths in a string vector in the model and add an integer parameter for the index. Then use the command
simulateExtendedModeland change only the index via the parametersinitialNamesandinitialValues.