pySpice.solver package

This is the core module to the program. Where the circuit’s states is solved. The method used here is called Modified Node Analysis(MNA). For details about this method, please refer here.

pySpice.solver.solver module

pySpice.solver.solver.single_solve(analysis_instance)[source]

Sub-Utility to Solve Function, Solving the States for a Single Analysis Type

Parameters:analysis_instance – internal data structure representing the analysis commands
Returns:A single frame of the output structure illustracted in the figure below
pySpice.solver.solver.solve()[source]

Top Level Encapsulation of the Utilities to Determine the Circuit’s State

Return:
  • watchpoint_data: A 3-D array (illustrated in the figure below), if assume the three coordinate of this array to be output[z][x][y]. Then each slices of z direction represents the output of either DC/AC/TRAN analysis. Within each Z frame, the X direction represent the watchlist item which is parsed in parsing phase and the Y direction contains the values solved in each iteration.
_images/solver_output.png

pySpice.solver.stamp module

pySpice.solver.stamp.make_generator(src, tran_gene)[source]

Make Generator out of the Transinent Stimulates

Because the stimulates for transinent analysis is defines with the voltage/current source, while the time step to transinent analysis is defined in the Transinent analysis command. It is not possible to make the generator describing the voltage/current at certain time point at parsing time. And this task in done here.

This function is the and encapsulation, according to the type of the time varient stimulates, the actually work is assigned to different sub-routines

pySpice.solver.stamp.pulse_generator(td, tr, pw, tf, per, vdd, gnd, tran_gene)[source]

Make generator describing pulse, with rise and falls

pySpice.solver.stamp.sin_generator(freq, vdd, gnd, tran_gene)[source]

Make generator describe sinusoidal variation

pySpice.solver.stamp.stair_generator(vdd, gnd, up_moment, tran_gene)[source]

Make genrator describing a step function

pySpice.solver.stamp.stamp(analysis_type, analysis_instance, MNA, RHS)[source]

Generating MNA and RHS to Represent the Circuit

This function retrieve information from the internal structure to constitute MNA and RHS. It also collects neessary information for doing iterate and converge operations.

Parameters:
  • analysis_type – ‘ac’, ‘dc’ or ‘tran’
  • analysis_instance – internal representation of an analysis command
  • MNA – an initialized matrix, with date type defined
  • RHS – an initialized vector, data type defined
Returns:

  • sweep_flag: a bool flag, indicating if iterate meahanism needed to be actived in the engine.
  • converge_flag: a bool flag, indicating if converge iteration should be actived
  • sweep_list: a list of sweep_item. Each sweep_item contains the information indicating how the solve_engine should change the MNA and RHS in each step of the iteration.
  • converge_list: a list of the element whose beahvior is non-linear.

About the class sweep_item, it is comprised of two part: The second part is a generator. In each iteration, by calling the .next() method to this generator, it will give the value needed to be stamped in this iteration. The first part is a list of tuples, with each tuple’s first element of a coordinate, indicating where to change the stamp. The second element to this tuple is a prefix, you need to multiply the value with this prefix to get the final value to be stamped in this position. Using generator is for memory reducing consideration.

pySpice.solver.engine module

pySpice.solver.engine.solve_engine(sweep_flag, sweep_list, converge_flag, converge_list, watch_list, MNA, RHS, ANS)[source]

Top-Level Encapsulation of the Matrix Solving Utility

This layer realizes the iterate operation support. This function controls to elicit the core matrix-solving utility at each step of the iteraion and at the same time change the stamping of MNA and RHS to represent different initial status of the circuit.

An graphical illustration of this module can be found below

_images/engine.png
Parameters:
  • sweep_flag – described at function stamp
  • converge_flag – described at function stamp
  • sweep_list – described at function stamp
  • converge_list – described at function stamp
  • watch_list – a list describe which node/branch’s value are of interest. When everytime the solution of the circuit is reached, only the data for these points will be kept.
  • MNA – stamped MNA
  • RHS – stamped RHS
  • ANS – The solution to the matrix equation. The reason for introduce it as a parameter is only for simplify the iteration process. Because for some element, the value to stamp for next iteration do not come from the generaor, but the answer of the previous iteration(like dynamic elements in transient analysis), so introducing such a parameter and set it’s initial value to 0 and avoid unnecessary branches.
Returns:

The value of all sweep points to the nodes/branches appeared on the watch_list

pySpice.solver.engine.state_definer(converge_flag, converge_list, MNA, RHS)[source]

Work out the Answer to the matrix equation, make sure the answer converge to the real state

An inner layer of the engine utility, it encapsualte the functionality to solve circuit state by working out the matrix equation. The mechanism to ensure the answer converge is included into this function. : param : Stated in solve_engine function : return: the raw answer of the matrix equation. Thses values are picked out at the outter layer