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

Modelica燃烧室模型外部输入连接器连接问题求助

解决Modelica燃烧室模型端口替换后的未连接连接器错误

问题根源

  1. 语法错误:方程段中Q = LHV * f_E_fuel * eta_comb末尾缺少分号,导致后续方程解析异常,编译器无法正确识别对prop.p等的赋值,误判为未连接。
  2. 重复赋值冲突:h_L被同时赋值为排气物性prop.h和燃料物性propFuel.h,逻辑矛盾且干扰编译器的变量依赖分析。
  3. 介质状态变量不匹配:燃料端口fuelFlow的介质设置为ph(压力+焓)作为独立变量,但代码中用燃烧室的P和T给propFuel赋值,违背了介质的状态变量定义逻辑。

修复步骤

1. 修复语法错误

在Q = LHV * f_E_fuel * eta_comb末尾添加分号:

Q = LHV * f_E_fuel * eta_comb;

2. 修正重复赋值问题

h_L是排气出口焓,删除h_L = propFuel.h;,避免变量冲突。若需燃料物性计算,使用单独变量存储。

3. 匹配介质状态变量

因为fuelFlow的介质以ph为独立变量,调整propFuel的赋值逻辑,使用燃料端口传入的压力和焓:

propFuel.p = P_fuel;  // 使用燃料端口压力而非燃烧室压力
propFuel.h = h_E_fuel;  // 使用端口传入的焓而非燃烧室温度
propFuel.X = {1};

修正后的完整代码

model CombustionChamberEnthalpies_C
 "Model of combustion chamber with given fuel LHV"
 //   import Modelica.Media.Interfaces.Choices.ReferenceEnthalpy;
 //   constant ReferenceEnthalpy referenceChoice=ReferenceEnthalpy.ZeroAt25C
 //     "Choice of reference enthalpy";
 package ExhaustGas = BasicAeroEngines.Media.ExhaustGas;
 package InletFuel = ExternalMedia.Media.CoolPropMedium (mediumName="Hydrogen", substanceNames={"H2"}, ThermoStates=Modelica.Media.Interfaces.Choices.IndependentVariables.ph);

 outer BasicAeroEngines.Components.Environment environment;

 parameter Modelica.SIunits.SpecificEnergy LHV = 42.8e6 "Lower heating value of fuel";
 Modelica.SIunits.MassFraction X_L[ExhaustGas.nX] "Composition of exhaust gases";
 //ExhaustGas.reference_Xfu
 parameter Modelica.SIunits.Volume V "Internal volume of combustion chamber";
 parameter Modelica.SIunits.Pressure P_start "Start value of pressure";
 parameter Modelica.SIunits.Temperature T_start "Start value of temperature";
 parameter Boolean steadyStateInit = false "Initialize in steady state if true";
 parameter Real ZC "number of carbon atoms in fuel equivalent chemical formula";
 parameter Real ZH "number of hydrogen atoms in fuel equivalent chemical formula";
 final parameter Real a_stoich = ZC + ZH / 4 "stoichiometric ratio of the fuel combustion reaction";
 final parameter Modelica.SIunits.MolarMass MMfuel = ZC * 12 + ZH "Eq. molar mass of the fuel";
 parameter Real eta_comb = 0.995 "Combustion chamber efficiency";
 parameter Real P_Loss = 4 "Relative pressure loss in percentage";
 BasicAeroEngines.Interfaces.AirPort airInlet annotation (Placement(
     visible=true,
     transformation(
       origin={-100,0},
       extent={{-10,-10},{10,10}},
       rotation=0),
     iconTransformation(
       origin={-100,3.55271e-15},
       extent={{-20,-20},{20,20}},
       rotation=0)));
 BasicAeroEngines.Interfaces.ExhaustPort exhaust annotation (Placement(
     visible=true,
     transformation(
       origin={100,2},
       extent={{-10,-10},{10,10}},
       rotation=0),
     iconTransformation(
       origin={100,7.10543e-15},
       extent={{-20,-20},{20,20}},
       rotation=0)));
 BasicAeroEngines.Media.ExhaustGas.BaseProperties prop "Properties of exhaust gas";
 BasicAeroEngines.Media.Hydrogen.BaseProperties propFuel "Properties of fuel (linked to the BaseProperties in CoolPropMedium as this allows a two-phase hydrogen to be used at temperatures below 200K)";

 Modelica.SIunits.MassFlowRate f_E "Entering mass flow rate";
 Modelica.SIunits.MassFlowRate f_L "Leaving mass flow rate";
 Modelica.SIunits.MassFlowRate f_E_fuel "Leaving mass flow rate";
 Modelica.SIunits.SpecificEnthalpy h_E "Entering specific enthalpy";
 Modelica.SIunits.SpecificEnthalpy h_L "Leaving specific enthalpy";
 Modelica.SIunits.SpecificEnthalpy h_E_fuel "Leaving specific enthalpy";
 Modelica.SIunits.Pressure P(start = P_start, stateSelect = StateSelect.prefer) "Exhaust gas pressure";
 Modelica.SIunits.Pressure P_fuel "fuel pressure";
 Modelica.SIunits.Temperature T(start = T_start, stateSelect = StateSelect.prefer) "Exhaust gas temperature";
 Modelica.SIunits.Mass M(stateSelect = StateSelect.avoid) "Total mass";
 Modelica.SIunits.Energy E(stateSelect = StateSelect.avoid) "Total internal energy";
 Modelica.SIunits.Power Q "Thermal power released by combustion";
 Modelica.SIunits.MassFraction X_E[BasicAeroEngines.Media.Air.nX]
   "Composition of air";
 Modelica.SIunits.SpecificHeatCapacity cp_gas "Cp of the flue gas";

 ThermoPower.Water.FlangeC fuelFlow annotation (Placement(transformation(extent=
          {{-10,90},{10,110}}), iconTransformation(extent={{-10,90},{10,110}})));
initial equation 
 if steadyStateInit or environment.onDesignInit then
   der(M) = 0;
   der(E) = 0;
   der(X_L[2:4]) = zeros(ExhaustGas.nX - 1);
 else
   T = T_start;
   P = P_start;
   X_L[2:4] = ExhaustGas.reference_X[2:4];
 end if;
equation 
 // Conservation equations
 der(M) = f_E +  f_E_fuel - f_L;
 der(E) = f_E * h_E - f_L * h_L + f_E_fuel * h_E_fuel + Q;
 //"Nitrogen","Oxygen","Water", "Carbondioxide"
 X_L[1] = 1 - X_L[2] - X_L[3] - X_L[4];
 der(M * X_L[2]) = f_E * X_E[2] - f_L * X_L[2] - a_stoich *  f_E_fuel / MMfuel * ExhaustGas.data[2].MM * 1000 "oxygen";
 der(M * X_L[3]) = (-f_L * X_L[3]) + ZH / 2 *  f_E_fuel / MMfuel * ExhaustGas.data[3].MM * 1000 "water";
 der(M * X_L[4]) = (-f_L * X_L[4]) + ZC *  f_E_fuel / MMfuel * ExhaustGas.data[4].MM * 1000 "carbondioxide";
 // Constitutive equations and fluid properties
 M = prop.d * V;
 E = prop.u * M;
 Q = LHV * f_E_fuel * eta_comb;  // 修复:添加分号
 prop.p = P;
 prop.T = T;
 prop.X = X_L;
 h_L = prop.h;
 cp_gas = ExhaustGas.specificHeatCapacityCp(prop.state);

 // 修复:调整propFuel的状态变量,匹配fuelFlow的ph独立变量
 propFuel.p = P_fuel;
 propFuel.h = h_E_fuel;
 propFuel.X = {1};

 // Boundary conditions
 P = airInlet.P;
 P * (1 - P_Loss / 100) = exhaust.P;
 f_E = airInlet.f;
 f_L = -exhaust.f;
 h_E = inStream(airInlet.h_L);
 exhaust.h_L = h_L;
 exhaust.X_L = X_L;
 X_E = BasicAeroEngines.Media.Air.reference_X;
 airInlet.h_L = 0 "Unused, no flow reversal";

 f_E_fuel = fuelFlow.m_flow;
 h_E_fuel = inStream(fuelFlow.h_outflow);
 P_fuel = fuelFlow.p;

 annotation (
   Icon(graphics={  Ellipse(origin = {0, -1}, fillColor = {129, 170, 194},
           fillPattern =                                                                 FillPattern.Solid, extent = {{-100, 101}, {100, -99}}, endAngle = 360), Polygon(origin = {-2, 19}, fillColor = {218, 74, 25}, pattern = LinePattern.None,
           fillPattern =                                                                                                                                                                                                        FillPattern.Solid, points = {{0, 75}, {-82, 3}, {-14, 35}, {-64, -55}, {-12, -1}, {4, -75}, {16, 1}, {62, -67}, {34, 31}, {82, 17}, {0, 75}})}));
end CombustionChamberEnthalpies_C;

内容的提问来源于stack exchange,提问作者AaronModelica

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.05 01:59:52