Skip to main content

powerio_matrix/matrix/
bdoubleprime.rs

1//! MATPOWER-compatible FDPF `Bpp` matrix.
2//!
3//! In fast decoupled power flow, `Bpp` is the fixed approximation to the
4//! reactive power versus voltage magnitude Jacobian block used for the Q step.
5//!
6//! Per MATPOWER `makeB.m`:
7//! - **XB scheme**: `Bpp = -Im(Y_bus)` with phase shifts zeroed.
8//! - **BX scheme**: `Bpp = -Im(Y_bus)` with line resistance and phase shifts
9//!   zeroed.
10//!
11//! Tap ratios, line charging, and bus shunts are kept in both schemes.
12
13use sprs::CsMat;
14
15use crate::Result;
16use crate::indexed::IndexedNetwork;
17
18use super::ybus::{YbusFlags, build_ybus_with_flags};
19use super::{BuildOptions, Scheme, negate_into};
20
21/// Calculate the MATPOWER fast decoupled power flow `Bpp` matrix.
22pub fn calc_bdoubleprime_matrix(case: &IndexedNetwork, opts: &BuildOptions) -> Result<CsMat<f64>> {
23    let flags = YbusFlags {
24        zero_resistance: matches!(opts.scheme, Scheme::Bx),
25        zero_charging: false,
26        unity_taps: false,
27        zero_shifts: true,
28        skip_bus_shunts: false,
29        skip_zero_impedance: opts.skip_zero_impedance,
30    };
31    // `parts.b` is owned and discarded here, so negate it in place rather than
32    // cloning the structure.
33    let parts = build_ybus_with_flags(case, flags)?;
34    Ok(negate_into(parts.b))
35}