You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Modelica Buildings库端子连接报错:类型不匹配问题求助

Modelica Buildings库Grid与Line组件连接类型不匹配问题

错误信息

[2] 18:20:02 Translation Error
[Buildings.Electrical.AC.ThreePhasesBalanced.Lines.Line: 4:5-4:47]: Type mismatch in binding terminal_n = grid_connection, expected subtype of Buildings.Electrical.AC.ThreePhasesBalanced.Interfaces.Terminal_n, got type Buildings.Electrical.AC.ThreePhasesBalanced.Sources.Grid

问题描述

使用Modelica Buildings.Electrical库时,尝试将Grid组件连接到Line组件触发上述类型不匹配错误,但连接逻辑和官方示例代码一致,附上我的代码和示例代码,寻求解决方法。

我的代码

model building
  Buildings.Electrical.AC.ThreePhasesBalanced.Sources.Grid grid_connection annotation(
    Placement(visible = true, transformation(origin = {-82, 60}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Buildings.Electrical.AC.ThreePhasesBalanced.Sources.PVSimpleOriented solar_array(A = 10)  annotation(
    Placement(visible = true, transformation(origin = {-106, 12}, extent = {{-10, -10}, {10, 10}}, rotation = 180)));
  Buildings.Electrical.AC.ThreePhasesBalanced.Loads.Resistive building_load annotation(
    Placement(visible = true, transformation(origin = {-4, 12}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Buildings.Electrical.AC.ThreePhasesBalanced.Storage.Battery BESS(EMax = 1800000000, SOC_start = 20)  annotation(
    Placement(visible = true, transformation(origin = {-82, -46}, extent = {{-10, -10}, {10, 10}}, rotation = 270)));
  Buildings.Electrical.AC.ThreePhasesBalanced.Lines.Line grid_line(terminal_n = grid_connection)  annotation(
    Placement(visible = true, transformation(origin = {-40, 12}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));

  Buildings.BoundaryConditions.WeatherData.ReaderTMY3 weather_data(filNam = "weather.mos")  annotation(
    Placement(visible = true, transformation(origin = {-184, 4}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Blocks.Sources.CombiTimeTable load_data(columns = 15:44640, fileName = "data.txt", tableOnFile = true, timeScale = 60, verboseRead = true)  annotation(
    Placement(visible = true, transformation(origin = {29, 13}, extent = {{9, -9}, {-9, 9}}, rotation = 0)));
  Modelica.Blocks.Sources.CombiTimeTable bess_data annotation(
    Placement(visible = true, transformation(origin = {-48, -46}, extent = {{8, -8}, {-8, 8}}, rotation = 0)));
equation
  connect(BESS.terminal, grid_line.terminal_n) annotation(
    Line(points = {{-82, -36}, {-48, -36}, {-48, 12}, {-50, 12}}, color = {255, 255, 255}));
  connect(grid_line.terminal_n, BESS.terminal) annotation(
    Line(points = {{-50, 12}, {-82, 12}, {-82, -36}}));
  connect(grid_line.terminal_n, solar_array.terminal) annotation(
    Line(points = {{-50, 12}, {-96, 12}}));
  connect(grid_line.terminal_p, building_load.terminal) annotation(
    Line(points = {{-30, 12}, {-14, 12}}));
  connect(load_data.y, building_load.Pow) annotation(
    Line(points = {{19, 13}, {13.5, 13}, {13.5, 12}, {6, 12}}, color = {0, 0, 127}));
  connect(bess_data.y, BESS.P) annotation(
    Line(points = {{-56, -46}, {-72, -46}}, color = {0, 0, 127}));
  connect(weather_data.weaBus, solar_array.weaBus) annotation();
  annotation(
    uses(Buildings(version = "9.1.0"), Modelica(version = "4.0.0")));
end building;

官方示例代码

within Buildings.Electrical.Examples;
model RenewableSources
  AC.ThreePhasesBalanced.Sources.Grid gri(
    f=f,
    V=V_nominal,
    phiSou=0) "Grid model that provides power to the system"
  AC.ThreePhasesBalanced.Lines.Line line1(mode=Buildings.Electrical.Types.CableMode.automatic,
      l=1500,
    V_nominal=V_nominal,
    P_nominal=7*(PLoa_nominal + PSun) + PWin) "Electrical line"
              annotation (Placement(transformation(extent={{-80,10},{-60,30}})));
equation
  connect(gri.terminal, line1.terminal_n) annotation (Line(
      points={{-90,40},{-90,20},{-80,20}},
      color={0,120,120},
      smooth=Smooth.None));

解决方法

核心错误是直接将Grid组件实例绑定给Line的terminal_n参数,而非通过connect语句连接组件的接口:

  1. 移除Line定义中的terminal_n = grid_connection绑定,修改后的Line定义:
Buildings.Electrical.AC.ThreePhasesBalanced.Lines.Line grid_line annotation(
  Placement(visible = true, transformation(origin = {-40, 12}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  1. 在equation块中添加Grid与Line的接口连接语句:
connect(grid_connection.terminal, grid_line.terminal_n) annotation(
  Line(points = {{-82, 60}, {-82, 12}, {-50, 12}}, color = {255, 255, 255}));
  1. 清理冗余连接:Modelica不需要双向定义连接,删除重复的connect(grid_line.terminal_n, BESS.terminal)语句,保留单方向连接即可。

  2. 修正拓扑冲突:当前代码中grid_line.terminal_n同时连接了BESS、solar_array和Grid,会导致电气拓扑错误,建议使用Buildings.Electrical.AC.ThreePhasesBalanced.Buses.Bus组件汇聚多个接口后,再连接到Line。

内容的提问来源于stack exchange,提问作者Luis Enriquez-Contreras

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 23:12:28