VeraGridEngine.Simulations.Derivatives package

Submodules

VeraGridEngine.Simulations.Derivatives.ac_jacobian module

VeraGridEngine.Simulations.Derivatives.ac_jacobian.AC_jacobian(Ybus: csc_matrix, V: ndarray[tuple[Any, ...], dtype[complex128]], pvpq: ndarray[tuple[Any, ...], dtype[int64]], pq: ndarray[tuple[Any, ...], dtype[int64]]) CSC[source]

Create the AC Jacobian function with no embedded controls :param Ybus: Ybus matrix in CSC format :param V: Voltages vector :param pvpq: array of pv|pq bus indices :param pq: array of pq indices :return: Jacobian Matrix in CSC format

VeraGridEngine.Simulations.Derivatives.ac_jacobian.AC_jacobianVc(Ybus: csc_matrix, V: ndarray[tuple[Any, ...], dtype[complex128]], idx_dtheta: ndarray[tuple[Any, ...], dtype[int64]], idx_dVm: ndarray[tuple[Any, ...], dtype[int64]], idx_dQ: ndarray[tuple[Any, ...], dtype[int64]]) CSC[source]

Create the AC Jacobian function with no embedded controls :param Ybus: Ybus matrix in CSC format :param V: Voltages vector :param idx_dtheta: pv, pq, p, pqv :param idx_dVm: pq, p :param idx_dQ: pq, pqv :return: Jacobian Matrix in CSC format

VeraGridEngine.Simulations.Derivatives.ac_jacobian.AC_jacobian_csr(Ybus: csr_matrix, V: ndarray[tuple[Any, ...], dtype[complex128]], pvpq: ndarray[tuple[Any, ...], dtype[int64]], pq: ndarray[tuple[Any, ...], dtype[int64]]) csc_matrix[source]

Create the AC Jacobian function with no embedded controls :param Ybus: Ybus matrix in CSC format :param V: Voltages vector :param pvpq: array of pv|pq bus indices :param pq: array of pq indices :return: Jacobian Matrix in CSR format

VeraGridEngine.Simulations.Derivatives.ac_jacobian.create_J_csc(nbus, Yx: ndarray[tuple[Any, ...], dtype[complex128]], Yp: ndarray[tuple[Any, ...], dtype[int64]], Yi: ndarray[tuple[Any, ...], dtype[int64]], V: ndarray[tuple[Any, ...], dtype[complex128]], pvpq, pq) CSC[source]

Calculates Jacobian in CSC format.

J has the shape

pvpq pq

pvpq | dP_dVa | dP_dVm |

pq | dQ_dVa | dQ_dVm |

Parameters:
  • nbus

  • Yx

  • Yp

  • Yi

  • V

  • pvpq

  • pq

Returns:

VeraGridEngine.Simulations.Derivatives.ac_jacobian.create_J_csr(nbus, dS_dVm_x, dS_dVa_x, Yp, Yj, pvpq, pq, Jx, Jj, Jp)[source]

Calculates Jacobian in CSR format. :param nbus: :param dS_dVm_x: :param dS_dVa_x: :param Yp: :param Yj: :param pvpq: :param pq: :param Jx: :param Jj: :param Jp: :return:

VeraGridEngine.Simulations.Derivatives.ac_jacobian.create_J_vc_csc(nbus: int, Yx: ndarray[tuple[Any, ...], dtype[complex128]], Yp: ndarray[tuple[Any, ...], dtype[int64]], Yi: ndarray[tuple[Any, ...], dtype[int64]], V: ndarray[tuple[Any, ...], dtype[complex128]], idx_dtheta: ndarray[tuple[Any, ...], dtype[int64]], idx_dVm: ndarray[tuple[Any, ...], dtype[int64]], idx_dP: ndarray[tuple[Any, ...], dtype[int64]], idx_dQ: ndarray[tuple[Any, ...], dtype[int64]]) CSC[source]

Calculates Jacobian in CSC format.

J has the shape

idx_dtheta idx_dVm

idx_dP | dP_dVa | dP_dVm | idx_dQ | dQ_dVa | dQ_dVm |

Parameters:
  • nbus

  • Yx

  • Yp

  • Yi

  • V

  • idx_dtheta – pv, pq, p, pqv

  • idx_dVm – pq, p

  • idx_dP – pv, pq, p, pqv

  • idx_dQ – pq, pqv

Returns:

Jacobina matrix

VeraGridEngine.Simulations.Derivatives.csc_derivatives module

VeraGridEngine.Simulations.Derivatives.csc_derivatives.csc_add_ff_comp(Am, An, Aindptr, Aindices, Adata, Bm, Bn, Bindptr, Bindices, Bdata, alpha, beta)[source]

C = alpha*A + beta*B

@param A: column-compressed matrix @param B: column-compressed matrix @param alpha: scalar alpha @param beta: scalar beta @return: C=alpha*A + beta*B, null on error (Cm, Cn, Cp, Ci, Cx)

VeraGridEngine.Simulations.Derivatives.csc_derivatives.csc_add_wrapper(A: CxCSC, B: CxCSC, alpha: float = 1.0, beta: float = 1.0) CxCSC[source]

Wrapper for csc_add_ff :param A: matrix A :param B: matrix B :param alpha: scalar alpha :param beta: scalar beta :return: matrix C = A * alpha + B * beta

VeraGridEngine.Simulations.Derivatives.csc_derivatives.csc_scatter_f_comp(Ap, Ai, Ax, j, beta, w, x, mark, Ci, nz)[source]

Scatters and sums a sparse vector A(:,j) into a dense vector, x = x + beta * A(:,j) :param Ap: :param Ai: :param Ax: :param j: the column of A to use :param beta: scalar multiplied by A(:,j) :param w: size m, node i is marked if w[i] = mark :param x: size m, ignored if null :param mark: mark value of w :param Ci: pattern of x accumulated in C.i :param nz: pattern of x placed in C starting at C.i[nz] :return: new value of nz, -1 on error, x and w are modified

VeraGridEngine.Simulations.Derivatives.csc_derivatives.csc_spalloc_f(m, n, nzmax)[source]

Allocate a sparse matrix (triplet form or compressed-column form).

@param m: number of rows @param n: number of columns @param nzmax: maximum number of entries @return: m, n, Aindptr, Aindices, Adata, Anzmax

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dDroopvsc_dPfp_csc(n_droop: int, nvsc: int, k_vsc_pfp_droop, u_vsc_pfp) CSC[source]

Compute the d(droop equation)/dPfp block :param n_droop: number of droop equations (rows) :param nvsc: total number of VSCs (domain size for the lookup) :param k_vsc_pfp_droop: VSC index of each droop equation :param u_vsc_pfp: unknown-Pfp VSC indices (column space) :return: CSC block

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dDroopvsc_dVm_csc(n_droop: int, nbus: int, i_u_vm, k_vsc_pfp_droop, Fdcp_vsc, dpfp_droop_slope) CSC[source]

Compute the d(droop equation)/dVm block :param n_droop: number of droop equations (rows) :param nbus: number of buses :param i_u_vm: unknown-Vm bus indices (column space) :param k_vsc_pfp_droop: VSC index of each droop equation :param Fdcp_vsc: from (positive pole) bus index of each VSC :param dpfp_droop_slope: d(Pfp)/dVm slope of each droop equation :return: CSC block.

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dImaxvsc_dPQ_csc(nvsc, k_vsc_imax, u_vsc_pqt, PQt_vsc, Vm, T_vsc) CSC[source]

Compute dImaxvsc_dPQ in CSC format. The equation is: (P**2 + Q**2) / Vm**2 - Imax**2 = 0 :param nvsc: Number of VSCs (rows of the matrix). :param k_vsc_imax: VSC indices working at maximum current. :param u_vsc_pqt: P or Q indices where the AC side power is unknonw. :param PQt_vsc: Active or reactive power flow on the AC side of the VSC. :param Vm: Voltage magnitude :param T_vsc: Bus index pointing to the AC bus of the VSC. :return: Sparse matrix in CSC format.

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dImaxvsc_dVm_csc(nbus, k_vsc_imax, i_u_vm, Pt_vsc, Qt_vsc, Vm, T_vsc) CSC[source]

Compute dImaxvsc_dVm in CSC format. The equation is: (P**2 + Q**2) / Vm**2 - Imax**2 = 0 :param nbus: Number of buses. :param k_vsc_imax: VSC indices working at maximum current. :param i_u_vm: Column indices for the sparse matrix. :param Pt_vsc: Active power flow on the AC side of the VSC. :param Qt_vsc: Reactive power flow on the AC side of the VSC. :param Vm: Voltage magnitude :param T_vsc: Bus index pointing to the AC bus of the VSC. :return: Sparse matrix in CSC format.

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dInj_dVa_csc(nhvdc, i_u_va, hvdc_pset, hvdc_r, hvdc_droop, V, F_hvdc, T_hvdc) CSC[source]

Compute dInj_dVa in CSC format for HVDC systems.

Parameters:
  • nhvdc – Number of HVDC systems (rows of the matrix).

  • i_u_va – Column indices for the sparse matrix (corresponding to voltage angles Va).

  • hvdc_pset – HVDC power setpoints.

  • hvdc_r – HVDC resistance values.

  • hvdc_droop – HVDC droop coefficients.

  • V – Voltage magnitudes at buses.

  • F_hvdc – From-bus indices for HVDC.

  • T_hvdc – To-bus indices for HVDC.

Returns:

Sparse matrix in CSC format.

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dInjhvdc_dPfhvdc_csc(nhvdc)[source]

dInjhvdc = Pf_hvdc - Pset - droop(Va[f] - Va[t])

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dInjhvdc_dVa_csc(nhvdc, nbus, i_u_va, hvdc_droop, F_hvdc, T_hvdc) CSC[source]

Compute dInjhvdc_dVa in CSC format for HVDC systems.

Parameters:
  • nhvdc – Number of HVDC systems (rows of the matrix).

  • nbus – Number of buses in the system.

  • i_u_va – Column indices for the sparse matrix (corresponding to voltage angles Va).

  • hvdc_droop_idx – Indices corresponding to HVDC droop control.

  • hvdc_droop – HVDC droop coefficients.

  • F_hvdc – From-bus indices for HVDC.

  • T_hvdc – To-bus indices for HVDC.

Returns:

Sparse matrix in CSC format.

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dIvsc_dPfnvsc_csc(k_vsc_has_dc_n, u_vsc_pfn, Vm, Va, Fdcp_vsc) CSC[source]

Compute dIvsc_dPfnvsc in CSC format. :param k_vsc_has_dc_n: array of VSC indices with negative poles. :param u_vsc_pfn: Column indices for the sparse matrix. :param Vm: Voltage magnitudes at buses. :param Va: Voltage angles at buses (used for the signed DC voltage Vm*cos(Va)). :param Fdcp_vsc: From positive bus indices for VSCs. :return: Sparse matrix in CSC format.

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dIvsc_dPfpvsc_csc(k_vsc_has_dc_n, u_vsc_pfp, Vm, Va, Fdcn_vsc) CSC[source]

Compute dIvsc_dPfpvsc in CSC format. :param k_vsc_has_dc_n: array of VSC indices with negative poles. :param u_vsc_pfp: Column indices for the sparse matrix. :param Vm: Voltage magnitudes at buses. :param Va: Voltage angles at buses (used for the signed DC voltage Vm*cos(Va)). :param Fdcn_vsc: From negative bus indices for VSCs. :return: Sparse matrix in CSC format.

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dIvsc_dVm_csc(k_vsc_has_dc_n: ndarray[tuple[Any, ...], dtype[int64]], nbus: int, i_u_vm: ndarray[tuple[Any, ...], dtype[int64]], Pfp_vsc, Pfn_vsc, Va, Fdcp_vsc, Fdcn_vsc) CSC[source]

Compute dIvsc_dVm in CSC format. :param k_vsc_has_dc_n: array of VSC indices with negative poles. :param nbus: Number of buses. :param i_u_vm: Column indices for the sparse matrix. :param Pfp_vsc: Active power flows from positive bus to VSC. :param Pfn_vsc: Active power flows from negative bus to VSC. :param Va: Voltage angles at buses (used for the signed DC voltage Vm*cos(Va)). :param Fdcp_vsc: From positive bus indices for VSCs. :param Fdcn_vsc: From negative bus indices for VSCs. :return: Sparse matrix in CSC format.

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dLosshvdc_dPfhvdc_csc(nhvdc, Vm, hvdc_r, F_hvdc)[source]

dLosshvdc = rpu * Pf_hvdc / Vm[F_hvdc]**2 - Pf_hvdc - Pt_hvdc

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dLosshvdc_dPthvdc_csc(nhvdc)[source]

dLosshvdc = rpu * Pf_hvdc / Vm[F_hvdc]**2 - Pf_hvdc - Pt_hvdc

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dLosshvdc_dVm_csc(nhvdc: int, nbus: int, i_u_vm: ndarray[tuple[Any, ...], dtype[int64]], Vm: ndarray[tuple[Any, ...], dtype[float64]], Pf_hvdc: ndarray[tuple[Any, ...], dtype[float64]], hvdc_r: ndarray[tuple[Any, ...], dtype[float64]], F_hvdc: ndarray[tuple[Any, ...], dtype[int64]])[source]

dLosshvdc = rpu * Pf_hvdc / Vm[F_hvdc]**2 - Pf_hvdc - Pt_hvdc

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dLossvsc_dPfvsc_csc(nvsc, u_vsc_pf) CSC[source]

Compute dLossvsc_dPfvsc in CSC format with column indices aligned to u_vsc_pf.

Parameters:
  • nvsc – Total number of rows in the matrix (number of VSCs).

  • u_vsc_pf – Indices to define the column indices for the sparse matrix.

Returns:

Sparse matrix in CSC format.

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dLossvsc_dPtvsc_csc(nvsc, u_vsc_pt, alpha2, alpha3, Vm, Pt, Qt, T_vsc) CSC[source]

Compute the sparse matrix for the derivative of loss with respect to Pt in CSC format.

Parameters:
  • nvsc – Number of VSCs (rows of the matrix).

  • u_vsc_pt – Column indices for the sparse matrix.

  • alpha2 – Array of alpha2 coefficients.

  • alpha3 – Array of alpha3 coefficients.

  • Vm – Voltage magnitudes at buses.

  • Pt – Active power flows.

  • Qt – Reactive power flows.

  • T_vsc – Indices for VSC buses.

Returns:

Sparse matrix in CSC format.

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dLossvsc_dQtvsc_csc(nvsc, u_vsc_qt, alpha2, alpha3, Vm, Pt, Qt, T_vsc) CSC[source]

Compute the sparse matrix for the derivative of loss with respect to Qt in CSC format.

Parameters:
  • nvsc – Number of VSCs (rows of the matrix).

  • u_vsc_pt – Column indices for the sparse matrix.

  • alpha2 – Array of alpha2 coefficients.

  • alpha3 – Array of alpha3 coefficients.

  • Vm – Voltage magnitudes at buses.

  • Pt – Active power flows.

  • Qt – Reactive power flows.

  • T_vsc – Indices for VSC buses.

Returns:

Sparse matrix in CSC format.

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dLossvsc_dVm_csc(nvsc, nbus, i_u_vm, alpha2, alpha3, Vm, Pt, Qt, T) CSC[source]

pq = Pt[ig_plossacdc] * Pt[ig_plossacdc] + Qt[ig_plossacdc] * Qt[ig_plossacdc] pq_sqrt = np.sqrt(pq) pq_sqrt += 1e-20 dLacdc_dVm = (alpha2[vsc_order] * pq_sqrt * Qt[ig_plossacdc] / (Vm[T_acdc] * Vm[T_acdc])

  • 2 * alpha3[vsc_order] * (pq) / (

    Vm[T_acdc[vsc_order]] * Vm[T_acdc[vsc_order]] * Vm[T_acdc[vsc_order]]))

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dPQ_dPQft_csc(nbus: int, nvsc: int, i_k_pq: ndarray[tuple[Any, ...], dtype[int64]], u_dev_pq: ndarray[tuple[Any, ...], dtype[int64]], FT_dev: ndarray[tuple[Any, ...], dtype[int64]]) CSC[source]

Calculate the derivatives of the power balance with respect to injections of branches The method works for vscs and transformers without loss of generality

Parameters:
  • i_k_pq – Indices for the rows corresponding to the power injections.

  • u_dev_pq – Column indices for the sparse matrix.

  • FT_dev – From or To bus indices.

Returns:

Sparse matrix in CSC format.

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dP_dPfvsc_csc(i_k_p, u_vsc_pf, F_vsc) CSC[source]

Compute dP_dPfvsc in CSC format.

Parameters:
  • i_k_p – Indices for the rows corresponding to the power injections.

  • u_vsc_pf – Column indices for the sparse matrix.

  • F_vsc – From bus indices for VSCs.

Returns:

Sparse matrix in CSC format.

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dPfdp_dVm_csc(nbus, br_indices, bus_indices, yff, yft, kdp, V, F, T) CSC[source]

dSf_dVm[br_indices, bus_indices] checked agins matpower derivatives :param nbus: number of buses :param br_indices: Branch indices :param bus_indices: Bus indices :param yff: yff primitives array :param yft: yft primitives array :param V: Voltages array :param F: Array of β€œfrom” indices :param T: Array of β€œto” indices :return: dSf_dVm

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dSbr_dm_csc(nbus, u_cbr_m, F_cbr, T_cbr, yff_cbr, yft_cbr, ytf_cbr, ytt_cbr, V, tap, tap_modules) CxCSC[source]

Derivative of the controllable branch power flows (and hence bus balance) w.r.t. m :param nbus: number of buses :param u_cbr_m: Array of indices where m is unknown :param F_cbr: Array of branch β€œfrom” bus indices :param T_cbr: Array of branch β€œto” bus indices :param yff_cbr: Array of branch primitive admittances :param yft_cbr: Array of branch primitive admittances :param ytf_cbr: Array of branch primitive admittances :param ytt_cbr: Array of branch primitive admittances :param V: Array of complex voltages :param tap: Array of branch complex taps (m * exp(1j * tau) :param tap_modules: Array of branch tap modules :return: dSbr_dm

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dSbr_dtau_csc(nbus, u_cbr_tau, F_cbr, T_cbr, yff_cbr, yft_cbr, ytf_cbr, ytt_cbr, V, tap, tap_modules) CxCSC[source]

Derivative of the controllable branch power flows (and hence bus balance) w.r.t. tau :param nbus: number of buses :param u_cbr_m: Array of indices where m is unknown :param F_cbr: Array of branch β€œfrom” bus indices :param T_cbr: Array of branch β€œto” bus indices :param yff_cbr: Array of branch primitive admittances :param yft_cbr: Array of branch primitive admittances :param ytf_cbr: Array of branch primitive admittances :param ytt_cbr: Array of branch primitive admittances :param V: Array of complex voltages :param tap: Array of branch complex taps (m * exp(1j * tau) :param tap_modules: Array of branch tap modules :return: dSbr_dtau

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dSbus_dV_csc(Ybus: csc_matrix, V: ndarray[tuple[Any, ...], dtype[complex128]], Vm) Tuple[CxCSC, CxCSC][source]

Call the numba sparse constructor of the derivatives :param Ybus: Ybus in CSC format :param V: Voltages vector :param Vm: Voltages modules :return: dS_dVm, dS_dVa in CSC format

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dSbus_dV_numba_sparse_csc(Yx: ndarray[tuple[Any, ...], dtype[complex128]], Yp: ndarray[tuple[Any, ...], dtype[int64]], Yi: ndarray[tuple[Any, ...], dtype[int64]], V: ndarray[tuple[Any, ...], dtype[complex128]], Vm: ndarray[tuple[Any, ...], dtype[float64]]) Tuple[ndarray[tuple[Any, ...], dtype[complex128]], ndarray[tuple[Any, ...], dtype[complex128]]][source]

Compute the power injection derivatives w.r.t the voltage module and angle :param Yx: data of Ybus in CSC format :param Yp: indptr of Ybus in CSC format :param Yi: indices of Ybus in CSC format :param V: Voltages vector :param Vm: voltage modules vector :return: dS_dVm, dS_dVa data ordered in the CSC format to match the indices of Ybus

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dSbus_dV_with_I0_numba_sparse_csc(Yx: ndarray[tuple[Any, ...], dtype[complex128]], Yp: ndarray[tuple[Any, ...], dtype[int64]], Yi: ndarray[tuple[Any, ...], dtype[int64]], V: ndarray[tuple[Any, ...], dtype[complex128]], Vm: ndarray[tuple[Any, ...], dtype[float64]], I0: ndarray[tuple[Any, ...], dtype[complex128]]) Tuple[ndarray[tuple[Any, ...], dtype[complex128]], ndarray[tuple[Any, ...], dtype[complex128]]][source]

Compute the power injection derivatives w.r.t the voltage module and angle, including the contribution from Norton current injections I0.

The power balance is: dS = V * conj(Ybus @ V) - Sbus where Sbus includes: V * conj(I0)

The I0 contribution to derivatives (diagonal only):

dS/dVa from -V*conj(I0): -j * V * conj(I0) dS/dVm from -V*conj(I0): -E * conj(I0) where E = V/|V|

Parameters:
  • Yx – data of Ybus in CSC format

  • Yp – indptr of Ybus in CSC format

  • Yi – indices of Ybus in CSC format

  • V – Voltages vector

  • Vm – voltage modules vector

  • I0 – Norton current injections vector

Returns:

dS_dVm, dS_dVa data ordered in the CSC format to match the indices of Ybus

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dSbus_dbeq_csc(nbus, bus_indices, beq_indices, F: ndarray[tuple[Any, ...], dtype[int64]], kconv: ndarray[tuple[Any, ...], dtype[float64]], tap_module: ndarray[tuple[Any, ...], dtype[float64]], V: ndarray[tuple[Any, ...], dtype[complex128]]) CxCSC[source]
Parameters:
  • nbus

  • bus_indices

  • beq_indices

  • F – Array of branch β€œfrom” bus indices

  • kconv – Array of β€œk2” parameters

  • tap_module – Array of tap modules

  • V – Array of complex voltages

Returns:

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dSbus_dm_csc(nbus, bus_indices, m_indices, F: ndarray[tuple[Any, ...], dtype[int64]], T: ndarray[tuple[Any, ...], dtype[int64]], Ys: ndarray[tuple[Any, ...], dtype[complex128]], Bc: ndarray[tuple[Any, ...], dtype[float64]], tap: ndarray[tuple[Any, ...], dtype[complex128]], tap_module: ndarray[tuple[Any, ...], dtype[float64]], V: ndarray[tuple[Any, ...], dtype[complex128]]) CxCSC[source]
Parameters:
  • nbus

  • bus_indices – bus indices involved

  • m_indices – branch indices where m is controlled

  • F – Array of branch β€œfrom” bus indices

  • T – Array of branch β€œto” bus indices

  • Ys – Array of branch series admittances

  • Bc – Array of branch total susceptance values (sum of the two legs)

  • tap – Array of branch complex taps (m * exp(1j * tau)

  • tap_module – Array of tap modules

  • V – Array of complex voltages

Returns:

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dSbus_dtau_csc(nbus, bus_indices, tau_indices, F: ndarray[tuple[Any, ...], dtype[int64]], T: ndarray[tuple[Any, ...], dtype[int64]], Ys: ndarray[tuple[Any, ...], dtype[complex128]], tap: ndarray[tuple[Any, ...], dtype[complex128]], V: ndarray[tuple[Any, ...], dtype[complex128]]) CxCSC[source]

This function computes the derivatives of Sbus, Sf and St w.r.t. the tap angle (tau) - dSbus_dPfsh, dSf_dPfsh, dSt_dPfsh -> if iPxsh=iPfsh - dSbus_dPfdp, dSf_dPfdp, dSt_dPfdp -> if iPxsh=iPfdp

Parameters:
  • nbus

  • bus_indices

  • tau_indices – array of indices {iPfsh or iPfdp}

  • F – Array of branch β€œfrom” bus indices

  • T – Array of branch β€œto” bus indices

  • Ys – Array of branch series admittances

  • tap – Array of branch complex taps (m * exp(1j * tau)

  • V – Array of complex voltages

Returns:

dSbus_dsh

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dSf_dV_csc(Yf, V, F, T) Tuple[CxCSC, CxCSC][source]

Flow β€œfrom” derivative w.r.t the voltage :param Yf: :param V: :param F: :param T: :return:

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dSf_dV_numba(Yf_nrows, Yf_ncols, Yf_indices, Yf_indptr, Yf_data, V, F, T) Tuple[CxCSC, CxCSC][source]
Parameters:
  • Yf_nrows

  • Yf_ncols

  • Yf_indices

  • Yf_indptr

  • Yf_data

  • V

  • F

  • T

Returns:

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dSf_dVa_csc(nbus, br_indices, bus_indices, yft, V, F, T) CxCSC[source]
Parameters:
  • nbus – number of buses

  • br_indices

  • bus_indices

  • yft

  • V

  • F

  • T

Returns:

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dSf_dVm_csc(nbus, br_indices, bus_indices, yff, yft, Vm, Va, F, T) CxCSC[source]

dSf_dVm[br_indices, bus_indices] checked agins matpower derivatives :param nbus: number of buses :param br_indices: Branch indices :param bus_indices: Bus indices :param yff: yff primitives array :param yft: yft primitives array :param V: Voltages array :param F: Array of β€œfrom” indices :param T: Array of β€œto” indices :return: dSf_dVm

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dSf_dbeq_csc(nbr, sf_indices, beq_indices, F: ndarray[tuple[Any, ...], dtype[int64]], kconv: ndarray[tuple[Any, ...], dtype[float64]], tap_module: ndarray[tuple[Any, ...], dtype[float64]], V: ndarray[tuple[Any, ...], dtype[complex128]]) CxCSC[source]

This function computes the derivatives of Sbus, Sf and St w.r.t. the tap angle (tau) - dSbus_dPfsh, dSf_dPfsh, dSt_dPfsh -> if iPxsh=iPfsh - dSbus_dPfdp, dSf_dPfdp, dSt_dPfdp -> if iPxsh=iPfdp

Parameters:
  • nbr – Number of branches

  • sf_indices – array of sf indices

  • beq_indices – array of branch indices with tau control

  • F – Array of branch β€œfrom” bus indices

  • kconv – Array of β€œk2” parameters

  • tap_module – Array of tap modules

  • V – Array of complex voltages

Returns:

dSf_dsh

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dSf_dm_csc(nbr, sf_indices, m_indices, F: ndarray[tuple[Any, ...], dtype[int64]], T: ndarray[tuple[Any, ...], dtype[int64]], Ys: ndarray[tuple[Any, ...], dtype[complex128]], Bc: ndarray[tuple[Any, ...], dtype[float64]], tap: ndarray[tuple[Any, ...], dtype[complex128]], tap_module: ndarray[tuple[Any, ...], dtype[float64]], V: ndarray[tuple[Any, ...], dtype[complex128]]) CxCSC[source]

This function computes the derivatives of Sbus, Sf and St w.r.t. the tap angle (tau) - dSbus_dPfsh, dSf_dPfsh, dSt_dPfsh -> if iPxsh=iPfsh - dSbus_dPfdp, dSf_dPfdp, dSt_dPfdp -> if iPxsh=iPfdp

:param nbr :param sf_indices: array of sf indices :param m_indices: array of branch indices with tau control :param F: Array of branch β€œfrom” bus indices :param T: Array of branch β€œto” bus indices :param Ys: Array of branch series admittances :param Bc: Array of branch total susceptance values :param Beq: Array of regulation susceptance of the FUBM model :param tap: Array of branch complex taps (m * exp(1j * tau) :param tap_module: Array of tap modules :param V: Array of complex voltages :return: dSf_dsh

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dSf_dtau_csc(nbr, sf_indices, tau_indices, F: ndarray[tuple[Any, ...], dtype[int64]], T: ndarray[tuple[Any, ...], dtype[int64]], Ys: ndarray[tuple[Any, ...], dtype[complex128]], tap: ndarray[tuple[Any, ...], dtype[complex128]], V: ndarray[tuple[Any, ...], dtype[complex128]]) CxCSC[source]

This function computes the derivatives of Sbus, Sf and St w.r.t. the tap angle (tau) - dSbus_dPfsh, dSf_dPfsh, dSt_dPfsh -> if iPxsh=iPfsh - dSbus_dPfdp, dSf_dPfdp, dSt_dPfdp -> if iPxsh=iPfdp

Parameters:
  • nbr – number of branches

  • sf_indices – array of sf indices

  • tau_indices – array of branch indices with tau control (must be equal to sf_indices)

  • F – Array of branch β€œfrom” bus indices

  • T – Array of branch β€œto” bus indices

  • Ys – Array of branch series admittances

  • tap – Array of branch complex taps (m * exp(1j * tau)

  • V – Array of complex voltages

Returns:

dSf_dsh

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dSt_dV_csc(Yt, V, F, T) Tuple[CxCSC, CxCSC][source]

Flow β€œto” derivative w.r.t the voltage :param Yt: :param V: :param F: :param T: :return:

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dSt_dV_numba(Yt_nrows, Yt_ncols, Yt_indices, Yt_indptr, Yt_data, V, F, T) Tuple[CxCSC, CxCSC][source]
Parameters:
  • Yt_nrows

  • Yt_ncols

  • Yt_indices

  • Yt_indptr

  • Yt_data

  • V

  • F

  • T

Returns:

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dSt_dVa_csc(nbus, br_indices, bus_indices, ytf, V, F, T) CxCSC[source]

:param nbus :param br_indices: :param bus_indices: :param ytf: :param V: :param F: :param T: :return:

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dSt_dVm_csc(nbus, br_indices, bus_indices, ytt, ytf, Vm, Va, F, T) CxCSC[source]

:param nbus :param br_indices: :param bus_indices: :param ytt: :param ytf: :param Vm: :param Va: :param F: :param T: :return:

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dSt_dbeq_csc(sf_indices, beq_indices) CxCSC[source]

This function computes the derivatives of Sbus, Sf and St w.r.t. the tap angle (tau) - dSbus_dPfsh, dSf_dPfsh, dSt_dPfsh -> if iPxsh=iPfsh - dSbus_dPfdp, dSf_dPfdp, dSt_dPfdp -> if iPxsh=iPfdp

Parameters:
  • sf_indices – array of sf indices

  • beq_indices – array of branch indices with tau control

Returns:

dSf_dsh

Returns:

dSt_dtau

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dSt_dm_csc(nbr, st_indices, m_indices, F: ndarray[tuple[Any, ...], dtype[int64]], T: ndarray[tuple[Any, ...], dtype[int64]], Ys: ndarray[tuple[Any, ...], dtype[complex128]], tap: ndarray[tuple[Any, ...], dtype[complex128]], tap_module: ndarray[tuple[Any, ...], dtype[float64]], V: ndarray[tuple[Any, ...], dtype[complex128]]) CxCSC[source]

This function computes the derivatives of Sbus, Sf and St w.r.t. the tap angle (tau) - dSbus_dPfsh, dSf_dPfsh, dSt_dPfsh -> if iPxsh=iPfsh - dSbus_dPfdp, dSf_dPfdp, dSt_dPfdp -> if iPxsh=iPfdp

Parameters:
  • nbr

  • st_indices – array of st indices

  • m_indices – array of branch indices with tau control

  • F – Array of branch β€œfrom” bus indices

  • T – Array of branch β€œto” bus indices

  • Ys – Array of branch series admittances

  • kconv – Array of β€œk2” parameters

  • tap – Array of branch complex taps (m * exp(1j * tau)

:param tap_module :param V: Array of complex voltages :return: dSf_dsh :return: dSt_dtau

VeraGridEngine.Simulations.Derivatives.csc_derivatives.dSt_dtau_csc(nbr, st_indices, tau_indices, F: ndarray[tuple[Any, ...], dtype[int64]], T: ndarray[tuple[Any, ...], dtype[int64]], Ys: ndarray[tuple[Any, ...], dtype[complex128]], tap: ndarray[tuple[Any, ...], dtype[complex128]], V: ndarray[tuple[Any, ...], dtype[complex128]]) CxCSC[source]

This function computes the derivatives of Sbus, Sf and St w.r.t. the tap angle (tau) - dSbus_dPfsh, dSf_dPfsh, dSt_dPfsh -> if iPxsh=iPfsh - dSbus_dPfdp, dSf_dPfdp, dSt_dPfdp -> if iPxsh=iPfdp

Parameters:
  • nbr – number of branches

  • st_indices – array of st indices

  • tau_indices – array of branch indices with tau control

  • F – Array of branch β€œfrom” bus indices

  • T – Array of branch β€œto” bus indices

  • Ys – Array of branch series admittances

  • tap – Array of branch complex taps (m * exp(1j * tau)

  • V – Array of complex voltages

Returns:

dSf_dsh

Returns:

dSt_dtau

VeraGridEngine.Simulations.Derivatives.csc_derivatives.derivatives_Beq_csc_numba(nbus, nbr, iBeqx, F, V, tap_module, kconv)[source]

Compute the derivatives of: - dSbus_dBeqz, dSf_dBeqz, dSt_dBeqz -> iBeqx=iBeqz - dSbus_dBeqv, dSf_dBeqv, dSt_dBeqv -> iBeqx=iBeqv

Parameters:
  • nbus – Number of buses

  • nbr – Number of Branches

  • iBeqx – array of indices {iBeqz, iBeqv}

  • F – Array of branch β€œfrom” bus indices

:param V:Array of complex voltages :param tap_module: Array of branch taps modules :param kconv: Array of β€œk2” parameters

Returns:

  • dSbus_dBeqz, dSf_dBeqz, dSt_dBeqz -> if iBeqx=iBeqz

  • dSbus_dBeqv, dSf_dBeqv, dSt_dBeqv -> if iBeqx=iBeqv

VeraGridEngine.Simulations.Derivatives.csc_derivatives.derivatives_ma_csc_numba(nbus, nbr, iXxma, F, T, Ys, kconv, tap, tap_module, Bc, Beq, V) Tuple[CxCSC, CxCSC, CxCSC][source]

Useful for the calculation of - dSbus_dQfma, dSf_dQfma, dSt_dQfma -> wih iXxma=iQfma - dSbus_dQtma, dSf_dQtma, dSt_dQtma -> wih iXxma=iQtma - dSbus_dVtma, dSf_dVtma, dSt_dVtma -> wih iXxma=iVtma

Parameters:
  • nbus – Number of buses

  • nbr – Number of Branches

  • iXxma – Array of indices {iQfma, iQtma, iVtma}

  • F – Array of branch β€œfrom” bus indices

  • T – Array of branch β€œto” bus indices

  • Ys – Array of branch series admittances

  • kconv – Array of β€œk2” parameters

  • tap – Array of branch complex taps (ma * exp(1j * theta_sh)

  • tap_module – Array of tap modules (this is to avoid extra calculations)

  • Bc – Array of branch total shunt susceptance values (sum of the two legs)

  • Beq – Array of regulation susceptance of the FUBM model

:param V:Array of complex voltages

Returns:

dSbus_dma, dSf_dma, dSt_dma

VeraGridEngine.Simulations.Derivatives.csc_derivatives.derivatives_tau_csc_numba(nbus, nbr, iPxsh, F: ndarray[tuple[Any, ...], dtype[int64]], T: ndarray[tuple[Any, ...], dtype[int64]], Ys: ndarray[tuple[Any, ...], dtype[complex128]], kconv, tap, V) Tuple[CxCSC, CxCSC, CxCSC][source]

This function computes the derivatives of Sbus, Sf and St w.r.t. the tap angle (tau) - dSbus_dPfsh, dSf_dPfsh, dSt_dPfsh -> if iPxsh=iPfsh - dSbus_dPfdp, dSf_dPfdp, dSt_dPfdp -> if iPxsh=iPfdp

Parameters:
  • nbus

  • nbr

  • iPxsh – array of indices {iPfsh or iPfdp}

  • F – Array of branch β€œfrom” bus indices

  • T – Array of branch β€œto” bus indices

  • Ys – Array of branch series admittances

  • kconv – Array of β€œk2” parameters

  • tap – Array of branch complex taps (m * exp(1j * tau)

  • V – Array of complex voltages

Returns:

  • dSbus_dPfsh, dSf_dPfsh, dSt_dPfsh -> if iPxsh=iPfsh

  • dSbus_dPfdp, dSf_dPfdp, dSt_dPfdp -> if iPxsh=iPfdp

VeraGridEngine.Simulations.Derivatives.csc_derivatives.map_coordinates_numba(nrows, ncols, indptr, indices, F, T)[source]
Parameters:
  • nrows

  • ncols

  • indptr

  • indices

  • F

  • T

Returns:

VeraGridEngine.Simulations.Derivatives.csc_derivatives.xalloc_comp(n)[source]

VeraGridEngine.Simulations.Derivatives.csr_derivatives module

VeraGridEngine.Simulations.Derivatives.csr_derivatives.dSbus_dV_csr(Ybus: csc_matrix, V: ndarray[tuple[Any, ...], dtype[complex128]]) Tuple[csr_matrix, csr_matrix][source]

Calls functions to calculate dS/dV depending on whether Ybus is sparse or not :param Ybus: Ybus in CSC :param V: Voltages vector :return: dS_dVm, dS_dVa in CSR format

VeraGridEngine.Simulations.Derivatives.csr_derivatives.dSbus_dV_numba_sparse_csr(Yx: ndarray[tuple[Any, ...], dtype[complex128]], Yp: ndarray[tuple[Any, ...], dtype[int64]], Yj: ndarray[tuple[Any, ...], dtype[int64]], V: ndarray[tuple[Any, ...], dtype[complex128]], E: ndarray[tuple[Any, ...], dtype[complex128]]) Tuple[ndarray[tuple[Any, ...], dtype[complex128]], ndarray[tuple[Any, ...], dtype[complex128]]][source]

partial derivatives of power injection w.r.t. voltage. :param Yx: Ybus data in CSC format :param Yp: Ybus indptr in CSC format :param Yj: Ybus indices in CSC format :param V: Voltage vector :param E: Normalized voltage vector :return: dS_dVm, dS_dVa data in CSR format, index pointer and indices are the same as the ones from Ybus

VeraGridEngine.Simulations.Derivatives.matpower_derivatives module

VeraGridEngine.Simulations.Derivatives.matpower_derivatives.Jacobian(Ybus, V: ndarray[tuple[Any, ...], dtype[complex128]], idx_dP: ndarray[tuple[Any, ...], dtype[int64]], idx_dQ: ndarray[tuple[Any, ...], dtype[int64]], idx_dVa: ndarray[tuple[Any, ...], dtype[int64]], idx_dVm: ndarray[tuple[Any, ...], dtype[int64]]) csc_matrix[source]

Computes the system Jacobian matrix in polar coordinates Args: :param Ybus: Admittance matrix :param V: Array of nodal voltages :param idx_dVa: vector of indices of PV|PQ|PQV|P buses :param idx_dVm: vector of indices of PQ|P buses :param idx_dP: vector of indices of PV|PQ|PQV|P buses :param idx_dQ: vector of indices of PQ|PQV buses

Returns:

The system Jacobian matrix

VeraGridEngine.Simulations.Derivatives.matpower_derivatives.dIbr_dV_matpower(Yf: csc_matrix, Yt: csc_matrix, V: ndarray[tuple[Any, ...], dtype[complex128]])[source]

Computes partial derivatives of branch currents w.r.t. voltage :param Yf: :param Yt: :param V: :return:

VeraGridEngine.Simulations.Derivatives.matpower_derivatives.dS_dbeq_matpower(V: ndarray[tuple[Any, ...], dtype[complex128]], Cf: csc_matrix, Ct: csc_matrix, k2: ndarray[tuple[Any, ...], dtype[float64]], m: ndarray[tuple[Any, ...], dtype[float64]])[source]
Parameters:
  • V

  • Cf

  • Ct

  • k2

  • m

Returns:

VeraGridEngine.Simulations.Derivatives.matpower_derivatives.dS_dm_matpower(V: ndarray[tuple[Any, ...], dtype[complex128]], Cf: csc_matrix, Ct: csc_matrix, R: ndarray[tuple[Any, ...], dtype[float64]], X: ndarray[tuple[Any, ...], dtype[float64]], B: ndarray[tuple[Any, ...], dtype[float64]], Beq: ndarray[tuple[Any, ...], dtype[float64]], k2: ndarray[tuple[Any, ...], dtype[float64]], m: ndarray[tuple[Any, ...], dtype[float64]], tau: ndarray[tuple[Any, ...], dtype[float64]])[source]
Parameters:
  • V

  • Cf

  • Ct

  • R

  • X

  • B

  • Beq

  • k2

  • m

  • tau

Returns:

VeraGridEngine.Simulations.Derivatives.matpower_derivatives.dS_dtau_matpower(V: ndarray[tuple[Any, ...], dtype[complex128]], Cf: csc_matrix, Ct: csc_matrix, R: ndarray[tuple[Any, ...], dtype[float64]], X: ndarray[tuple[Any, ...], dtype[float64]], k2: ndarray[tuple[Any, ...], dtype[float64]], m: ndarray[tuple[Any, ...], dtype[float64]], tau: ndarray[tuple[Any, ...], dtype[float64]])[source]

Ybus = Cf’ * Yf + Ct’ * Yt + diag(Ysh)

Yf = Yff * Cf + Yft * Ct Yt = Ytf * Cf + Ytt * Ct

Ytt = Ys + 1j*Bc/2 Yff = Gsw+( (Ytt+1j*Beq) ./ ((k2.^2).*tap .* conj(tap)) ) %%<<AAB- FUBM formulation- Original: Yff = Ytt ./ (tap .* conj(tap)); Yft = - Ys ./ conj(tap) Ytf = - Ys ./ tap

Polar coordinates: Partials of Ytt, Yff, Yft and Ytf w.r.t. Theta_shift

dYtt/dsh = zeros(nl,1) dYff/dsh = zeros(nl,1) dYft/dsh = -Ys./(-1j*k2.*conj(tap)) dYtf/dsh = -Ys./( 1j*k2.*tap )

Partials of Yf, Yt, Ybus w.r.t. Theta_shift

dYf/dsh = dYff/dsh * Cf + dYft/dsh * Ct dYt/dsh = dYtf/dsh * Cf + dYtt/dsh * Ct

dYbus/dsh = Cf’ * dYf/dsh + Ct’ * dYt/dsh

Partials of Sbus w.r.t. shift angle

dSbus/dsh = diag(V) * conj(dYbus/dsh * V)

Parameters:
  • V

  • Cf

  • Ct

  • R

  • X

  • k2

  • m

  • tau

Returns:

VeraGridEngine.Simulations.Derivatives.matpower_derivatives.dSbr_dV_matpower(Yf: csc_matrix, Yt: csc_matrix, V: ndarray[tuple[Any, ...], dtype[complex128]], F: ndarray[tuple[Any, ...], dtype[int64]], T: ndarray[tuple[Any, ...], dtype[int64]], Cf: csc_matrix, Ct: csc_matrix) Tuple[csc_matrix, csc_matrix, csc_matrix, csc_matrix][source]

Derivatives of the branch power w.r.t the branch voltage modules and angles :param Yf: Admittances matrix of the Branches with the β€œfrom” buses :param Yt: Admittances matrix of the Branches with the β€œto” buses :param V: Array of voltages :param F: Array of branch β€œfrom” bus indices :param T: Array of branch β€œto” bus indices :param Cf: Connectivity matrix of the Branches with the β€œfrom” buses :param Ct: Connectivity matrix of the Branches with the β€œto” buses :return: dSf_dVa, dSf_dVm, dSt_dVa, dSt_dVm

VeraGridEngine.Simulations.Derivatives.matpower_derivatives.dSbus_dV_matpower(Ybus: csc_matrix, V: ndarray[tuple[Any, ...], dtype[complex128]]) Tuple[csc_matrix, csc_matrix][source]

Derivatives of the power Injections w.r.t the voltage :param Ybus: Admittance matrix :param V: complex voltage arrays :return: dSbus_dVa, dSbus_dVm

VeraGridEngine.Simulations.Derivatives.matpower_derivatives.dSf_dV_matpower(Yf: csc_matrix, V: ndarray[tuple[Any, ...], dtype[complex128]], F: ndarray[tuple[Any, ...], dtype[int64]], Cf: csc_matrix, Vc: ndarray[tuple[Any, ...], dtype[complex128]], diagVc: csc_matrix, diagE: csc_matrix, diagV: csc_matrix) Tuple[csc_matrix, csc_matrix][source]

Derivatives of the branch power β€œfrom” w.r.t the branch voltage modules and angles :param Yf: Admittances matrix of the Branches with the β€œfrom” buses :param V: Array of voltages :param F: Array of branch β€œfrom” bus indices :param Cf: Connectivity matrix of the Branches with the β€œfrom” buses :param Vc: array of conjugate voltages :param diagVc: diagonal matrix of conjugate voltages :param diagE: diagonal matrix of normalized voltages :param diagV: diagonal matrix of voltages :return: dSf_dVa, dSf_dVm

VeraGridEngine.Simulations.Derivatives.matpower_derivatives.dSt_dV_matpower(Yt, V, T, Ct, Vc, diagVc, diagE, diagV)[source]

Derivatives of the branch power β€œto” w.r.t the branch voltage modules and angles :param Yt: Admittances matrix of the Branches with the β€œto” buses :param V: Array of voltages :param T: Array of branch β€œto” bus indices :param Ct: Connectivity matrix of the Branches with the β€œto” buses :param Vc: array of conjugate voltages :param diagVc: diagonal matrix of conjugate voltages :param diagE: diagonal matrix of normalized voltages :param diagV: diagonal matrix of voltages :return: dSf_dVa, dSf_dVm, dSt_dVa, dSt_dVm

Module contents