隐藏(抑制显示)全局公共参数对话框(Modelica Dymola)
我有一个隐藏(抑制显示)全局公共参数对话框(Modelica Dymola),modelica,Modelica,我有一个参数,它总是根据其他参数计算出来的,并且需要是公共的,以便我的项目中的其他组件模型可以使用它。基本上,它是对象中的一个全局参数,非常类似于TIL.SystemInformationManager对象 因为它是经过计算的,所以在任何对话框中显示它是没有意义的;使用注释(dialog(enable=false))可能会导致混乱和沮丧,因为用户认为它总是被禁用,没有什么好的理由 因为它必须是public,所以我不能使用protected关键字 它不能是final,因为它是由使用它的模型设置的
参数
,它总是根据其他参数计算出来的,并且需要是公共的
,以便我的项目中的其他组件模型可以使用它。基本上,它是对象中的一个全局参数
,非常类似于TIL.SystemInformationManager
对象
因为它是经过计算的,所以在任何对话框中显示它是没有意义的;使用注释(dialog(enable=false))
可能会导致混乱和沮丧,因为用户认为它总是被禁用,没有什么好的理由
因为它必须是public
,所以我不能使用protected
关键字
它不能是final
,因为它是由使用它的模型设置的
最后,它必须是一个参数
,而不是一个变量,因为我使用它来标注数组的尺寸
这是模型。其思想是在sim2
中设置连接器类型ct
,然后计算所有连接器组件中使用的阵列myArray
的大小n
:
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;
使用注释(dialog(connectorSizing=true))
禁止在对话框中显示参数。例如,更改以下行:
parameter Integer n;
读,
parameter Integer n annotation(dialog(connectorSizing=true));
您可以使用
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感谢您的回复。我的问题是,为了在其他模型中对数组进行尺寸标注,我需要传递这个参数,因此它必须是
public
。如果我仍然缺少什么(很可能),请告诉我。如果我不是,那么我想我应该澄清我的问题。根据Modelica规范connectorSizing
与隐藏结果无关。另外,为了清楚起见,connectorSizing
只能用于Integer
类型。因此,即使可以在一些非标准的后续工具中使用,它一般也不会起作用。同样是一个小的输入错误,注释是对话框
(Modelica区分大小写)。@Dietmar 1。事实上,我的问题“与隐瞒结果无关”。再看看这个问题。2.你在迪莫拉试过这个吗?我刚刚测试了整数
/实数
对话框/对话框
和真
/假
的所有八种组合。关于在对话框中显示参数
,Dymola唯一关心的是true
/false
。我有Dymola版本2016 FD01(32位),2015-10.13。你用的是什么版本?如果所有这些都是真的,你投了我的票,你会考虑删除它吗?