簡體   English   中英

如何通過 Dymola 中的腳本定義 Combitimetable?

[英]How to define a Combitimetable through a script in Dymola?

我正在嘗試在腳本中使用 for 循環按順序執行多個模擬。 從模擬到模擬,唯一要改變的變量是 Combitimetable 的文件路徑。

我傳播了變量 fileName 以便在每次迭代中分配一個新路徑。 但是,當 model 讀取擴展名時,更改了 timeScale 並且分辨率低於需要。 我也嘗試傳播 timeScale,但沒有改變。 是否有 function 來定義 Combitimetable 變量? 我唯一的選擇是合並所有表並手動拆分結果嗎?

單次運行的腳本示例(沒有 for 循環):

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);

我不確定您的問題出在哪里以及您如何更改fileName 在您的問題timeScale也沒有在任何地方使用。 無論如何,我會這樣做:為fileName添加一個參數到您的 model 。 由於它是一個字符串,因此更改它的唯一方法是通過一個修飾符,該修飾符可以包含在simulateModel命令的 model 名稱中。

這是一個示例:在帶有時間表的 model 中,傳播參數fileName

model MyModel
  parameter String fileName="NoName" "File where matrix is stored";
  Modelica.Blocks.Tables.CombiTable1Ds combiTable1Ds(
    tableOnFile=true,
    tableName="x",
    fileName=fileName) annotation (Placement(transformation(extent={{-10,-10},{10,10}})));
  Modelica.Blocks.Sources.Ramp ramp(duration=1) annotation (Placement(transformation(extent={{-60,-10},{-40,10}})));
equation 
  connect(ramp.y, combiTable1Ds.u) annotation (Line(points={{-39,0},{-12,0}}, color={0,0,127}));
  annotation (uses(Modelica(version="4.0.0")));
end MyModel;

然后在每個循環中更改fileName的值。 這里我們假設工作區中有三個 .mat 文件,分別命名為First.matSecond.matThird.mat

function batchSim
  input String fileNames[:] = {"First", "Second", "Third"};
algorithm 
  for f in fileNames loop
    simulateModel("MyModel(fileName=\""+f+".mat\")", stopTime=1, resultFile="Full_Year_Simulation_"+f);
  end for;
  annotation(__Dymola_interactive=true);
end batchSim;

這工作得很好,但缺點是 model 將在 for 循環的每次迭代中重新編譯,因為修飾符已更改。 如果這是一個大問題,請在 model 中的字符串向量中定義所有文件路徑,並為索引添加一個 integer 參數。 然后使用命令simulateExtendedModel並通過參數initialNamesinitialValues僅更改索引。

基於 marco 的答案(相同的 model 和相同的外部文件),另一種方法是制作一個腳本,例如:

fileNames := {"First", "Second", "Third"};
Advanced.AllowStringParameters:=true;
translateModel("MyModel");
for f in fileNames loop
  fileName:=f;
  simulateModel("MyModel", stopTime=1, resultFile="Full_Year_Simulation_"+f);
end for;

不幸的是,您似乎無法將其轉換為 function。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM