RustPower is a cutting-edge power flow calculation library written in Rust, specifically designed for steady-state analysis of electrical power systems. With the introduction of ECS-based architecture in version 0.2.0, RustPower offers unparalleled modularity and extensibility.
-
World's First ECS-Based Power Flow Solver:
RustPower now adopts the Entity-Component-System (ECS) architecture using Bevy, enabling modular design and extensibility for domain-specific applications such as:- Time-series simulations.
- Real-time monitoring.
- Custom plugin development.
The legacyPFNetwork
is now deprecated but remains available as a demo for the basic Newton-Raphson solver.
-
Post-Processing Trait:
Added a flexible post-processing trait to manage simulation results, allowing users to handle data as if working with a dataframe. This demonstrates Rust's compositional design philosophy and makes ECS highly effective for handling large datasets. -
Experimental Switch Handling:
Introduced two optional methods for modeling switch elements:- Admittance-Based Method: Adjusts admittance matrices.
- Node-Merging Method: Merges connected nodes for simplified modeling.
These are implemented as plugins and can be enabled as needed.
- High-performance power flow computation with Newton-Raphson.
- Modular and extensible design using ECS for future-proof applications.
- Support for
pandapower
JSON network files (with experimental CSV support). - Handles external grid nodes, transformers, and switch elements.
- Includes both RSparse and KLU solvers (KLU requires
SUITESPARSE_DIR
on Windows).
RustPower achieves industry-leading performance in power flow calculations:
-
IEEE 39-Bus System:
- ~300 microseconds with KLU (3 iterations).
- ~500 microseconds with RSparse solver.
10x faster than Python/Numba implementations.
-
PEGASE 9241 System:
Demonstrates significant performance advantages over Python-based solutions, even without multi-threading. RustPower is highly optimized for speed and avoids the complexity of C/C++ memory management.
As rustpower
is not yet published on Crates.io, you can add it to your project directly from GitHub:
-
Add the following line to your
Cargo.toml
:[dependencies] rustpower = { git = "https://github.com/chengts95/rustpower", branch = "main" }
use ecs::post_processing::PostProcessing; // for print bus results
use rustpower::{io::pandapower::*, prelude::*};
fn main() {
let dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let zipfile = format!("{}/cases/pegase9241/data.zip", dir);
let net = load_csv_zip(&zipfile).unwrap();
// Initialize the ECS application with plugins
let mut pf_net = default_app();
// Register the power network as a resource
pf_net.world_mut().insert_resource(PPNetwork(net));
pf_net.update(); // Initializes the data for the first run
// Retrieve results
let results = pf_net.world().get_resource::<PowerFlowResult>().unwrap();
assert!(results.converged);
println!("Converged in {} iterations", results.iterations);
// Post-process and print results
pf_net.post_process();
pf_net.print_res_bus();
}
For more examples, check the cases
folder.
This project is licensed under the MPLv2 License. See the LICENSE file for more details.
Contributions are welcome! Feel free to open an issue or submit a pull request to help improve the library.
- Tianshi Cheng
This project draws inspiration from:
Although ECS-Grid is a more complex electromagnetic transient (EMT) simulation system, its design philosophy and methodologies greatly influenced the development of this steady-state power flow solver.