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

私には思えますが、あなたの質問は次のように言い換えることができます。

他のコンポーネントを接続できるようにモデルを作成するにはどうすればよいですか?

その場合、キーは元のモデルを (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. Modelica 標準ライブラリの Resistor モデルを使用しているか、独自の Resistor モデルを使用しているかは明確ではありません。Modelica 標準ライブラリを使用している場合は、「MyPin」を「Modelica.Electrical.Analog.Interfaces.PositivePin」に置き換えます (名前だと思います)。
  2. Modelica のモデルは、慣例により大文字で始まります。したがって、モデルを他の人が読みやすくするために、モデルの名前を「Circuit1」および「Circuit2」に変更することをお勧めします。
  3. モデルの最後にあるセミコロンを忘れないでください (Martin も指摘しています)。
  4. 編集で行ったように extends を使用したくないことは間違いありません。抵抗やグランドなどで行ったのと同じように、ピンをダイアグラムに追加する必要があります。

物事をよりよく理解するのに役立つことを願っています。

于 2011-09-09T07:25:20.960 に答える
3

セミコロンの欠落 (end circuit2;) を除けば、コードは適切に解析され、複合 Modelica モデルを作成する正しい方法です。

于 2011-09-08T13:02:22.513 に答える