Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why are currents "measured" on the p pin? #133

Closed
dodoplus opened this issue Dec 17, 2022 · 1 comment
Closed

Why are currents "measured" on the p pin? #133

dodoplus opened this issue Dec 17, 2022 · 1 comment

Comments

@dodoplus
Copy link

Take a look at this simple example - it's the same as in the docs, but with a Current source instead of a Voltage source:

using ModelingToolkit, OrdinaryDiffEq, Plots
using ModelingToolkitStandardLibrary.Electrical
using ModelingToolkitStandardLibrary.Blocks: Constant

R = 1.0
C = 1.0
I = 1.0
@variables t
@named resistor = Resistor(R=R)
@named capacitor = Capacitor(C=C)
@named source = Current()
@named constant = Constant(k=I)
@named ground = Ground()

rc_eqs = [
        connect(constant.output, source.I)
        connect(source.p, resistor.p)
        connect(resistor.n, capacitor.p)
        connect(capacitor.n, source.n, ground.g)
        ]

@named rc_model = ODESystem(rc_eqs, t, systems=[resistor, capacitor, constant, source, ground])
sys = structural_simplify(rc_model)
prob = ODAEProblem(sys, Pair[], (0, 10.0))
sol = solve(prob, Tsit5());

if we inquire the current at the source we get:

sol[source.i]
7-element Vector{Float64}:
1.0
 1.0
 1.0
 1.0
 1.0
 1.0
 1.0

which makes sense.

However, the current on the resistor is:

sol[resistor.i]
7-element Vector{Float64}:
 -1.0
 -1.0
 -1.0
 -1.0
 -1.0
 -1.0
 -1.0

which looks weird.

The current on the resistor should flow in the direction p -> n, and thus be positive.
However, resistor.i is an alias for resistor.p.i which measures the current in the reverse direction.

We could alias i as n.i in OnePort which will then measure the current out of the component.

@ValentinKaisermayer
Copy link
Contributor

Both are subtypes of a OnePort and follow the Modelica standard library. The sign convention is that the flow variable (in this case the current) is positive if the flow flows in the component. And the convention for the pin is "Positive pin (potential p.v > n.v for positive voltage drop v)".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants