powerio_matrix/matrix/bprime.rs
1//! MATPOWER-compatible FDPF `Bp` matrix.
2//!
3//! In fast decoupled power flow, `Bp` is the fixed approximation to the active
4//! power versus voltage angle Jacobian block used for the P step.
5//!
6//! Per MATPOWER `makeB.m`, `Bp` is built as `-Im(Y_bus)` after modifying the
7//! network data used for that one matrix:
8//!
9//! - bus shunts are cleared
10//! - line charging is cleared
11//! - tap magnitudes are set to one
12//! - line resistance is cleared in the XB scheme
13//! - phase shifts remain
14//!
15//! With zero phase shifts this has the usual weighted bus Laplacian sign
16//! pattern: stored nonzero off diagonal entries are negative and diagonals are
17//! nonnegative. Phase shifters change the off diagonal terms, matching MATPOWER.
18
19use sprs::CsMat;
20
21use crate::Result;
22use crate::indexed::IndexedNetwork;
23
24use super::ybus::{YbusFlags, build_ybus_with_flags};
25use super::{BuildOptions, Scheme, negate_into};
26
27pub fn build_bprime(case: &IndexedNetwork, opts: &BuildOptions) -> Result<CsMat<f64>> {
28 let flags = YbusFlags {
29 zero_resistance: matches!(opts.scheme, Scheme::Xb),
30 zero_charging: true,
31 unity_taps: true,
32 zero_shifts: false,
33 skip_bus_shunts: true,
34 skip_zero_impedance: opts.skip_zero_impedance,
35 };
36 let parts = build_ybus_with_flags(case, flags)?;
37 Ok(negate_into(parts.b))
38}