Utility classes from the analyses package are documented here.
This module contains basic classes/functions for nodal analysis. These are part of the standard netlist analyses but they can also be used independently.
Calculates the DC part of currents and Jacobian
Matrices and vectors (G, Jac, s) are allocated here. This is to centralize all allocations and avoid repetitions.
Requires a nodal-ready Circuit instance (ckt) instance (see make_nodal_circuit())
Retrieve guesses from vPortGuess in each nonlinear device
Returns a guess vector
Calculate total current
returns iVec = G xVec + i(xVec)
xVec: input vector of nodal voltages.
iVec: output vector of currents
Calculate total current and Jacobian
Returns (iVec, Jac):
iVec = G xVec + i(xVec)
Jac = G + (di/dx)(xVec)
xVec: input vector of nodal voltages.
iVec: output vector of currents
Jac: system Jacobian
Get the source vector considering only the DC source components
Re-generate linear matrices
Used for parameter sweeps
Save nodal voltages in terminals and set OP in elements
The following information is saved:
- The nodal voltage vector for the circuit (self.xop)
- The nodal voltage in each terminal (term.nD_vOP)
- The control port voltages in each nonlinear device (elem.nD_xOP)
Set external currents applied to subcircuit
extIvec: vector of external currents. Length of this vector should be equal to the number of external connections. The sum of all currents must be equal to zero (KCL)
This will fail if not a subcircuit
Keeps track of transient analysis equations.
This class only sets up transient equations. Equations are solved elsewhere. Circuit history required for numerical integration is kept by an integration method class.
Matrices and vectors (G, C, JacI, JacQ, s, etc.) are allocated here. This is to centralize all allocations and avoid repetitions.
Requires a nodal-ready Circuit instance (ckt) instance (see make_nodal_circuit()). The circuit is not modified, one circuit can be shared amongst several TransientNodal objects.
Accept xVec for current time step and store state
Calculate total current
returns iVec = G’ xVec + i’(xVec)
xVec: input vector of nodal voltages.
iVec: output vector of currents
Calculate total current and Jacobian
Returns (iVec, Jac):
iVec = G' xVec + i'(xVec)
Jac = G' + (di'/dx)(xVec)
xVec: input vector of nodal voltages.
iVec: output vector of currents
Jac: system Jacobian
Returns system rhs vector: s’
s’ includes source vector, charge history and convolution contributions
ctime: current time
Get the source vector considering DC and TD source components
ctime: current time.
Re-generate linear matrices
Used for parametric sweeps
Set initial conditions (ICs)
h: (initial) time step
Retrieves ICs from DC operating point info in elements
Recalculate Gp from im information
Recalculate qVec for a given value of xVec
Use linear interpolation to find v(t-td)
td: time delay vp: current port voltage h: current time step tsV: vector with past time steps vpV: vector with past voltage samples
returns (v(t-td), deriv_coeff)
Add attributes to Circuit/Elements/Terminals for nodal analysis
This functionality should be useful for any kind of nodal-based analysis (DC, AC, TRAN, HB, etc.)
Takes a Circuit instance (ckt) as an argument. If the circuit contains the ‘gnd’ node, it is used as the reference. Otherwise an indefinite matrix with no reference is assumed.
If termList is provided, the terminals in that list are assigned the first positions in the NAM matrix. Row/Column numbers for external terminals are stored in the nD_extRClist attribute.
New attributes are added in Circuit/Element/Terminal instances. All new attributes start with nD_
Process element for nodal analysis
Restore RC numbers in internal terminals
Assumption is number of internal terminals is the same
Set up and solve AC equations
ckt: nodal-ready Circuit instance (ckt) instance with OP already set
fvec: frequency vector. All frequencies must be different from zero
DC solution not calculated here as it needs special treatment and that solution is already obtained by the OP analysis.
Set results in terminals in vectors named aC_V
Returns a matrix with results. Dimension: (nvars x nfreq)
Set current contributions of Jac into M
Set current contributions of current into iVec
Set transconductance/transcapacitance quad
G: target matrix
Calculate input port voltage xin
This module contains basic classes/functions for nodal analysis. These are part of the standard netlist analyses but they can also be used independently.
This implementation uses Scipy sparse matrices. By default SuperLU is used to factor the matrix. UMFPack could be used, but SuperLU seems to be faster. The main matrix is built in triplet format (Scipy coo_matrix format).
Many of the functions are directly imported from the nodal module to avoid redundancy. Some of these could be optimized for better performance.
Calculates the DC part of currents and Jacobian
Matrices and vectors (G, Jac, s) are allocated here. This is to centralize all allocations and avoid repetitions.
Requires a nodal-ready Circuit instance (ckt) instance (see make_nodal_circuit())
Retrieve guesses from vPortGuess in each nonlinear device
Returns a guess vector
Calculate total current
returns iVec = G xVec + i(xVec)
xVec: input vector of nodal voltages.
iVec: output vector of currents
Calculate total current and Jacobian
Returns (iVec, Jac):
iVec = G xVec + i(xVec)
Jac = G + (di/dx)(xVec)
xVec: input vector of nodal voltages.
iVec: output vector of currents
Jac: system Jacobian
Get the source vector considering only the DC source components
Re-generate linear matrices (and Jacobian structure)
Used for parameter sweeps
Save nodal voltages in terminals and set OP in elements
The following information is saved:
- The nodal voltage vector for the circuit (self.xop)
- The nodal voltage in each terminal (term.nD_vOP)
- The port voltages in each nonlinear device (elem.nD_xOP)
- The operating point (OP) information in nonlinear devices
Set current contributions of Jac into M (in coo format)
Set external currents applied to subcircuit
extIvec: vector of external currents. Length of this vector should be equal to the number of external connections. The sum of all currents must be equal to zero (KCL)
This will fail if not a subcircuit
Keeps track of transient analysis equations.
This class only sets up transient equations. Equations are solved elsewhere. Circuit history required for numerical integration is kept by an integration method class.
Matrices and vectors (G, C, JacI, JacQ, s, etc.) are allocated here. This is to centralize all allocations and avoid repetitions.
Requires a nodal-ready Circuit instance (ckt) instance (see make_nodal_circuit()). The circuit is not modified, one circuit can be shared among several TransientNodal objects.
Accept xVec for current time step and store state
Calculate total current
returns iVec = G’ xVec + i’(xVec)
xVec: input vector of nodal voltages.
iVec: output vector of currents
Calculate total current and Jacobian
Returns (iVec, Jac):
iVec = G' xVec + i'(xVec)
Jac = G' + (di'/dx)(xVec)
xVec: input vector of nodal voltages.
iVec: output vector of currents
Jac: system Jacobian
Returns system rhs vector: s’
s’ includes source vector, charge history and convolution contributions
ctime: current time
Get the source vector considering DC and TD source components
ctime: current time.
Re-generate linear matrices
Used for parametric sweeps
Set initial conditions (ICs)
h: (initial) time step
Retrieves ICs from DC operating point info in elements
Set current contributions of Jac into M (in coo format)
Recalculate Gp from im information
Recalculate qVec for a given value of xVec
Creates pre-calculated indexes for nonlinear devices
The following indexes are calculated:
nD_csidx = (cpidx, cnidx, jacpidx, jacnidx) nD_qsidx = (qpidx, qnidx, jacqpidx, jacqnidx)
cpidx, cnidx, qpidx and qnidx are relative to 0 in this element. The final position in the coo matrix is unknown at this time.
Important note: these indexes depend on the order used to insert elements in set_Jac_triplet()
Add attributes to Circuit/Elements/Terminals for nodal analysis
Similar to nodal.make_nodal_circuit but in addition calls create_additional_indexes()
Process element for nodal analysis
Set elements in M
M: target matrix in (dataVec, rowVec, colVec) format (triplet format)
The looping is not optimal but has the advantage that all positive values are inserted first. This simplify index calculation in create_additional_indexes()
Set transconductance/transcapacitance quad
G: target matrix in (dataVec, rowVec, colVec) format (triplet format)
Add val at [row, col] position into G matrix (triplet format)
This module provides the main function that tries different equation solving strategies provided by an object passed as an argument.
A simple Newton method routine is also provided here. In the future we could implement here additional nonlinear equation solving routines.
Solves a multidimensional non-linear equation with Newton-Raphson’s method. In each iteration the linear system:
is solved and a new value for is obtained. Arguments:
x0: initial guess vector
get_deltax(x): function that returns the vector
f_eval(x): function that returns error function vector
Convergence parameters are taken from the global options (Global Options and Constants Tables). Relative and absolute tolerances are checked independently for each variable.
Returns the following tuple: (x, res, niter, success)
x: estimated solution vector at the last iteration
res: maximum residual from all variables
niter: number of iterations
success: True if method converged to specified tolerance, False otherwise
This function originally adapted from pycircuit (https://github.com/henjo/pycircuit)
Attempt solving circuit equations using several strategies
x0: initial guess
sV: source vector
convergence_helpers: list of functions that can be used to solve equations
Example of helper functions:
solve_simple(x0, sV)
solve_homotopy_gmin(x0, sV)
solve_homotopy_source(x0, sV)
This function originally adapted from pycircuit (https://github.com/henjo/pycircuit)
This module implement different integration methods to be used in transient analysis.
Implements Backwards Euler method:
Accept q as last valid value
Returns
Initialize for integration
Set time step size to h. q is ignored as it is not needed
Change time step size to h
Implements Trapezoidal method:
Accept q as last valid value
Returns
Initialize for integration
Set time step size to h, previous charge to q previous derivative to dq
Change time step size to h in next call to f_n1
Functions to calculate derivatives for sensitivity analysis. Elements are assumed to have nodal arguments (nD_*).
Create sensitivity AD tape
Inputs:
device: device with nodal attributes parList: list of parameters to calculate sensitivities
inVec: input vector including parameters and perhaps nonlinear control voltages at the end of the vector
Side effects: operating point attributes lost in internal terminals
Returns DC current derivatives with respect to given parameters
Inputs:
device (linear or nonlinear) parList: list of parameters as returned by param.get_float_attributes() xVec: nodal vector force: if True, force tape re-generation
Outputs:
output currents Jacobian
Possible side effect: operating point attributes lost in internal terminals if tape is created