我写建模程序作为文凭的一部分,我寻找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
答案 0 :(得分:3)
除了缺少分号(end circuit2;)之外,代码解析得很好,是创建复合Modelica模型的正确方法。
答案 1 :(得分: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。
另外一些评论:
我希望这能帮助你更好地理解事情。