pub struct PowerNetwork {
pub buses: Vec<Bus>,
pub branches: Vec<Branch>,
pub generators: Vec<Generator>,
pub base_mva: f64,
}Expand description
AC power network: buses, branches, and generators.
Holds the full topology and parameter data needed to run power flow, OPF, stability analysis, and other studies.
§Example
let net = PowerNetwork::from_matpower("ieee14.m")?;
let result = net.solve_powerflow(&PowerFlowConfig::default())?;
println!("Losses: {:.2} MW", result.total_p_loss_mw);Fields§
§buses: Vec<Bus>All buses (indexed 0..n−1 internally; bus.id holds the external ID).
branches: Vec<Branch>All branches (π-model: r, x, b/2 shunt, tap, shift).
generators: Vec<Generator>All generators (slack, PV, and dispatchable reactive sources).
base_mva: f64System MVA base used throughout for per-unit conversion.
Implementations§
Source§impl PowerNetwork
impl PowerNetwork
Sourcepub fn branch_count(&self) -> usize
pub fn branch_count(&self) -> usize
Number of branches (lines + transformers) in the network.
Sourcepub fn bus_index(&self, bus_id: usize) -> Result<usize>
pub fn bus_index(&self, bus_id: usize) -> Result<usize>
Look up the internal 0-based index for a bus given its external ID.
Returns Err if the bus ID is not found.
Sourcepub fn slack_bus_index(&self) -> Result<usize>
pub fn slack_bus_index(&self) -> Result<usize>
Internal index of the slack bus.
Returns Err if no slack bus is defined (BusType::Slack).
Sourcepub fn admittance_matrix(&self) -> Result<CsMat<Complex64>>
pub fn admittance_matrix(&self) -> Result<CsMat<Complex64>>
Build and return the sparse nodal admittance (Y-bus) matrix.
Uses the π-model for every branch (including transformers with tap + shift).
Sourcepub fn total_load_mw(&self) -> f64
pub fn total_load_mw(&self) -> f64
Total real power load across all buses [MW].
Sourcepub fn total_load_mvar(&self) -> f64
pub fn total_load_mvar(&self) -> f64
Total reactive power load across all buses [MVAr].
Sourcepub fn installed_capacity_mw(&self) -> f64
pub fn installed_capacity_mw(&self) -> f64
Sum of Pmax for all in-service generators [MW] (installed capacity).
Sourcepub fn total_generation_mw(&self) -> f64
pub fn total_generation_mw(&self) -> f64
Sum of current Pg setpoints for all in-service generators [MW].
Sourcepub fn reserve_margin(&self) -> f64
pub fn reserve_margin(&self) -> f64
Reserve margin: (installed capacity − total load) / total load.
Returns f64::INFINITY if total load is zero.
Sourcepub fn n_pq_buses(&self) -> usize
pub fn n_pq_buses(&self) -> usize
Number of PQ buses (load buses).
Sourcepub fn n_pv_buses(&self) -> usize
pub fn n_pv_buses(&self) -> usize
Number of PV buses (generator/voltage-controlled buses).
Sourcepub fn net_injection(&self) -> (Vec<f64>, Vec<f64>)
pub fn net_injection(&self) -> (Vec<f64>, Vec<f64>)
Net scheduled real and reactive power injections at each bus [p.u.].
Returns (p_inj, q_inj) vectors of length bus_count().
Positive = injection into network (generation), negative = load.
Sourcepub fn from_matpower(path: &str) -> Result<Self>
pub fn from_matpower(path: &str) -> Result<Self>
Parse a MATPOWER .m file (Case Format v2).
Accepts any MATPOWER test case: case14, case30, case57, case118, etc.
Sourcepub fn from_ieee_cdf(path: &str) -> Result<Self>
pub fn from_ieee_cdf(path: &str) -> Result<Self>
Parse an IEEE Common Data Format (CDF) file.
Sourcepub fn from_pandapower(path: &str) -> Result<Self>
pub fn from_pandapower(path: &str) -> Result<Self>
Parse a pandapower JSON file.
Sourcepub fn from_pandapower_str(content: &str) -> Result<Self>
pub fn from_pandapower_str(content: &str) -> Result<Self>
Parse pandapower JSON from a string.
Sourcepub fn incidence_matrix(&self) -> Vec<Vec<f64>>
pub fn incidence_matrix(&self) -> Vec<Vec<f64>>
Bus-branch incidence matrix A of size (n_bus × n_branch).
A[i,k] = +1 if branch k leaves bus i (from-bus) = -1 if branch k enters bus i (to-bus) = 0 otherwise
Returns a dense matrix as Vec<Vec
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Returns true if the network graph is fully connected (ignoring branch status).
Uses a BFS from the first bus over all defined branches.
Sourcepub fn degree(&self, bus_id: usize) -> usize
pub fn degree(&self, bus_id: usize) -> usize
Number of branches incident to bus_id (degree in the network graph).
Returns 0 if the bus ID is not found or has no branches.
Source§impl PowerNetwork
impl PowerNetwork
pub fn solve_powerflow( &self, config: &PowerFlowConfig, ) -> Result<PowerFlowResult>
Trait Implementations§
Source§impl Clone for PowerNetwork
impl Clone for PowerNetwork
Source§fn clone(&self) -> PowerNetwork
fn clone(&self) -> PowerNetwork
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PowerNetwork
impl Debug for PowerNetwork
Source§impl<'de> Deserialize<'de> for PowerNetwork
impl<'de> Deserialize<'de> for PowerNetwork
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for PowerNetwork
impl Serialize for PowerNetwork
Source§impl ToDigitalTwin for PowerNetwork
impl ToDigitalTwin for PowerNetwork
fn to_digital_twin(&self, model_id: &str) -> DigitalTwinModel
Auto Trait Implementations§
impl Freeze for PowerNetwork
impl RefUnwindSafe for PowerNetwork
impl Send for PowerNetwork
impl Sync for PowerNetwork
impl Unpin for PowerNetwork
impl UnsafeUnpin for PowerNetwork
impl UnwindSafe for PowerNetwork
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§unsafe fn to_subset_unchecked(&self) -> SS
unsafe fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.