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

Modelica建模报错:DAE索引缩减失败,无法对自定义函数求导

问题描述

运行Modelica模型时遇到DAE降阶失败的错误,报错信息如下:

Failed to differentiate the equation
T = Water.ph.T_ph(Ps, Hs*1000, 0);

in order to reduce the DAE index.

Cannot find differentiation function:
Water.ph.T_ph(Ps, Hs*1000, 0)
with respect to time

Failed to reduce the DAE index.

相关代码片段:

V1*der(Ps)=Rs*T*(Ge+Gaux+Geved-Gvo-Gn)/3600;
  rou2=Water.pT.d_pT(Ps,T,0);
  der(rou2*V1*Hs)=(Ge*He+Gaux*Haux+Geved*h1-Gvo*Hs-Gn*Hs)/3600;
function T_ph
  "Return thermodynamic state as function of p, h and phase"
    extends Modelica.Icons.Function;
    input Water.total.Medium.AbsolutePressure p "Pressure";
    input Water.total.Medium.SpecificEnthalpy h "Enthalpy";
    input Water.total.Medium.FixedPhase phase=0
    "2 for two-phase, 1 for one-phase, 0 if not known";
    output Water.total.Medium.Temperature T;
protected 
       Water.total.Medium.ThermodynamicState state;
algorithm 
  state := Water.total.Medium.setState_ph(
        p,
        h,
        phase);
     T:=state.T;
end T_ph;
function total

package Medium
extends ExternalMedia.Media.CoolPropMedium(
    mediumName = "Water")
end Medium;

end total;
解决方案

问题核心是自定义的T_ph函数使用algorithm段实现,编译器无法自动推导其对时间的符号导数,导致DAE降阶失败。以下是几种解决方法:

  • 优先使用ExternalMedia内置可微分函数
    直接替换自定义的T_ph为库中提供的temperature_ph函数,该函数已内置符号可微分支持:

    T = Water.total.Medium.temperature_ph(Ps, Hs*1000, 0);
    
  • 将自定义函数改为equation段实现
    如果必须保留自定义函数,把algorithm替换为equation,让编译器能自动解析导数逻辑(仅适用于无顺序依赖的纯数学关系):

    function T_ph
      "Return thermodynamic state as function of p, h and phase"
      extends Modelica.Icons.Function;
      input Water.total.Medium.AbsolutePressure p "Pressure";
      input Water.total.Medium.SpecificEnthalpy h "Enthalpy";
      input Water.total.Medium.FixedPhase phase=0
        "2 for two-phase, 1 for one-phase, 0 if not known";
      output Water.total.Medium.Temperature T;
    protected 
      Water.total.Medium.ThermodynamicState state;
    equation 
      state = Water.total.Medium.setState_ph(p, h, phase);
      T = state.T;
    end T_ph;
    
  • 调整方程结构避免循环导数依赖
    重新整理方程逻辑,比如将der(rou2*V1*Hs)展开,或者直接用状态量关联物性参数,减少对自定义函数输出的导数依赖,降低DAE求解的复杂度。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.22 21:30:28