## target_spice: election of "node 0"

A valid spice circuit must have a ground network, which is considered potential 0. All other voltages are normally measured against this potential. In spice terminology this is called node 0.

The plugin export_spice will look for a net that has the spice/gnd attribute set. When found, this net is renamed to 0 on the output (but not in the abstract model).

The target_spice plugin attempts to guarantee there is a spice/gnd net at the end of the compilation process. First it looks through all nets to find one that already has spice/gnd set during compilation (e.g. from the concrete model). This gives the user a chance to explicitly select a gnd net by setting a wirenet attribute. This is useful for circuits with multiple different ground networks (digital ground, analog ground, power ground, etc.)

If target_spice did not find a spice/gnd net, it will elect one and set the spice/gnd attribute on the elected net. The election scores each net and the net with the highest score wins. If the net name is "gnd" (not case sensitive), it gets the highest score (and confidence). Else if it contains "gnd" or "GND" (case sensitive), it gets the second highest score. Else the score is proportional to the number of ports connected to the net (in other words, it is assumed that the net with the most number of connections is the best choice for gnd). When the code was not confident in the choice, an error message is also generated, asking the user to explicitly set spice/gnd.

In practice, for the simple cases, for majority of the boards, this works without any network attribute, because there will be a net called "gnd" or "GND", which will get the highest score with high confidence. If the situation is more complex, the code will throw an error and the user should add the spice/gnd attribute to a net.