# RustRankine **Repository Path**: thermalogic/rust_rankine ## Basic Information - **Project Name**: RustRankine - **Description**: RustRankine - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: oop - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-05-24 - **Last Updated**: 2026-07-05 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # RustRankine The Object-oriented Rust-based Rankine Cycle simulator. It uses JSON configuration files to describe the rankine cycle, and implements automatic creation of equipment objects via `Equipment` enum dispatch, port data sharing through direct `Vec` indexing, and iterative cycle calculations. ## Project * [oop-rankine](oop-rankine) : Rust package of Rankine and wasm version * [rankine_service](rankine_service) : Web service of Rankine simulator ## Dependencies - `serde` / `serde_json`: JSON serialization/deserialization - `wasm-bindgen`: WASM JavaScript bindings - `criterion`: Benchmarking (dev dependency) - `actix-web`: Web service framework (rankine_service) - `seuif97`: IAPWS-IF97 thermodynamic property calculation * seuif97 = { path = "../../iapws-if97/RustSEUIF97" } ## Key Features - **JSON Configuration**: Describe cycle structure and parameters via JSON files - **Equipment Enum Dispatch**: `Equipment` enum with `match` dispatch for zero-cost abstraction - **Port Data Sharing**: Automatic synchronization via direct `Vec` indexing - **Polling Calculation**: Iterative traversal of ready equipment to find calculation order - **IAPWS-IF97**: Accurate thermodynamic properties via `seuif97` - **JSON Output**: `out_results_json()` returns complete simulation results as JSON ## Supported Components | Component | Description | |-----------|-------------| | `Boiler` | Heat addition equipment | | `TurbineEx0` | Single-stage turbine (no extraction) | | `TurbineEx1` | Single extraction turbine | | `Condenser` | Heat rejection equipment | | `Pump` | Feedwater pump | | `OpenedHeaterDw0` | Open feedwater heater | | `ClosedHeaterDw0` | Closed feedwater heater with drain water outlet | | `OpenedHeaterDw1` | Open feedwater heater with drain water inlet | | `Reheater` | Reheat steam equipment | | `Trap` | Drain water throttling device | ## The Example Rankine Cycles Michael J. Moran, Howard N. Shapiro, Daisie D. Boettner, Margaret B. Bailey. Fundamentals of Engineering Thermodynamics(9th Edition). John Wiley & Sons, Inc. 2018 Chapter 8: Vapor Power Systems | File | Description | |------|-------------| | [rankine81.json](./rankine_json_model/rankine81.json) | Basic ideal Rankine cycle | | [rankine82.json](./rankine_json_model/rankine82.json) | Rankine cycle with real components | | [rankine85.json](./rankine_json_model/rankine85.json) | Rankine cycle with feedwater heating | | [rankine86.json](./rankine_json_model/rankine86.json) | Rankine cycle with reheat and regenerative heating | ## Usage ```rust use simrankine::model::load_cycle; use simrankine::rankine::RankineCycle; fn main() { let cycle_config = load_cycle("../rankine_json_model/rankine82.json"); println!("=== Cycle: {} ===", cycle_config.name); let mut cycle = RankineCycle::new(&cycle_config); cycle.simulator(); cycle.out_results(); } ``` ## JSON Output `out_results_json()` returns a JSON string containing: - `name`: Cycle name - `totalwork_extracted`: Turbine work (kJ/kg) - `totalwork_required`: Pump work (kJ/kg) - `netpoweroutput`: Net power output (kJ/kg) - `totalheat_added`: Heat added in boiler/reheater (kJ/kg) - `efficiency`: Cycle efficiency (0-1) - `heat_rate`: Heat rate (kJ/kWh) - `steam_rate`: Steam rate (kg/kWh) - `ports`: Array of port thermodynamic states - `components`: Array of component results with energy values and port data ## Building and Running ### Rust ```bash cargo build --release cargo bench ``` example ```bash cargo run --release --example rankine_demo ``` ### Web Service ```bash cd rankine_service cargo run --release ``` Test with curl: ```bash curl -X POST http://localhost:8080/simulate \ -H "Content-Type: application/json" \ -d @rankine_model_json/rankine86.json ``` ### Building WASM ES Modules #### wasm-bindgen Cargo.toml ```toml [dependencies.wasm-bindgen] version = "0.2.100" optional = true [features] wasm = ["wasm-bindgen"] ``` ```bash cargo build --release --features wasm --target wasm32-unknown-unknown ``` ```bash wasm-bindgen target/wasm32-unknown-unknown/release/simrankine.wasm --out-dir pkg --target web ``` #### wasm-pack Cargo.toml ```toml [dependencies] wasm-bindgen = "0.2.100" [package.metadata.wasm-pack.profile.release] wasm-opt = false ``` ```bash wasm-pack build --out-dir pkg --target web ``` ```bash wasm-pack build --target web ``` #### usage in JavaScript ```javascript import init, { run_cycle_from_json } from './pkg/simrankine.js'; await init(); const jsonResult = run_cycle_from_json(jsonConfigString); const results = JSON.parse(jsonResult); ``` example: * ./oop-rankine/examples/wasm_demo.html.html