This module provides the methods required to perform a transient analysis.

Our problem can be written as:

\[D \cdot dx/dt + MNA \cdot x + T_v(x) + T_t(t) + N = 0\]

We need:

  1. \(MNA\), the static Modified Nodal Analysis matrix,
  2. \(N\), constant DC term,
  3. \(T_v(x)\), the non-linear DC term
  4. \(T_t(t)\), the time variant term, time dependent-sources, to be evaluated at each time step,
  5. The dynamic \(D\) matrix,
  6. a differentiation method to approximate \(dx/dt\).
check_step(tstep, time, tstop, HMAX)[source]

Checks the step for several common issues and corrects them.

The following problems are checked:

  • the step must be shorter than HMAX. In the context of a transient analysis, that usually is the time step provided by the user,
  • the step must be equal or shorter than the simulation time left (ie stop time minus current time),
  • the step must be longer than options.hmin, the minimum allowable time step. If the step goes below this value, convergence problems due to machine precision will occur. Typically when this happens, we halt the simulation.


tstep : float
The time step, in second, that needs to be checked.
time : float
The current simulation time.
tstop : float
The time at which the simulation ends.
HMAX : float
The maximum allowable time step.


tstep : float
The step provided if it passes the tests, a shortened step otherwise.
Raises:ValueError – When the step is shorter than option.hmin.
class dfbuffer(length, width)[source]

This is a LIFO buffer with a method to read it all without deleting the elements.

Newer entries are added on top of the buffer. It checks the size of the added elements, to be sure they are of the same size.


length : int
The length of the buffer. Samples are added at index 0, shifting all the previous samples back to higher indices. Samples at an index equal to length (or higher) are discarded without notice.
width : int
The width of the buffer, every time add() is called, it must be to add a tuple of the same length as this parameter.

Add a new data point to the buffer.


atuple : tuple of floats
The data point to be added. Notice that the length of the tuple must agree with the width of the buffer.
Raises:ValueError – if the provided tuple and the buffer width do not



Read out the contents of the buffer, without any modification

This method, in the context of a transient analysis, returns a vector suitable for a differentiation formula.


vec : list of tuples

a list of tuples, each tuple being composed of width floats. In the context of a transient analysis, the list (or vector) conforms to the specification of the differentiation formulae. That is, the simulator stores in the buffer a list similar to:

[[time(n), x(n), dx(n)], [time(n-1), x(n-1), dx(n-1)], ...]

This shouldn’t be used to determine if the buffer has enough points to use the df _if_ you use the step control. In that case, it holds even the points required for the FF.

generate_D(circ, shape)[source]

Generates the D matrix

For every time t, the D matrix is used (elsewhere) to solve the following system:

\[D dx/dt + MNA x + N + T(x) = 0\]

It’s easy to set up the KCL law for the voltage unknowns, capacitors introduce stamps just like resistors do in the MNA and we know that row 1 refers to node 1, row 2 refers to node 2, and so on

Inductors generate, together with voltage sources, ccvs, vcvs, a additional line in the MNA matrix, and hence in D too.

The current flowing through the device gets added to the x vector.

In the case of an inductors, we have:

\[V(n_1) - V(n_2) - V_L = 0\]


\[V_L = L dI/dt\]

That’s 0 (zero) in DC analysis, but not in transient analysis, where it needs to be differentiated.

To understand on which line does the inductor’s L*dI/dt go, we use the order of the elements in circuit: first are all voltage lines, then the current ones in the same order of the elements that introduce them. Therefore, we need to access the circuit (circ).


circ : circuit instance
The circuit instance for which the \(D\) matrix is computed.
shape : tuple of ints
The shape of the reduced \(MNA\) matrix, D will be of the same shape.


D : ndarray
The unreduced D matrix.
import_custom_df_module(method, print_out)[source]

Imports a module that implements differentiation formula through imp.load_module Parameters: method: a string, the name of the df method module print_out: print to stdout some verbose messages

Returns: The df module or None if the module is not found.

transient_analysis(circ, tstart, tstep, tstop, method=u'TRAP', use_step_control=True, x0=None, mna=None, N=None, D=None, outfile=u'stdout', return_req_dict=None, verbose=3)[source]

Performs a transient analysis of the circuit described by circ.

Parameters: circ: circuit instance to be simulated. tstart: start value. Better leave this to zero. tstep: the maximum step to be allowed during simulation or tstop: stop value for simulation method: differentiation method: ‘TRAP’ (default) or ‘IMPLICIT_EULER’ or ‘GEARx’ with x=1..6 use_step_control: the LTE will be calculated and the step adjusted. default: True x0: the starting point, the solution at t=tstart (defaults to None, will be set to the OP) mna, N, D: MNA matrices, defaulting to None, for big circuits, reusing matrices saves time outfile: filename, the results will be written to this file. “stdout” means print out. return_req_dict: to be documented verbose: verbosity level from 0 (silent) to 6 (very verbose).