1

我编写建模程序作为文凭的一部分,并寻找 Modelica 作为输入语言。

但在标准规范中,我找不到如何实现该功能:

例如我有一些模型:

model circuit1
Resistor R1(R=10);
Capacitor C(C=0.01);
Resistor R2(R=100);
Inductor L(L=0.1);
VsourceAC AC;
Ground G;
equation
connect (AC.p, R1.p);
connect (R1.n, C.p);
connect (C.n, AC.n);
connect (R1.p, R2.p); 
connect (R2.n, L.p);
connect (L.n, C.n);
connect (AC.n, G.p); 
end circuit1

如何将此模型用作不同模型的一部分?

像那样:

model circuit2
Resistor R1(R=10);
circuit1 circ();                 // ! Define some circuit1
Resistor R2(R=100);
Inductor L(L=0.1);
VsourceAC AC;
Ground G;
equation
connect (AC.p, R1.p); 
connect (R1.n, C.p);
connect (circ.somePin1, AC.n);   // ! Connect circuit1 pins
connect (R1.p, R2.p); 
connect (R2.n, L.p);
connect (L.n, circ.somePin2);    // ! Connect circuit1 pins
connect (AC.n, G.p);
end circuit2 

编辑

model circuit1
extends somePin1;         //
extends somePin2;         //
Resistor R1(R=10);
Capacitor C(C=0.01);
Resistor R2(R=100);
Inductor L(L=0.1);
VsourceAC AC;
Ground G;
equation
connect (AC.p, R1.p);
connect (R1.n, C.p);
connect (C.n, AC.n);
connect (R1.p, R2.p); 
connect (R2.n, L.p);
connect (L.n, C.n);
connect (AC.n, G.p);
connect (AC.n, somePin1); //
connect (R1.n, somePin2); //
end circuit1
4

2 回答 2

3

除了缺少分号(end circuit2;)外,代码解析良好,是创建复合 Modelica 模型的正确方法。

于 2011-09-08T13:02:22.513 回答
3

在我看来,您的问题可以改写为:

如何制作模型以便其他组件可以连接到它?

如果是这样,关键是将您的原始模型(如 Martin 建议的那样)修改为如下所示:

model circuit1
  Resistor R1(R=10);
  Capacitor C(C=0.01);
  Resistor R2(R=100);
  Inductor L(L=0.1);
  VsourceAC AC;
  MyPin somePin1;  // Add some external connectors for
  MyPin somePin2;  // models "outside" this model to connect to
  Ground G;
equation
  connect (somePin1, AC.p); // Indicate where the external models
  connect (somePin2, AC.n); // should "tap into" this model.
  connect (AC.p, R1.p);
  connect (R1.n, C.p);
  connect (C.n, AC.n);
  connect (R1.p, R2.p); 
  connect (R2.n, L.p);
  connect (L.n, C.n);
  connect (AC.n, G.p); 
end circuit1;

现在我认为您可以完全按照您在问题中所写的方式使用 circuit2 。

一些额外的评论:

  1. It isn't clear if you are using the Resistor model in the Modelica Standard Library or your own Resistor model. If you are using the Modelica Standard Library, then replace "MyPin" with "Modelica.Electrical.Analog.Interfaces.PositivePin" (I think that is the name).
  2. Models in Modelica start with capital letters by convention. So to make your model more readable to others, I would suggest renaming your models "Circuit1" and "Circuit2".
  3. Don't forget the semicolons at the ends of the models (as Martin also pointed out).
  4. You definitely DO NOT want to use extends as you have done in your edit. You need to add the pins to your diagram just as you have done with the resistor, ground, etc.

I hope that helps you understand things a bit better.

于 2011-09-09T07:25:20.960 回答