基于OpenModelica脚本实现仿真自动化的技术咨询
OpenModelica仿真自动化脚本求助
我正尝试通过OpenModelica脚本实现仿真自动化,具体目标如下:
- 使用for循环批量运行不同仿真任务
- 通过数组配置每次仿真所需的不同参数
- 将仿真输出保存为仅包含指定参数的CSV文件(全量导出参数会导致文件体积过大)
初始OMS代码
loadFile("scenario_1_fists_paper_microgrid_no_bess_no_solar_l2_l3_no_ev_charging.mo"); getErrorString(); parameter Real BESSCapacity[3] = {1620000000, 3240000000, 16200000000}; getErrorString(); parameter String BESSFunction[3] = {"demandResponse", "demandResponse", "peakShaving"}; getErrorString(); equation for i in 1:4 loop Buildings.Electrical.AC.ThreePhasesBalanced.Storage.Battery BESS(EMax = BESSCapacity[i], SOC_start = 0.5, pf = 0.9) annotation( Placement(visible = true, transformation(origin = {-10, -68}, extent = {{10, -10}, {-10, 10}}, rotation = 90))); Buildings.Utilities.IO.Python_3_8.Real_Real level_2_ev_charger_random_generator(functionName = BESSFunction[i] ,moduleName = "pythonFile",nDblRea = 1, nDblWri = 1, samplePeriod = 900) annotation( Placement(visible = true, transformation(origin = {89, -51}, extent = {{9, -9}, {-9, 9}}, rotation = 0))); simulate(conf_paper_microgrid, fileNamePrefix = "run_1", outputFormat = "csv"); getErrorString(); end for;
我是OpenModelica脚本新手,现在有两个疑问:
- OpenModelica脚本中的for循环是否和建模时的循环规则一致?
- 如何导出仅包含指定参数(如
building_load.P、BESS.P等)的CSV文件?
根据建议修改后的代码
loadFile("scenario_1_fists_paper_microgrid_no_bess_no_solar_l2_l3_no_ev_charging.mo"); getErrorString(); parameter Real BESSCapacity[3] = {1620000000, 3240000000, 16200000000}; getErrorString(); parameter String BESSFunction[3] = {"demandResponse", "demandResponse", "peakShaving"}; getErrorString(); equation for i in {1, 2, 3} loop // Do something for parameter sweep simulate(conf_paper_microgrid, fileNamePrefix = "run_1", outputFormat = "csv"); getErrorString(); end for;
内容的提问来源于stack exchange,提问作者Luis Enriquez-Contreras
相关产品推荐
相关产品推荐

