下面的Modelica模型通过了验证:
model TestController
parameter Real off[4] = fill(20, 4) "Radiator turn off threshold";
parameter Real on[4] = fill(19, 4) "Radiator turn on threshold";
discrete Modelica.Blocks.Interfaces.RealInput x[4];
output Modelica.Blocks.Interfaces.BooleanOutput h[4];
protected
Boolean has_heater[4];
equation
has_heater = {false, true, true, false};
algorithm
for j in 1:4 loop
h[j] := has_heater[j] and ((not h[j] and x[j] <= on[j]) or (h[j] and x[j] < off[j]));
end for;
end TestController;
但是,当我尝试模拟它时,在编译的代码中出现错误:
sme.12.0.0_1575385723_1403176131_main.cpp: In function ‘int function_zeroCrossing(f2c_integer*, double*, double*, f2c_integer*, double*, double*, f2c_integer*)’:
sme.12.0.0_1575385367_109695398_main.cpp:347:35: error: ‘$i1_j’ was not declared in this scope
349 | base_array_range_check1(&$tmp0, $i1_j - 1, "[:0:0-0:0]", "x[$i1_j]");
|
一定有一些基本的我不了解的东西,为什么这个循环不模拟?如果我删除h值的第二个子句并使之简单,h[j] := has_heater[j]
则模拟工作正常。
只是一个想法,将其发布为答案是因为评论太长了:也许内联for循环的效果更好,而不是
for j in 1:4 loop
h[j] := has_heater[j] and ((not h[j] and x[j] <= on[j]) or (h[j] and x[j] < off[j]));
end for;
尝试一下
h := {has_heater[j] and ((not h[j] and x[j] <= on[j]) or (h[j] and x[j] < off[j])) for j in 1:4};
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句