【发布时间】:2021-04-24 07:21:38
【问题描述】:
只有当 S2 为真时,我才能在 S1=... 语句中实现 y>1 的事件检测,否则会阻止它,因为它只会减慢一般情况下的模拟速度?
model zeroCrossingTest
// BOOLEAN VARIABLE DECLARATIONS
Boolean S1(start=true, fixed=true);
Boolean S2(start=false, fixed=true);
Boolean S3(start=false, fixed=true);
Real y;
equation
der(y) = -y + 2;
// =================
// TRANSITIONS START
S1 = if pre(S2) then (y>1) else
if pre(S1) then not ( (y>0.2) )
else false;
S2 = if pre(S1) then (y>0.2) else
if pre(S2) then not ( (y>0.5) or (y>1) )
else false;
S3 = if pre(S2) then (y>0.5) else
pre(S3);
end zeroCrossingTest;
S1 的零交叉 = if pre(S2) then (y>1).. 仍然在 OpenModelica 中计算(时间状态事件 = 0.69),尽管 pre(S2) 为假
UPDATE1:不会产生不必要事件的替代实现.. 感谢@marco
model zeroCrossingTest_OriginalImplementation
// BOOLEAN VARIABLE DECLARATIONS
Boolean S1(start = true, fixed = true);
Boolean S2(start = false, fixed = true);
Boolean S3(start = false, fixed = true);
Real y;
equation
der(y) = -y + 2;
// =================
// TRANSITIONS START
S1 = pre(S2) and y>1 or
pre(S1) and not y>0.2;
S2 = pre(S1) and y>0.2 or
pre(S2) and not ( y>0.5 or y>1 );
S3 = pre(S2) and y>0.5 or
pre(S3);
end zeroCrossingTest_OriginalImplementation;
UPDATE2:一个更复杂的模型,它给出了布尔变量的相同行为,生成了不必要的状态事件(对于 y>0.7,y>0.8):
model zeroCrossingTest_OriginalImplementation
Boolean S1(start=true, fixed=true);
Boolean S2(start=false, fixed=true);
Boolean S3(start=false, fixed=true);
Boolean S4(start=false, fixed=true);
Boolean S5(start=false, fixed=true);
Boolean S6(start=false, fixed=true);
Real y;
equation
der(y) = -y + 2;
// =================
// TRANSITIONS START
S1 = pre(S2) and (y>1) or
pre(S6) and (y>0.8) or
pre(S1) and not ( (y>0.2) );
S2 = pre(S1) and (y>0.2) or
pre(S2) and not ( (y>0.5) or (y>1) or (y>0.6) );
S3 = pre(S2) and (y>0.5) or
pre(S3);
S4 = pre(S2) and (y>0.6) or
pre(S4) and not ( (y>0.65) );
S5 = pre(S4) and (y>0.65) or
pre(S5) and not ( (y>0.7) );
S6 = pre(S5) and (y>0.7) or
pre(S6) and not ( (y>0.8) );
end zeroCrossingTest_OriginalImplementation;
更新 3:此实现仅生成必要的事件(总共 2 个事件)。有什么理由反对这种方法?
model zeroCrossingTest_OriginalImplementation
Boolean S1(start=true, fixed=true);
Boolean S2(start=false, fixed=true);
Boolean S3(start=false, fixed=true);
Boolean S4(start=false, fixed=true);
Boolean S5(start=false, fixed=true);
Boolean S6(start=false, fixed=true);
Real inS1;
Real inS2;
Real inS3;
Real inS4;
Real inS5;
Real inS6;
Real y;
equation
der(y) = -y + 2;
// =====================
// inState Variables
inS1= if pre(S1) then 1 else 0;
inS2= if pre(S2) then 1 else 0;
inS3= if pre(S3) then 1 else 0;
inS4= if pre(S4) then 1 else 0;
inS5= if pre(S5) then 1 else 0;
inS6= if pre(S6) then 1 else 0;
// =================
// TRANSITIONS START
S1 = pre(S2) and (inS2*y>1) or
pre(S6) and (inS6*y>0.8) or
pre(S1) and not ( (inS1*y>0.2) );
S2 = pre(S1) and (inS1*y>0.2) or
pre(S2) and not ( (inS2*y>0.5) or (inS2*y>1) or (inS2*y>0.6) );
S3 = pre(S2) and (inS2*y>0.5) or
pre(S3);
S4 = pre(S2) and (inS2*y>0.6) or
pre(S4) and not ( (inS4*y>0.65) );
S5 = pre(S4) and (inS4*y>0.65) or
pre(S5) and not ( (inS5*y>0.7) );
S6 = pre(S5) and (inS5*y>0.7) or
pre(S6) and not ( (inS6*y>0.8) );
end zeroCrossingTest_OriginalImplementation;
【问题讨论】:
-
我知道,这不是一个真正的答案,但 Dymola 不会在 0.69 秒时计算事件。只是为了表明似乎可以避免计算......
-
关于原始帖子和更新 1 和 2:正如 Hans Olsson 在他的评论中指出的那样,OpenModelica 的行为很奇怪,因为 if-then-else 方法应该有效。我建议在trac.openmodelica.org/OpenModelica 打开一个错误报告
标签: modelica openmodelica