我正在 Wolfram System Modeler 中创建 Max Per Interval 块。
为了便于解释,我只是将 Max 值设置为 10。
block HighWaterMarkPerInterval
extends Modelica.Blocks.Interfaces.SISO;
protected
Integer index;
Real currentMax;
Real endTimes[1, 45] = [30812532.2, 32037805, 33265581.8, 34493233.8, 35720861.5, 36948483, 38176307.7, 39426940.6, 40654485.4, 41882212.1, 43109672.7, 44337076, 45564265.7, 46793039.6, 48045130.9, 50749960.3, 52040090.6, 53558507.7, 54814537.3, 56331978.2, 57587753.3, 59105952.9, 60362517.8, 61879307.8, 63136031.5, 64363411.4, 65590464.3, 67738027.40000001, 84725789.8, 87831338.09999999, 89030965.40000001, 90258821.8, 91486663.5, 92714210.3, 93941727.7, 95166770.3, 97283519, 99434222.90000001, 100658067.1, 102807019, 104030032.7, 106179193, 107402090, 109550214.2, 110771545.3];
algorithm
if endTimes[1, index] < time then
index := pre(index) + 1;
currentMax := 0;
else
currentMax := 10; // Constant to until I get logic working
end if;
initial algorithm
index := 0;
equation
y = currentMax;
end HighWaterMarkPerInterval;
运行时,索引立即增加到无穷大。我觉得我的逻辑有问题,但我想不通。
该代码应该检查我们是否仍在间隔时间中,并且当我们跨入下一个间隔时间时,它将“currentMax”值设置为零。这将重置我在另一个块中实现的最大值。
任何帮助,将不胜感激。谢谢。
编辑:代码部分表单示例。
model HighWaterMarkPerInterval
annotation(Diagram(coordinateSystem(extent = {{-148.5, -105}, {148.5, 105}}, preserveAspectRatio = true, initialScale = 0.1, grid = {5, 5})));
extends Modelica.Blocks.Interfaces.SISO;
Modelica.Blocks.Math.Max maxblock(u1 = currentMax, u2 = u);
Real flybyEnds[1, 45] = [30813151,32038322,33266015, truncated for space saving...];
Integer index;
Real currentMax;
initial equation
index = 1;
currentMax = 0;
algorithm
// When we are in the interval continually grab max block output and output currentMax
when {time>=flybyEnds[1, index-1], time <=flybyEnds[1,index]} then
currentMax := pre(maxblock.y);
y := currentMax;
end when;
// When we move to the next interval reset current max and move to the next interval
when time > flybyEnds[1, index] then
currentMax := 0;
index := pre(index) + 1;
end when;
end HighWaterMarkPerInterval;