CODE
type voltage = Real(final unit = "V");
type current = Real(final unit = "A");
type resistance = Real(final unit = "V/A", final min = 0);
connector pin
voltage v;
flow current i;
end pin;
model R
pin p,n;
parameter resistance R0;
equation
p.v - n.v = p.i * R0;
p.i + n.i = 0;
end R;
model circuit
R R1(R0(max = 1e9) = 1);
pin p, n;
equation
p.v - n.v = 10 "Volt";
connect(p, R1.p);
connect(n, R1.n);
n.v = 0;
p.i + n.i = 0;
end circuit;
what I am trying is to implement a voltage source within the circuit
this may not be wise but I want to understand what happens if one
goes this path.
CODE
>> instantiateModel(elec.circuit)
"fclass elec.circuit
Real R1.p.v(unit = "V");
Real R1.p.i(unit = "A");
Real R1.n.v(unit = "V");
Real R1.n.i(unit = "A");
parameter Real R1.R0(unit = "V/A", min = 0.0, max = 1000000000.0) = 1.0;
Real p.v(unit = "V");
Real p.i(unit = "A");
Real n.v(unit = "V");
Real n.i(unit = "A");
equation
R1.p.v - R1.n.v = R1.p.i * R1.R0;
R1.p.i + R1.n.i = 0.0;
p.v - n.v = 10.0;
n.v = 0.0;
p.i + n.i = 0.0;
(-n.i) + R1.n.i = 0.0;
n.v = R1.n.v;
(-p.i) + R1.p.i = 0.0;
p.v = R1.p.v;
p.i = 0.0;
n.i = 0.0;
end elec.circuit;
"
we have 2 pins within R and 2 pins within the circuit, which makes 8 variables in total
all but the last two equations (n.i=0; p.i=0) can also be found in the previous code
I guess that all flow-prefixed variables will implicitly(?) create such 0-equations
but should not this be the case when the pins (p and n) were left unconnected?
It would be nice if someone could provide some advice.
Regards, Daniel