Modelica示例——事件相关函数

监测变化

edge()函数和change()函数常用来监测事件的变化。当变量的值改变时,这两个函数可以给出提示。

edge()函数仅能用于bool变量;change()函数仅能用于bool、整数和字符串型变量。

edge()的等价定义式为:

edge(x) = x and not pre(x);

换句话说,x为真,而之前不为真,则edge为真。

change()的等价定义式为:

change(x) = x <> pre(x);

换句话说,当x取不同于之前值的时候,change为真。

定期生成事件

sample() 是一个内置函数,含有两个参变量,第一个参变量是取样开始的时间,第二个参变量为取样频率。

within ModelicaByExample.DiscreteBehavior.PulseGenerator;
model PulseGenerator "A model that produces pulses at a fixed interval"
  type Time=Real(unit="s");
  parameter Time width=100e-3;
  Boolean pulse;
initial equation
  pulse = false;
equation
  when sample(width,width) then
    pulse = not pre(pulse);
  end when;
end PulseGenerator;

识别分析的起点和终点

initial()

在仿真开始的一瞬间,initial()函数返回true值,这对于连续变量和离散变量设置初值非常有用。

terminal()

在仿真结束的一瞬间,treminal()函数返回true值。常用于调用一个把最终仿真结果写入文件的外部函数



猜你喜欢

转载自blog.csdn.net/bear_miao/article/details/80155966