A fast, modern and safe re-implementation of the EPANET2 hydraulic solver, written in Rust.
Dual-licensed under Apache 2.0 or MIT.
The EPANET2 solver has been the industry standard for hydraulic network simulation for decades due to its robustness, numerical stability, and extensive validation. Its algorithms and results are widely trusted in both academic and industrial applications. The core EPANET2 codebase, however, is several decades old and written in C, making it difficult to maintain, extend, and optimize using modern software engineering practices. In addition, the original implementation predates modern CPU architectures and therefore does not fully exploit multi-core processors or SIMD (Single Instruction, Multiple Data) capabilities.
Modern applications of the EPANET solver, such as monte-carlo simulations, leak detection algorithms and real-time digital twins of huge networks require a more modern implementation, with better performance and maintainability.
epanet-rs is a modern reimplementation of the EPANET2 hydraulic solver written in Rust, designed to preserve the original algorithms and numerical behavior while enabling safer memory management, improved maintainability, and performance optimizations through multi-threading and SIMD acceleration.
epanet-rs runs about as fast as the original EPANET2_3 solver in sequential mode, and up to 5 times faster in parallel mode for extended period simulations for supported networks (no tanks/controls)!
- Numerical Parity with EPANET2_3 solver (hyd_2_3 branch), ensuring identical or equivalent results for the same input
- High Performance through multi-threading, SIMD acceleration and a modern, faer based sparse solver
- Parallelization of the solver loop by rewriting the solver to return vectors of heads and flows instead of in-place assignment
- Memory Safety through Rust's ownership and borrowing system
- Modern API with a focus on ease of use and parallelization
- Backwards Compatibility with EPANET2_3 network API methods
# Run simulation
epanet-rs run <network_file.inp>
# Run with output file (.json format)
epanet-rs run <network_file.inp> output.json
# Run with parallel solving (for extended period simulations without tanks/controls)
epanet-rs run <network_file.inp> < --parallel
# Convert network to different format (JSON or MessagePack)
epanet-rs convert <network_file.inp> output.json
epanet-rs convert <network_file.inp> output.msgpack
# Validate results against EPANET
epanet-rs validate <network_file.inp>use epanet_rs::model::network::Network;
use epanet_rs::simulation::Simulation;
let mut simulation = Simulation::from_file("test.inp").unwrap();
let results = match simulation.solve_hydraulics() {
Ok(results) => results,
Err(e) => {
error!("Solver failed: {}", e);
std::process::exit(1);
}
};# Debug build
cargo build
# Release build (optimized)
cargo build --release# Run all tests
cargo test
# Run solver tests
cargo test --test solver_test- INP file support
- Parallel Hydraulic Solver for extended period simulations
- (Partial) Backwards compatibility with EPANET2_3 network API methods
- Pressure dependent demand simulation
- CONTROLS
- EMITTERS
- LEAKAGE
- RULES
- ENERGY
- Quality simulation
- faer - Sparse linear algebra
- rayon - Parallel iteration
- hashbrown - Fast hash maps
- serde - Serialization
- clap - Command line parsing
- fastapprox - Fast approximations
- log - Logging
- simplelog - Logging
- time - Time
- strum - String enums
- thiserror - Error handling
This library is under active development. Until it is feature-complete, we want to keep close control over its API, architecture, and implementation. We are therefore not accepting pull requests at this stage.
We are building an improved and extended version of EPANET, rather than a one-to-one rewrite of the original C codebase. Existing behavior and implementation choices inform our work, but we may deliberately revisit them to improve the design, functionality, and maintainability of the library.
Ideas, suggestions, and bug reports are welcome. If you would like something changed, please open an issue first so we can discuss the problem, proposed behavior, and how it fits into the library. This includes changes to the public API, architecture, dependencies, and existing code.
We do not accept AI-generated code contributions. Generating more code is not our bottleneck; deciding what belongs in the library and taking responsibility for its design and maintenance is. If we choose to use AI during development, we will do so ourselves under our own review.
The most useful contribution right now is a clear issue: explain your use case, describe the limitation or bug, and include a small reproducible example where relevant.
We may revisit this policy as the library matures.
EPANET-RS is licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
EPANET-RS is heavily inspired by EPANET 2.3 and implements the same hydraulic algorithms and models, with slight modifications to improve performance and memory safety. We acknowledge the original EPANET developers, the OpenWaterAnalytics team and the broader water distribution modeling community for their decades of work establishing these foundations.
Abel Heinsbroek (Vitens N.V.)