From this discussion about Spice internals, it looks that Spice builds a matrix for a netlist. I wonder how it does it in detail, e.g. for to write a simple parser.
E.g. :
R1 1 2 4
V1 2 1 2
How can a data structure of this circuit look like?
Best Answer
I haven't quite looked at the SPICE source code, but I've looked at GNUCAP more than a few times.
Generally, there will be a base class (or structure) for any component that you would put in a circuit. Then, components like resistors and voltage sources can inherit from this base class.
Here's what it might look like in C++
And the 'doing stuff' section is entirely up to you. I'd recommend learning about the Visitor design pattern, if you are going to be analyzing or modifying the circuit structure in anyway.
You could probably add another base class called
Component
, that will be inherited byResistor
andVoltageSource
that contains thevalue
member, and trim off a few lines of code (if you wanted to).