Modelica中when语句中离散状态机变量的方程太多

Modelica中when语句中离散状态机变量的方程太多,modelica,openmodelica,Modelica,Openmodelica,我有一个精心设计的Modelica模型,其中a有一个状态机变量,当语句: model WhenExample type State = enumeration(first, second, third); State state; initial equation state = State.first; equation when sample(0, 1) then state = State.second; end when; when sample

我有一个精心设计的Modelica模型,其中a有一个状态机变量,当语句:

model WhenExample
  type State = enumeration(first, second, third);

  State   state;
initial equation
  state = State.first;

equation
  when sample(0, 1) then
    state = State.second;
  end when;

  when sample(0, 3) then
    state = State.third;
  end when;
end WhenExample;
在OpenModelica OMC下编译时,出现以下错误:

[1] 16:46:39 Symbolic Error
Too many equations, over-determined system. The model has 2 equation(s) and 1 variable(s).
这有点道理,因为我的单个
state
变量有两个等式。然而,这些方程只适用于离散时间点,对吗


当语句时,我是否需要确保特定变量的所有“操作”仅在单个
语句中发生?

请参见Modelica规范,第8.5节事件和同步:

在第8.6节之前,有一个例子应该对您有所帮助。 下面给出了一些基于此的代码:

model WhenExample
  parameter Integer multiplySample = 3;
  Boolean fastSample, slowSample;
  Integer ticks(start=0);
  type State = enumeration(first, second, third);
  State state(start = State.first);
equation
  fastSample = sample(0,1);
algorithm
  when fastSample then
    ticks := if pre(ticks) < multiplySample then pre(ticks)+1 else 0;
    slowSample := pre(ticks) == 0;
    state := State.second;
  end when;
  when slowSample then
    state := State.third;
  end when;
end WhenExample;
模型,例如
参数整数乘以样本=3;
布尔快速采样,慢速采样;
整数刻度(开始=0);
类型状态=枚举(第一、第二、第三);
状态状态(开始=状态。第一);
方程式
fastSample=样本(0,1);
算法
那么什么时候开始取样呢
滴答声:=如果前置(滴答声)<倍数采样,则前置(滴答声)+1,否则为0;
慢采样:=pre(ticks)==0;
state:=state.second;
结束时;
那么什么时候开始
state:=state.third;
结束时;
例如,结束时;

参见Modelica规范第8.5节事件和同步:

在第8.6节之前,有一个例子应该对您有所帮助。 下面给出了一些基于此的代码:

model WhenExample
  parameter Integer multiplySample = 3;
  Boolean fastSample, slowSample;
  Integer ticks(start=0);
  type State = enumeration(first, second, third);
  State state(start = State.first);
equation
  fastSample = sample(0,1);
algorithm
  when fastSample then
    ticks := if pre(ticks) < multiplySample then pre(ticks)+1 else 0;
    slowSample := pre(ticks) == 0;
    state := State.second;
  end when;
  when slowSample then
    state := State.third;
  end when;
end WhenExample;
模型,例如
参数整数乘以样本=3;
布尔快速采样,慢速采样;
整数刻度(开始=0);
类型状态=枚举(第一、第二、第三);
状态状态(开始=状态。第一);
方程式
fastSample=样本(0,1);
算法
那么什么时候开始取样呢
滴答声:=如果前置(滴答声)<倍数采样,则前置(滴答声)+1,否则为0;
慢采样:=pre(ticks)==0;
state:=state.second;
结束时;
那么什么时候开始
state:=state.third;
结束时;
例如,结束时;

谢谢。将我的
语句放在
算法
部分时,效果会更好。谢谢。把我的
语句放在
算法
部分的时候,实际上更有意义;添加两个when方程使状态有两个方程,Modelica不可能在事件之间创建优先级,因此必须使用
elsewhen
(或如下所示的算法部分)。是;添加两个when方程使状态有两个方程,Modelica不可能在事件之间创建优先级,因此必须使用
elsewhen
(或如下所示的算法部分)。