surge_dc/lib.rs
1// SPDX-License-Identifier: LicenseRef-PolyForm-Noncommercial-1.0.0
2//! Surge DC — DC power flow solver and linear sensitivity analysis.
3//!
4//! # DC Power Flow: Fundamental Assumptions
5//!
6//! The DC power flow model makes **three simultaneous approximations** to linearize
7//! the AC power flow equations:
8//!
9//! 1. **Flat voltage profile** — all bus voltage magnitudes are assumed to be 1.0 p.u.
10//! (`|V_i| = 1.0` for all buses). This eliminates the voltage magnitude unknowns
11//! and decouples P from Q.
12//!
13//! 2. **Small angle differences** — the sine of the voltage angle difference across
14//! each branch is replaced by the angle itself: `sin(theta_i - theta_j) ≈ theta_i - theta_j`.
15//! Valid when angle differences are small (typically < 10-15 degrees).
16//!
17//! 3. **Lossless branches** — branch resistance is neglected (`r ≈ 0`, so that
18//! `g_ij ≈ 0` and the branch admittance is purely imaginary: `y_ij ≈ -j/x_ij`).
19//! This means real power losses (I^2 R) are not captured.
20//!
21//! Together, these yield the linear system:
22//!
23//! ```text
24//! P = B' * theta
25//! ```
26//!
27//! where `B'` is the bus susceptance matrix (with the slack bus row/column removed)
28//! and `theta` is the vector of bus voltage angles. This system is solved with a
29//! single sparse LU factorization (KLU) — no iteration required.
30//!
31//! # What DC Power Flow Does NOT Compute
32//!
33//! Because of the three approximations above, DC power flow **does not** produce:
34//!
35//! - **Voltage magnitudes** — reported as 1.0 p.u. for all buses (assumed, not computed).
36//! - **Reactive power flows** — reported as 0.0 for all buses and branches.
37//! - **Real power losses** — the lossless assumption means branch losses are zero.
38//! - **Voltage-dependent load behavior** — all loads are treated as constant-power at 1.0 p.u.
39//!
40//! For precise power flow results including losses, reactive power, voltage magnitudes,
41//! and voltage-dependent loads, use the AC Newton-Raphson solver in `surge_ac`.
42//!
43//! # When to Use DC Power Flow
44//!
45//! DC power flow is the **industry standard** for applications where speed and linearity
46//! matter more than exact voltage/reactive results:
47//!
48//! - **ISO/RTO real-time market clearing** — all US ISOs (ERCOT, PJM, MISO, CAISO, SPP,
49//! NYISO, ISO-NE) use DC power flow in their Security-Constrained Economic Dispatch (SCED)
50//! and Locational Marginal Price (LMP) engines.
51//! - **Contingency screening** — PTDF/LODF-based N-1 and N-2 screening is orders of
52//! magnitude faster than AC re-solve for each contingency.
53//! - **Transfer capability studies** — ATC/TTC/AFC calculations per NERC methodology.
54//! - **Shift factor computation** — GSF, BLDF, PTDF, LODF for market and planning analysis.
55//! - **Injection capability heatmaps** — FERC Order 2023 interconnection study requirements.
56//!
57//! # Module Structure
58//!
59//! - Top-level exports provide the canonical public API.
60//! - [`streaming`] exposes advanced lazy LODF/N-2 column builders.
61//! - Internal modules cover the DC solver kernel and one-shot sensitivity wrappers.
62//!
63//! Transfer capability analysis (ATC/TTC/AFC, DFAX, stability-limited transfer)
64//! has been consolidated in the `surge_transfer` crate.
65
66pub(crate) mod bprime;
67mod sensitivity;
68mod solver;
69#[cfg(test)]
70mod test_util;
71pub(crate) mod types;
72
73/// Lazy streaming builders for LODF and N-2 LODF column computation.
74pub mod streaming {
75 pub use crate::solver::{LodfColumnBuilder, N2LodfColumnBuilder};
76}
77
78pub use sensitivity::{
79 DcSensitivityOptions, DcSensitivitySlack, LodfMatrixRequest, LodfRequest, N2LodfBatchRequest,
80 N2LodfRequest, OtdfRequest, PtdfRequest, compute_lodf, compute_lodf_matrix, compute_lodf_pairs,
81 compute_n2_lodf, compute_n2_lodf_batch, compute_otdf, compute_ptdf,
82};
83pub use solver::{
84 PreparedDcStudy, compute_loss_sensitivities_adjoint, run_dc_analysis, solve_dc, solve_dc_opts,
85 to_pf_solution,
86};
87pub use surge_network::{AngleReference, DistributedAngleWeight};
88pub use types::{
89 DcAnalysisRequest, DcAnalysisResult, DcError, DcPfOptions, DcPfSolution, LodfMatrixResult,
90 LodfPairs, LodfResult, N2LodfBatchResult, N2LodfResult, OtdfResult, PtdfRows,
91};