Modelica建模方式2--基于组件建模和基于子系统建模

假设我们要建立一个齿轮总成的模型,示意简图如下:

Modelica建模方式2--基于组件建模和基于子系统建模

方法一:基于组件的建模

基于组件的建模是直接通过拖曳组件并将组件连接起来设定相应的参数值即可。

Modelica建模方式2--基于组件建模和基于子系统建模

模型建立好后,切换至代码视图(自动生成代码)如下所示:

model Gear_assembly
  extends Modelica.Icons.Example;
  Modelica.Blocks.Sources.Trapezoid trapezoid1(period = 0.8) annotation(
    Placement(visible = true, transformation(origin = {-118, 44}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Mechanics.Rotational.Sources.Torque torque1 annotation(
    Placement(visible = true, transformation(origin = {-70, 44}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Mechanics.Rotational.Components.Inertia inertia1(J = 0.01) annotation(
    Placement(visible = true, transformation(origin = {-30, 44}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Mechanics.Rotational.Components.ElastoBacklash elastoBacklash1(b = 0.00304617, c = 1000) annotation(
    Placement(visible = true, transformation(origin = {10, 44}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Mechanics.Rotational.Components.IdealGear idealGear1(ratio = 4) annotation(
    Placement(visible = true, transformation(origin = {44, 44}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Mechanics.Rotational.Components.Inertia inertia2(J = 0.02) annotation(
    Placement(visible = true, transformation(origin = {82, 44}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Mechanics.Rotational.Components.Inertia inertia3(J = 0.1) annotation(
    Placement(visible = true, transformation(origin = {118, 44}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Mechanics.Rotational.Components.Damper damper1(d = 2) annotation(
    Placement(visible = true, transformation(origin = {54, -4}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
  Modelica.Mechanics.Rotational.Components.Fixed fixed1 annotation(
    Placement(visible = true, transformation(origin = {-70, -18}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
  connect(idealGear1.support, damper1.flange_b) annotation(
    Line(points = {{44, 34}, {44, -4}}));
  connect(damper1.flange_a, torque1.support) annotation(
    Line(points = {{64, -4}, {-70, -4}, {-70, 34}}));
  connect(damper1.flange_b, inertia3.flange_b) annotation(
    Line(points = {{44, -4}, {128, -4}, {128, 44}}));
  connect(torque1.tau, trapezoid1.y) annotation(
    Line(points = {{-82, 44}, {-106, 44}}, color = {0, 0, 127}));
  connect(torque1.flange, inertia1.flange_a) annotation(
    Line(points = {{-60, 44}, {-40, 44}}));
  connect(torque1.support, fixed1.flange) annotation(
    Line(points = {{-70, 34}, {-70, -18}}));
  connect(inertia1.flange_b, elastoBacklash1.flange_a) annotation(
    Line(points = {{-20, 44}, {0, 44}}));
  connect(elastoBacklash1.flange_b, idealGear1.flange_a) annotation(
    Line(points = {{20, 44}, {34, 44}}));
  connect(inertia3.flange_a, inertia2.flange_b) annotation(
    Line(points = {{108, 44}, {92, 44}}));
  connect(inertia2.flange_a, idealGear1.flange_b) annotation(
    Line(points = {{72, 44}, {54, 44}, {54, 44}, {54, 44}}));
end Gear_assembly;

方法二:基于子系统的建模

子系统模型是由组件或其他子系统组成的模型。为了避免冗余,我们可以将常用的子系统封装起来,方便日后建立模型的时候直接使用子系统进行建模。 

在齿轮总成的案例中,我们可以将篮框部分封装成发动机子系统,步骤如下:

step1:使用基于组件建模的方法,将子系统中该有的组件以及组件之间的连接关系做好。

Modelica建模方式2--基于组件建模和基于子系统建模

step2:将子系统和外部通信的接口添加到模型中,并和内部组件连接起来。

Modelica建模方式2--基于组件建模和基于子系统建模

step3:切换到代码视图中,将你需要设置初始参量的参量写在模型的最前面(可以设置默认值),这么做的目的是在后面你重用这个模型时,双击它能够直接显示输入参数页面。注意,代码不用手写,直接进入相应组件的代码视图中复制相应参数行即可。然后将子系统的内部组件的关键字设置为protected,和外界通信的接口和输入参数的关键字设置为public(可省略)。如果想要将子系统设置图标,可以继承发动机的图标。如图所示:

Modelica建模方式2--基于组件建模和基于子系统建模

参数代码的复制方法,以惯性元件的参数为例

Modelica建模方式2--基于组件建模和基于子系统建模

step4:最后我们建立齿轮总成的模型时,我们就可以将子系统直接拖到页面来建立,如下图所示。

Modelica建模方式2--基于组件建模和基于子系统建模

 

参考书籍:Modelica实例教程(作者:Dr.Michael M.Tiller,译者:谢东平)

上一篇:Android Annotation使用快速入门,Android入门


下一篇:Android APT注解扫盲