首页 > 解决方案 > 在 Modelica 中,如何在不连接 2 个块的情况下调用不同块中的变量?

问题描述

我们正在对各种工业组件块进行建模,每个块都有 CAPEX、人工成本、维护成本、总 OPEX 等。我们希望有 1 个块,在最好的情况下不连接到其他块,以占总 OPEX,由模型中存在的块引起的总资本支出、总劳动力成本等:块的数量不是固定的。有没有办法不用电线连接块?

如果没有办法,我们找到了使用 RealOutput y 向量的解决方案,如 Modelica.Blocks.Interfaces.MO 中所定义:nout 定义为我们想要加起来的实际变量的数量(例如,如果 CAPEX、OPEX和维护感兴趣,则nout = n = 3)。但是,我们争取 2 点:

  1. 我们如何通过这个 RealOutput 传递一个矩阵?例如,当 CAPEX 具有 3 个值时,这将很有用:估计值、乐观值和悲观值。
  2. 我们如何才能在 1 个区块中占用这个 y?现在我们设法使用 n Modelica.Blocks.Math.MultiSum 块来分别占用每个变量,但是有没有办法将它们分别相加,但在同一个块中?

感谢您非常感谢您的帮助和回答!

标签: modelica

解决方案


我认为您应该能够使用inner/outer构造和带有flow变量的自定义连接器来执行此操作,例如,您的资本支出,如 Fritzson 的书“Modelica 3.3 的面向对象建模和仿真原理”的第 5.8 节所示。

我本可以发誓已经有一个例子可以将大量组件的总和相加,但我在任何地方都找不到它......

package SO_69945088

model System
  FinancialAggregator fin_totals() "Collects financial info";
  inner CapexConn common_connection "autoshared connection";
  Component comp1(capex_info.amount={0, 3, 5});
  Component comp2(capex_info.amount={1, 10, 12});
  Component comp3(capex_info.amount={5, 6, 7});
equation
  //Conveniently collect financial info in fin_totals
  connect(common_connection, fin_totals.agg_conn);
end System;
connector CapexConn
  // the amount being a "flow" variables means all contributions
  // sum at a connection point.
  flow Real[3] amount;    
  // every "flow" variable should have a non-flow variable,
  // at least for "physical" connections. Let's add a dummy:
  Real [3] period;

end CapexConn;

  model CapexEmitter
    CapexConn conn;
    Real[3] amount = fill(0, 3);
    Real[3] period;
  equation
// Here you could also have more logic, like computing emitted capex
// depending on the period
    conn.amount = -amount; //negative because of sign of flow direction in connectors
    conn.period = period;
  end CapexEmitter;

model Component "Industrial component block with capex tracking"
  // (you would extend your other components from this to use it)
  outer CapexConn common_connection;  // make outside connection visible
  CapexEmitter capex_info;
equation
  // all Component instances automatically connect, without manual wiring
  connect(capex_info.conn, common_connection);
end Component;

  model FinancialAggregator
    CapexConn agg_conn;
    Real[3] capexsum; 
    Real period[3] = {1,1,1};
  equation
   capexsum = agg_conn.amount;
   period = agg_conn.period;

  end FinancialAggregator;
end SO_69945088;

模拟System给出fin_totals.capexsum{6, 19, 24} 的 a(乐观、估计、悲观)。

这应该给你一个展示原则的起点。


推荐阅读