使用 OpenModelica 脚本自动化 OpenModelica 模拟

问题描述 投票:0回答:1

我正在尝试自动化我的 openModelica 模拟。我的三个目标如下:

  1. 运行 for 循环来运行不同的模拟
  2. 更改每次模拟所需的不同参数,每个参数都描述为一个数组
  3. 将模拟的输出保存为 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 脚本中的 for 循环是否与 openmodelica 中的相同。另外,如何仅使用模拟中的选择参数(building_load.P、BESS.P 等)保存模拟的 csv 文件。我是 openmodelica 脚本编写的新手,所以如果其中一些问题很微不足道,我深表歉意。谢谢您的帮助。

编辑评论中的建议:

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;

modelica openmodelica
1个回答
0
投票

这可以通过两种方式完成,使用 loadString 或 setComponentModifierValue:

loadFile("scenario_1_fists_paper_microgrid_no_bess_no_solar_l2_l3_no_ev_charging.mo"); getErrorString();

BESSCapacity[3] := {1620000000, 3240000000, 16200000000}; getErrorString();
BESSFunction[3] := {"demandResponse", "demandResponse", "peakShaving"}; getErrorString();


// using loadString to build a model on the fly
loadFile("scenario_1_fists_paper_microgrid_no_bess_no_solar_l2_l3_no_ev_charging.mo"); getErrorString();
for i in 1:4 loop
  loadString(
"model conf_paper_microgrid_" + String(i) + "
   extends conf_paper_microgrid(
     BESS(EMax = " + String(BESSCapacity[i]) + ", SOC_start = 0.5, pf = 0.9),
     level_2_ev_charger_random_generator(functionName = " + BESSFunction[i] +", moduleName = \"pythonFile\", nDblRea = 1, nDblWri = 1, samplePeriod = 900));
end conf_paper_microgrid_" + String(i) + ";"); getErrorString();
 simulate(stringTypeName("conf_paper_microgrid" + String(i)), fileNamePrefix = "run_" + String(i), outputFormat = "csv"); getErrorString();
end for;


/* second approach, use setComponentModifierValue, not sure if it works
for i in 1:4 loop
  setComponentModifierValue(conf_paper_microgrid, BESS, $Code((EMax = BESSCapacity[i], SOC_start = 0.5, pf = 0.9))); getErrorString();
  setComponentModifierValue(conf_paper_microgrid, level_2_ev_charger_random_generator, $Code((functionName = BESSFunction[i], moduleName = "pythonFile", nDblRea = 1, nDblWri = 1, samplePeriod = 900));
  simulate(conf_paper_microgrid, fileNamePrefix = "run_" + String(i), outputFormat = "csv"); getErrorString();
end for;
*/
© www.soinside.com 2019 - 2024. All rights reserved.