Help - Search - Members - Calendar
Full Version: is such a construct allowed?
Modelica Forum > Modelica > Modelica
daniel@ka
Hello @all,

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
daniel@ka
CODE

    model R
        pin p,n;
        parameter resistance R0;
    equation
        p.v - n.v = p.i * R0;
        p.i + n.i = 0;
    end R;
    
    model ground
        pin n;
    equation
        n.v = 0;
    end ground;
    
    model V
        pin p,n;
        parameter voltage V0;
    equation
        p.v - n.v = V0;
        p.i + n.i = 0;
    end V;
    
    model circuit_working
        V V1(V0 = 1);
        R R1(R0 = 1);
        ground gnd;
    equation
        connect(V1.p, R1.p);
        connect(V1.n, R1.n);
        connect(V1.n, gnd.n);          
    end circuit_working;

    model circuit_not_working
        V V1(V0 = 1);
        R R1(R0 = 1);
        pin n;
    equation
        n.v = 0;
                connect(V1.n, n);
        connect(V1.p, R1.p);
        connect(V1.n, R1.n);
    end circuit_not_working;


this is very similar to my previous problem
I think it is obvious what the code should do
In my opinion both variants are equivalent in terms of mathematical description
(I am using the openmodelica 3.0)

I would like to ask somebody to try this example in dymola (as I do not have access to it)
and to report the results.

Regards, Daniel
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.