Skip to main content

powerio_matrix/
lib.rs

1//! `powerio-matrix`: sparse matrices and graph outputs 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 representation. 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 terminal admittance 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//! [the matrix guide](https://eigenergy.github.io/powerio/guide/matrices.html).
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, GenCostPatch, GenCostPolicyReport,
40    Generator, Hvdc, IndexCore, IndexedNetwork, Load, MissingGenCostPolicy, Network, Parsed,
41    PwdDisplay, PwdSubstation, PypsaCsvOutputs, Result, ScenarioMismatch, Shunt, SourceFormat,
42    Storage, TargetFormat, WriteOptions, convert_file, convert_file_with_options, convert_str,
43    convert_str_with_options, display_format_from_name, error, format, gen_cost, indexed, network,
44    parse_display_bytes, parse_display_file, parse_file, parse_gen_cost_csv, parse_matpower,
45    parse_matpower_file, parse_pandapower_json, parse_powermodels_json, parse_powerworld,
46    parse_pslf, parse_psse, parse_str, read_pypsa_csv_folder, target_format_from_name, write_as,
47    write_as_with_options, write_egret_json, write_matpower, write_pandapower_json,
48    write_powermodels_json, write_powerworld, write_psse, write_pypsa_csv_folder,
49};
50
51pub mod io;
52pub mod matrix;
53pub mod opf_pipeline;
54pub mod pipeline;
55pub mod synth;
56
57pub use matrix::{
58    BuildOptions, BusCosts, DcConvention, GenCosts, GroundedIndexMap, IncidenceParts, MatrixStats,
59    OpfInstance, Scheme, Units, ZeroImpedanceRule, ZeroImpedanceSkips, build_adjacency,
60    build_bdoubleprime, build_bprime, build_flow_map, build_incidence, build_lacpf, build_lodf,
61    build_opf_instance, build_ptdf, build_ptdf_lodf, build_weighted_laplacian, build_ybus,
62    ground_at, ground_at_each, reference_indicator, sddm_check, skipped_zero_impedance,
63    susceptance_diag, unit_vector,
64};
65pub use opf_pipeline::{DcOpfOptions, DcOpfOutputs, write_dcopf_bundle};
66pub use pipeline::{
67    MatrixKind, Pipeline, PipelineOutputs, RhsKind, build_kind, matrix_stats_for_kind,
68    zero_impedance_rule_for_kind, zero_impedance_skips_for_kind,
69};
70
71#[cfg(feature = "gridfm")]
72pub use io::gridfm::{
73    GridfmOptions, GridfmOutputs, GridfmRead, GridfmSnapshot, GridfmTables, gridfm_base_case,
74    gridfm_record_batches, gridfm_record_batches_batch, gridfm_scenario_ids, numbered_snapshots,
75    read_gridfm_dataset, read_gridfm_network, read_gridfm_scenarios, write_gridfm_batch,
76    write_gridfm_dataset,
77};
78#[cfg(feature = "gridfm")]
79pub use io::{dataset_scenario_ids, read_dataset_dir};