modelica - 在 Modelica 中,如何在不连接 2 个块的情况下调用不同块中的变量?
问题描述
我们正在对各种工业组件块进行建模,每个块都有 CAPEX、人工成本、维护成本、总 OPEX 等。我们希望有 1 个块,在最好的情况下不连接到其他块,以占总 OPEX,由模型中存在的块引起的总资本支出、总劳动力成本等:块的数量不是固定的。有没有办法不用电线连接块?
如果没有办法,我们找到了使用 RealOutput y 向量的解决方案,如 Modelica.Blocks.Interfaces.MO 中所定义:nout 定义为我们想要加起来的实际变量的数量(例如,如果 CAPEX、OPEX和维护感兴趣,则nout = n = 3)。但是,我们争取 2 点:
- 我们如何通过这个 RealOutput 传递一个矩阵?例如,当 CAPEX 具有 3 个值时,这将很有用:估计值、乐观值和悲观值。
- 我们如何才能在 1 个区块中占用这个 y?现在我们设法使用 n Modelica.Blocks.Math.MultiSum 块来分别占用每个变量,但是有没有办法将它们分别相加,但在同一个块中?
感谢您非常感谢您的帮助和回答!
解决方案
我认为您应该能够使用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(乐观、估计、悲观)。
这应该给你一个展示原则的起点。
推荐阅读
- java - OpenWeatherMap 将 arraylist 转换为 Map
- android - Flutter,RawKeyboardListener 在 Enter 按键后获取文本
- java - 生成 700 万个不重叠的随机字符串
- android - 为什么androidx不支持导航栏?
- java - 如何将我的税率数组应用于我的 junit 测试用例?
- python - 为什么我尝试解压地图会导致“TypeError:'int' object is not iterable”
- c# - 如何让 BIML 编译器允许脚本任务、脚本组件中的 c#6 语言功能
- amazon-web-services - AWS Lambda 检查 DynamoDB KMS 加密
- python - 如何将“datetime-local”输入类型的值从 HTML 返回到字符串中的 python 烧瓶
- greenplum - 分发键如何为GreenPlum分段分配数据