2011-09-08 47 views
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 

回答

3
从分号失踪(完circuit2;)

除此之外,代码解析罚款,是创建一个复合的Modelica模型的正确道路。

+0

但是如何在circuit1中定义circ.somePin1和circ.somePin2?我找不到一些导出变量功能! –

+0

在model1中,添加:MyPin somePin1; –

3

在我看来,你的问题可以表述为:

我怎样才能让一个模型,因此其他部件可以连接到它?

如果是这样,关键是要修改原来的模型(马丁建议)看起来像这样:

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. ,如果你使用的是Modelica标准模型库中的电阻器模型或您自己的电阻器模式不清晰。如果您使用Modelica标准库,则将“MyPin”替换为“Modelica.Electrical.Analog.Interfaces.PositivePin”(我认为是名称)。
  2. Modelica中的模型按照惯例以大写字母开头。所以为了让你的模型对其他人更易读,我建议你将模型重命名为“Circuit1”和“Circuit2”。
  3. 不要忘记模型末尾的分号(正如Martin也指出的那样)。
  4. 你肯定不想使用扩展,因为你在编辑中已经完成了。您需要将引脚添加到您的图表中,就像您使用电阻,接地等一样。

我希望能帮助您更好地理解事情。

相关问题