有人能启发我为什么以下Modelica代码在OpenModelica 1.12.0上生成错误吗?如果删除最后两个连接方程式,则可以正常工作。
class A
Conn cc[3];
Real a(start=0,fixed=true);
Real b(start=0,fixed=true);
Real c(start=0,fixed=true);
equation
der(a) = 1;
der(b) = 2;
der(c) = 3;
connect(a,cc[1].v);
connect(b,cc[2].v); // Remove this to make it work
connect(c,cc[3].v); // Remove this to make it work
end A;
可扩展连接器cc为空:
expandable connector Conn
end Conn;
上面的代码在OpenModelica 1.12.0上产生错误:
[1] 15:07:44 Symbolic Error
Too many equations, over-determined system. The model has 6 equation(s) and 4 variable(s).
[2] 15:07:44 Symbolic Warning
[A: 11:3-11:21]: Equation 5 (size: 1) b = cc[2].v is not big enough to solve for enough variables.
Remaining unsolved variables are:
Already solved: b
Equations used to solve those variables:
Equation 2 (size: 1): der(b) = 2.0
[3] 15:07:44 Symbolic Warning
[A: 12:3-12:21]: Equation 6 (size: 1) c = cc[3].v is not big enough to solve for enough variables.
Remaining unsolved variables are:
Already solved: c
Equations used to solve those variables:
Equation 3 (size: 1): der(c) = 3.0
基本上,我希望有一个可扩展连接器数组,可以根据需要添加不同类型的变量。
关于我只能将“连接器”连接到可扩展连接器,实际上我看到了Modelica Spec 3.4文档说:
All components in an expandable connector are seen as connector instances even if they are not declared as
such [i.e. it is possible to connect to e.g. a Real variable].
所以看来我可以将Real变量连接到OpenModelica中的可扩展连接器,但是,我在JModelica中遇到错误:
Error at line 13, column 11, in file 'A.mo':
Connecting to an instance of a non-connector type is not allowed
此外,我还可以在OpenModeica中将Real变量连接到普通(不可扩展)连接器,但是在JModelica中同样不允许这样做。因此,工具对语言规范的解释会有所不同!
答案 0 :(得分:2)
您不能将Real变量连接到可扩展连接器,它必须是连接器。但是无论如何也不起作用,似乎是一个错误。可行的方法(在OM和Dymola中测试)如下:
class Expandable
expandable connector Conn
Real v[3];
end Conn;
connector RealOutput = output Real "'output Real' as connector";
Conn cc;
RealOutput a(start=0,fixed=true);
RealOutput b(start=0,fixed=true);
RealOutput c(start=0,fixed=true);
equation
der(a) = 1;
der(b) = 2;
der(c) = 3;
connect(a,cc.v[1]);
connect(b,cc.v[2]);
connect(c,cc.v[3]);
end Expandable;