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
21pub fn build_bdoubleprime(case: &IndexedNetwork, opts: &BuildOptions) -> Result<CsMat<f64>> {
22 let flags = YbusFlags {
23 zero_resistance: matches!(opts.scheme, Scheme::Bx),
24 zero_charging: false,
25 unity_taps: false,
26 zero_shifts: true,
27 skip_bus_shunts: false,
28 skip_zero_impedance: opts.skip_zero_impedance,
29 };
30 // `parts.b` is owned and discarded here, so negate it in place rather than
31 // cloning the structure.
32 let parts = build_ybus_with_flags(case, flags)?;
33 Ok(negate_into(parts.b))
34}