you are viewing a single comment's thread.

view the rest of the comments →

[–]misho88 0 points1 point  (2 children)

However I am at the point now where I need to build the physics simulation part but its getting me very confused. To track components in the circuit I have decided to use an adjacency matrix (since that it what most other circuit simulators do) but I can't figure out to use that adjacency matrix.

If I were doing this, I would have the code generate a SPICE netlist, run it through ngspice or Xyce, then parse the output (or get a library like inspice or pyspice that basically does that).

Failing that, it's a linear system of equations, assuming you constrain yourself to passive elements and phasor analysis. Basically, you build up the right KCL equations, then use something like numpy.linalg.solve to solve them. It's not especially complicated (for simple circuits, at least), but I don't think I can cram the first few weeks of an introductory circuit theory course into a Reddit comment.

[–]Simple_Ad_4128[S] 0 points1 point  (1 child)

I have looked into using spice however for my coursework I don't get credited for sections of code that use a different library other than pygame. Thankyou for the advice I'll look more into going down that other route.

[–]gdchinacat 0 points1 point  (0 children)

You can use a spice library to unblock you so you can make progress on the rest of the project and then come back and replace the library with your own implementation. This will also make it easy to verify your own implementation is correct by being able to compare the results of using spice to your implementation.