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.
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?