Clone this wiki locally
This describes what happens within a Circuit object; Overview of Simulator contains the steps leading to and from this moment.
Entrance Point The simulation loops repeatedly calls Circuit::doNonLogic(). From here, Circuit will update itself if any of
- The inputs (Element values, logic inputs, etc) have changed.
- It contains transient Elements (capacitance and inductance) whose models are functions of time.
If the Circuit contains no transient elements, then it will cache the circuit state (voltages on CNodes and currents through CBranches; explained below) for each configuration of LogicIn? values. The cache is stored as a binary tree. [sorry;] Each level corresponds to a LogicInput?, and each branching corresponds to the possible high and low values. At the end of the branches is a Vector storing the currents and voltages of the circuit.
When the configuration of logic inputs changes, then a cache will be used if the circuit state has already been calculated; else the new state will be calculated and stored. The cache becomes invalidated when an Element property (such as resistance) is changed.
This is the the mathematical model behind the circuit simulation. I am not going to describe this here; there are already lots of pages to that effect (e.g. try googling for "modified nodal analysis", Wikipedia, qucs, Swarthmore college). Instead, I will describe how the Circuit, Element, etc classes use it.
On circuit initialisation, each non-ground node (node as in the MNA sense) is assigned a number and an associated CNode. The Elements (which belong to Components and not the Circuit) are then told about the number of their node, from which they store a pointer to the associated CNode object. CNode is used for (a) getting the node number (for the MNA matrix), and (b) getting the previously calculated voltage at that node. The branches (in the MNA sense) are treated similarly to nodes.
The MNA matrix entries are accessed from the Element using the A_g(), A_b(), A_c() and A_d() functions for the g, b, c, and d submatrices respectively. The current/voltage vector b is accessed similarly via b_i() and b_v().
// TODO: Finish