Search code examples
modelica

How can I use some model as part of a different model?


I write modeling program as part of diploma and I look for Modelica as input language.

But In the standard specification I can't find how to realize that feature:

For example I have some model:

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

How can I use this model as part of a different model?

Like that:

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 

Edit

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

Solution

  • Apart from semicolons missing (end circuit2;), the code parses fine and is a correct way to create a composite Modelica model.