powerio_matrix/lib.rs
1//! `powerio-matrix`: sparse matrices and graph views for power system case files,
2//! built on [`powerio`] (re-exported, so one `use powerio_matrix::...` pulls in
3//! both layers).
4//!
5//! Signed incidence `A`, weighted Laplacian `L = A diag(b) Aᵀ` and its
6//! reference-grounded form, B'/B''/Y_bus, PTDF/LODF, adjacency, the LACPF block,
7//! and the DC OPF instance bundle, plus a petgraph view. The builders take the
8//! dense-indexed [`IndexedNetwork`] view of a [`Network`].
9//!
10//! ```
11//! use powerio_matrix::{parse_file, IndexedNetwork, build_bprime, BuildOptions};
12//!
13//! # let case = concat!(env!("CARGO_MANIFEST_DIR"), "/../tests/data/case14.m");
14//! let net = parse_file(case, None)?.network; // re-exported from powerio
15//! let g = IndexedNetwork::new(&net); // dense [0, n) analysis view
16//! let bprime = build_bprime(&g, &BuildOptions::default())?;
17//! assert_eq!(bprime.rows(), g.n()); // B' is n×n
18//! # Ok::<(), powerio_matrix::Error>(())
19//! ```
20//!
21//! # Conventions
22//!
23//! B' and the Laplacians use the positive (M-matrix) form: off-diagonal `< 0`,
24//! diagonal `> 0`, `diag = Σ|off-diag|`. Bus ids are 1-based on the
25//! model; [`IndexedNetwork`] maps them to a dense `[0, n)`. `tap == 0` means
26//! `tap = 1`; B' ignores taps and shifts, B'' keeps taps and zeros shifts,
27//! Y_bus keeps both. Branch charging susceptance is stored per unit. DC OPF is
28//! bus indexed
29//! (`p_g ∈ ℝⁿ`), default susceptance `b = 1/x`, with [`DcConvention::Matpower`]
30//! the `1/(x·τ)` plus phase-shift variant. The full reference across every
31//! matrix is in
32//! [docs/matrices.md](https://github.com/eigenergy/powerio/blob/main/docs/matrices.md).
33
34// Re-export the powerio data layer so this crate is a one-stop import, and so
35// the matrix modules' `crate::Error` / `crate::network` / `crate::format` paths
36// resolve unchanged after the split.
37pub use powerio::{
38 Branch, Bus, BusId, BusType, ConnectivityReport, Conversion, DisplayData, DisplayFormat,
39 ElementCounts, Error, ErrorCategory, Extras, GenCost, Generator, Hvdc, IndexCore,
40 IndexedNetwork, Load, Network, Parsed, PwdDisplay, PwdSubstation, PypsaCsvOutputs, Result,
41 ScenarioMismatch, Shunt, SourceFormat, Storage, TargetFormat, convert_file, convert_str,
42 display_format_from_name, error, format, indexed, network, parse_display_bytes,
43 parse_display_file, parse_file, parse_matpower, parse_matpower_file, parse_pandapower_json,
44 parse_powermodels_json, parse_powerworld, parse_psse, parse_str, read_pypsa_csv_folder,
45 target_format_from_name, write_as, write_egret_json, write_matpower, write_pandapower_json,
46 write_powermodels_json, write_powerworld, write_psse, write_pypsa_csv_folder,
47};
48
49pub mod io;
50pub mod matrix;
51pub mod opf_pipeline;
52pub mod pipeline;
53pub mod synth;
54
55pub use matrix::{
56 BuildOptions, BusCosts, DcConvention, GenCosts, GroundedIndexMap, IncidenceParts, MatrixStats,
57 OpfInstance, Scheme, Units, build_adjacency, build_bdoubleprime, build_bprime, build_flow_map,
58 build_incidence, build_lacpf, build_lodf, build_opf_instance, build_ptdf, build_ptdf_lodf,
59 build_weighted_laplacian, build_ybus, ground_at, ground_at_each, reference_indicator,
60 sddm_check, susceptance_diag, unit_vector,
61};
62pub use opf_pipeline::{DcOpfOptions, DcOpfOutputs, write_dcopf_bundle};
63pub use pipeline::{MatrixKind, Pipeline, PipelineOutputs, RhsKind, build_kind};
64
65#[cfg(feature = "gridfm")]
66pub use io::gridfm::{
67 GridfmOptions, GridfmOutputs, GridfmRead, GridfmSnapshot, GridfmTables, gridfm_base_case,
68 gridfm_record_batches, gridfm_record_batches_batch, gridfm_scenario_ids, numbered_snapshots,
69 read_gridfm_dataset, read_gridfm_network, read_gridfm_scenarios, write_gridfm_batch,
70 write_gridfm_dataset,
71};