-
Notifications
You must be signed in to change notification settings - Fork 20
User's guide
The SpicePy wiki provides the minimum information to use the code.
SpicePy makes use of a netlist to describe the circuit. The notation used is very similar to the SPICE one. A netlist is a text file (common extensions are .net or .cir).
In a netlist every component is defined as:
<label><X> <node+> <node-> <value> <other optional information>
where:
-
<label><X>
is thelabel
of the component andX
is an identification number -
<node+>
is one node to which the component is connected. The sign+
indicates that it is conventionally the positive node -
<node->
is one node to which the component is connected. The sign-
indicates that it is conventionally the negative node -
<value>
is the value of the component -
<other optional information>
can be, for example, initial conditions for dynamic components of the phase of a generator to be used in AC problems
To give an example, a 5.6 ohm resistor caller R3
connected between nodes 1 and 5 is described in the netlist by:
R3 1 5 5.6
The analysis is defined using standard SPICE simulation commands. The simulation command have to be included at the end (last line) of the netlist. Right now SpicePy supports only two kind of simulation:
- Operating point analysis: used to solve direct current (DC) networks and also to compute the initial conditions of circuits including dynamic componets
- AC analysis: used to solve AC network in frequency domanin
To perform an operating point analysis it is sufficient to add at the end of the netlist the following simulation command:
.op
The AC analysis is defined by the following simulation command:
.ac type n f1 f2
where:
-
.ac
indicates the AC analysis -
type
indicates how to create the frequency range. It can be:-
lin
for a linear sweep withn
points between frequenciesf1
andf2 (> f1)
-
dec
for a logarithmic sweep (by decades) withn
points between frequenciesf1
andf2 (> f1)
-
oct
for a logarithmic sweep (by octaves) withn
points between frequenciesf1
andf2 (> f1)
-
Right now SpicePy only supports a single frequency simulation using the following notation:
.ac lin 1 f f
The transient analysis is defined by the following simulation command:
.tran step tend
where:
-
.tran
indicates the transient analysis -
step
is the time step for numerical integration -
tend
set the final integration time (i.e. the transient is analyzed in the range 0 - tend)
In transient analysis it is better to plot (rather than print) the results. Therefore, there is another command that must be included in the network to specify what to plot:
.plot v(<label><X>) ... i(<label><X>) ...
where:
-
.plot
indicates the intention to plot something -
v(<label><X>)
means the voltage across the component<label><X>
(same notation as in the component description) -
i(<label><X>)
means the current through the component<label><X>
(same notation as in the component description)
The user can specify as many variable as desired and it not required any specific order. In the final plot voltages are grouped in the same plot and separated by currents which are grouped in another plot. Voltages and currents appear in the plot according to the order defined by the user in the .plot
command.
Since all information about the circuit and the problem type are included in the netlist. The code to solve the circuit is always the same.
The following modules have to be imported.
import netlist as ntl # module to read the netlist
from netsolve import net_solve # module to solve the circuit
import netprint as prn # modeule to print results
Given a netlist in the file circuit.net
, the following code provides the circuit solution using the modified nodal analysis:
net = ntl.Network('circuit.net') # read the netlist
net_solve(net) # compute the circuit solution
Branch quantities, voltages and currents, can be calculated using the methods of the python class Network:
net.branch_voltage() # compute branch voltages
net.branch_current() # compute branch currents
Branch quantities can be eventually printed netprint
module:
prn.print_branch_voltage(net) # print all branch voltages
prn.print_branch_current(net) # print all branch currents
prn.print_branch_quantity(net) # print both voltages and currents
More details can be found in the examples page.