首页 > 解决方案 > 具有非参数测试的 if 方程中的所有分支必须具有相同数量的方程 - Modelica

问题描述

我在 Modelica 上收到一条错误消息:

具有非参数测试的 if 方程中的所有分支必须具有相同数量的方程

错误的来源是以下代码部分:

equation
  if der(Posit2.s)<=0 then
    pressure=4e5+((500e5-4e5)/0.0111)*(0.0111-Posit2.s);
  end if;

你知道如何处理这个错误吗?

标签: modelicaopenmodelica

解决方案


你需要一个 else,所以显而易见的想法是说压力不会改变:

 equation
    if der(Posit2.s)<=0 then
           pressure=4e5+((500e5-4e5)/0.0111)*(0.0111-Posit2.s);
    else
           der(pressure)=0;
    end if;

但是,由于索引问题,这可能无法编译。一种可能性是手动减少索引并编写如下内容:

 initial equation
    if der(Posit2.s)<=0 then
           pressure=4e5+((500e5-4e5)/0.0111)*(0.0111-Posit2.s);
    else
           pressure=4e5;
    end if;
 equation
    if der(Posit2.s)<=0 then
           der(pressure)=((500e5-4e5)/0.0111)*(-der(Posit2.s));
    else
           der(pressure)=0;
    end if;

请注意,该等式具有der(pressure)=...*der(Posit2.s);- 由于手动索引减少。


推荐阅读