我有parameter
总是从其他参数计算出来,需要public
,以便我的项目中的其他组件模型可以使用它。基本上,它是一个与parameter
对象非常相似的对象中的全局 TIL.SystemInformationManager
。
因为它是计算的,所以在任何对话框中显示它都没有意义;并且使用annotation(dialog(enable=false))
可能会导致混淆和沮丧,因为用户认为总是被禁用是没有充分理由的。
因为它必须是public
,所以我无法使用protected
关键字。
它不能是final
,因为它是由使用它的模型设置的。
最后,它必须是parameter
,而不是变量,因为我用它来标注数组。
这是模型。我们的想法是在sim2
中设置连接器类型ct
,然后计算所有连接器组件中使用的数组n
的大小myArray
:
package VerySimpleSIM
model Sim2
parameter Integer ct = 0 "Connector type";
final parameter Integer n = if (ct > 0) then 2 else 0;
end Sim2;
connector MyConnector "Connector with array size set by global parameter n"
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//This parameter is always set by the component using the connector,
//so I don't want to show it in any dialog box.
parameter Integer n;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Real myArray[n];
end MyConnector;
model Creator
protected
outer Sim2 sim2 "System information manager";
public
MyConnector cnctrB(final n=sim2.n) annotation (Placement(transformation(extent={{80,-10},{100,10}})));
equation
//Create arbitrary values for testing: time + 0.1 * {1,2,...,n}
cnctrB.myArray = {time + 0.1 * i for i in 1:sim2.n};
end Creator;
model Changer
protected
outer Sim2 sim2 "System information manager";
public
MyConnector cnctrA(final n=sim2.n) annotation (Placement(transformation(extent={{-100,-10},{-80,10}})));
MyConnector cnctrB(final n=sim2.n) annotation (Placement(transformation(extent={{80,-10},{100,10}})));
equation
//Output = sin(2 * pi * input)
cnctrB.myArray = Modelica.Math.sin(2 * Modelica.Constants.pi .* cnctrA.myArray);
end Changer;
model TestSim2
inner Sim2 sim2(ct=1) annotation (Placement(transformation(extent={{20,20},{40,40}})));
Changer changer annotation (Placement(transformation(extent={{-10,-10},{10,10}})));
Creator creator annotation (Placement(transformation(extent={{-40,-10},{-20,10}})));
equation
connect(creator.cnctrB, changer.cnctrA) annotation (Line(points={{-21,0},{-9,0}}));
annotation (Icon(coordinateSystem(preserveAspectRatio=false)), Diagram(coordinateSystem(preserveAspectRatio=false)));
end TestSim2;
end VerySimpleSIM;
答案 0 :(得分:3)
您可以使用public
和protected
关键字显示/隐藏参数,如以下示例所示:
model protectedParameter
parameter Real p1=1 "Visible parameter";
parameter Real p2=3.14 "another visible parameter";
protected
parameter Real derivedParameter=p1+p2+p3 "Hidden (protected) parameter";
public
parameter Real p3=2.71 "yet another visible parameter";
equation
// equations from here on
...
end protectedParameter;
或者,您可以将final
关键字放在参数声明的前面,Dymola至少会将其隐藏在对话框中。
祝你好运, Rene Just Nielsen
答案 1 :(得分:0)
使用annotation(dialog(connectorSizing=true))
禁止在对话框中显示参数。例如,改变读取的行
parameter Integer n;
阅读,
parameter Integer n annotation(dialog(connectorSizing=true));