List of nodal currents in pycircuit?

26 views
Skip to first unread message

Rogelio E. Cardona-Rivera

unread,
Mar 23, 2012, 11:51:38 AM3/23/12
to pycircuit
Hello,

First off, I'm a big fan of this project. I am trying to find a way
to extract all the currents coming into and out of a node in DC
analysis, and I can't seem to find an intuitive way how to do it.

Currently (no pun intended), I look at the currents from all the
components connected to a node (say 'net01') and then figure out the
currents coming in and out manually. I have gone through the code
myself and I thought I could do it like follows:

for node in c.nodenames.keys():
print 'Current in node ', node, ' is ', res.i(node)

When I do the analysis on a piece of paper, however, the node currents
that I get from the above code snippet don't make sense.



Thanks!
-- Rogelio

Henrik Johansson

unread,
Mar 24, 2012, 9:39:17 AM3/24/12
to pyci...@googlegroups.com, Rogelio E. Cardona-Rivera
Hi Rogelio,

I tried to reproduce your problem using a SymbolicDC analysis but then I found
a bug that made it useless if one wanted to extract currents. After fixing this
bug it's now working. So please use the latest version to run the example
below.

I think there is a misunderstanding (due to lacking documentation) on how
current probing works. In pycircuit, currents are measured at the terminals.
So for example if you have a subcircuit with a resistor R1 which has terminals
plus and minus you use the following syntax: result.i('R1.plus') to calculate
the current going *into* the terminal.

from pycircuit.circuit import *
from sympy import *

c=SubCircuit(toolkit=symbolic)

iin, iout, R1, R2, R3 = symbols('i_in i_out R1 R2 R3')

c['IS'] = IS(gnd, 1, i=iin, toolkit=symbolic)
c['VL'] = VS(3, gnd, v=0, toolkit=symbolic)
c['R1'] = R(1, 2, r=R1, toolkit=symbolic)
c['R2'] = R(2, gnd, r=R2, toolkit=symbolic)
c['R3'] = R(2, 3, r=R3, toolkit=symbolic)

res = SymbolicDC(c, toolkit=symbolic).solve()

# print current going into R2
# by the law of current division you expect R3 / (R2 + R3)
expand(res.i('R2.plus'))

Best regards,

Henrik

severin...@libertysurf.fr

unread,
Mar 28, 2012, 9:39:05 AM3/28/12
to pyci...@googlegroups.com
Dear Group,
I haven't been so productive so far but I had a look inside the JWDB processor.
There's a Mentor function inside the C-API wich gives the type of the
simulation. It is not used inside pycircuit version I have.
So to simply retrieve the analysis type, you may do :

# Dictionary for reserved named dedicated to analysis type
ams_analysis = {
0 : 'TRAN',
1 : 'AC',
2 : 'DC',
3 : 'FFT',
4 : 'SSTAC',
5 : 'TSST',
6 : 'SSTNOISE',
7 : 'FSST',
8 : 'SSTXF',
9 : 'FMODSST',
10: 'TMODSST',
11: 'FOURSST',
12: 'NOISETRAN',
13: 'LSTB',
14: 'SSTJITTER',
15: 'SSTSTABIL',
16: 'NOISE',
17: 'EXTRACT',
18: 'SENSTRAN',
19: 'UNKNOWN'
}

file = "../henjo-pycircuit-5e66d42/pycircuit/post/jwdb/test/data/noise.wdb"
fileid = jwdb.ams_sim_open_read_file(file)
ams_analysis[jwdb.ams_sim_get_current_analysis(fileid)]

Up to ams_2010.2 this was a buggy function (a NOISE simulation gave UNKNOWN).
Mentor support was really reactive on this point. In ams_2010.2d, this was
corrected.
Regards,
Severin.

Reply all
Reply to author
Forward
0 new messages