1
\$\begingroup\$

I am modeling a mechanical process by using an electrical analogue. I need to calculate the loop (mesh) currents, then I can see if any mesh current is greater than a predetermined value \$\lambda\$. There are voltage bars connected to the top, and the bottom is connected to GND. Initially the voltage, \$_{VCC}\$ is 10V. Each edge is a \$ 1 \Omega \$ ideal resistor.

The way I thought to do it was use Kirchoff's voltage law for each loop

\$\sum^N_{k=0} V_k = 0\$.

then solve the system of equations using: I = np.linalg.solve(Z,V)

where Z is my impedance matrix and V is my voltage matrix.

Rectangular grid of resistor, coordinates on nodes

So if you look a the picture above there should be four loops, but networkx, a graph theory based library for python3, returns using nx.cycle_basis(G):

[(1, 1), (1, 2), (0, 2), (0, 1)]
[(1, 1), (2, 1), (2, 2), (1, 2)]
[(0, 0), (1, 0), (2, 0), (2, 1), (2, 2), (1, 2), (0, 2), (0, 1)]
[(1, 1), (1, 0), (2, 0), (2, 1)]

which is WRONG.

[(0, 0), (1, 0), (2, 0), (2, 1), (2, 2), (1, 2), (0, 2), (0, 1)] 

should be:

[(1,1), (0,1), (0,0), (1,0)]

to get the mesh in the bottom left corner.

I know how to calculate the resistance between two points by using the Kronecker product in numpy, but I don't see what use that would be to me because I need the current and to solve Ohm's law I need the voltage between the nodes.

So yes my question is how can I efficiently calculate the branch currents of a massive resistor network?

\$\endgroup\$
  • \$\begingroup\$ Take a look at this recent question. I am not claiming it is exactly the same as yours, just that it is possibly helpful. electronics.stackexchange.com/questions/342340/… \$\endgroup\$ – mkeith Dec 21 '17 at 20:48
  • \$\begingroup\$ If you build your model using spice circuit syntax, you can probably feed it to spice and let spice solve it for you. It is not exactly elegant, but it would be relatively easy and fast to implement. And the input and output of spice is relatively easy to deal with. \$\endgroup\$ – mkeith Dec 21 '17 at 20:49
  • \$\begingroup\$ See: Program to Solve Finite Grid \$\endgroup\$ – jonk Dec 21 '17 at 21:35
  • \$\begingroup\$ Is VCC/GND applied to just 0,0 / 2,2, or is VCC going to 0,0; 0,1; 0,2? \$\endgroup\$ – pscheidler Dec 21 '17 at 21:53
  • \$\begingroup\$ @pscheidler Well in my code that works for just 3 resistors and one voltage source I have the voltage source between the nodes (0,2) and (0,1), and I assumed the bottom rail is connected to GND. \$\endgroup\$ – Lewis Dec 21 '17 at 22:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.