feat: implement mass balance validation for Story 7.1
- Added port_mass_flows to Component trait and implements for core components. - Added System::check_mass_balance and integrated it into the solver. - Restored connect methods for ExpansionValve, Compressor, and Pipe to fix integration tests. - Updated Python and C bindings for validation errors. - Updated sprint status and story documentation.
This commit is contained in:
150
bindings/wasm/src/components.rs
Normal file
150
bindings/wasm/src/components.rs
Normal file
@@ -0,0 +1,150 @@
|
||||
//! WASM component bindings (stub).
|
||||
//!
|
||||
//! Provides JavaScript-friendly wrappers for thermodynamic components.
|
||||
//! NOTE: This is a minimal implementation to demonstrate the WASM build.
|
||||
//! Full component bindings require additional development.
|
||||
|
||||
use crate::types::{WasmEnthalpy, WasmMassFlow, WasmPressure, WasmTemperature};
|
||||
use serde::Serialize;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
/// WASM wrapper for Compressor component (stub).
|
||||
#[wasm_bindgen]
|
||||
pub struct WasmCompressor {
|
||||
_fluid: String,
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl WasmCompressor {
|
||||
/// Create a new compressor.
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(fluid: String) -> Result<WasmCompressor, JsValue> {
|
||||
Ok(WasmCompressor { _fluid: fluid })
|
||||
}
|
||||
|
||||
/// Get component name.
|
||||
pub fn name(&self) -> String {
|
||||
"Compressor".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
/// WASM wrapper for Condenser component (stub).
|
||||
#[wasm_bindgen]
|
||||
pub struct WasmCondenser {
|
||||
_fluid: String,
|
||||
_ua: f64,
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl WasmCondenser {
|
||||
/// Create a new condenser.
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(fluid: String, ua: f64) -> Result<WasmCondenser, JsValue> {
|
||||
Ok(WasmCondenser {
|
||||
_fluid: fluid,
|
||||
_ua: ua,
|
||||
})
|
||||
}
|
||||
|
||||
/// Get component name.
|
||||
pub fn name(&self) -> String {
|
||||
"Condenser".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
/// WASM wrapper for Evaporator component (stub).
|
||||
#[wasm_bindgen]
|
||||
pub struct WasmEvaporator {
|
||||
_fluid: String,
|
||||
_ua: f64,
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl WasmEvaporator {
|
||||
/// Create a new evaporator.
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(fluid: String, ua: f64) -> Result<WasmEvaporator, JsValue> {
|
||||
Ok(WasmEvaporator {
|
||||
_fluid: fluid,
|
||||
_ua: ua,
|
||||
})
|
||||
}
|
||||
|
||||
/// Get component name.
|
||||
pub fn name(&self) -> String {
|
||||
"Evaporator".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
/// WASM wrapper for ExpansionValve component (stub).
|
||||
#[wasm_bindgen]
|
||||
pub struct WasmExpansionValve {
|
||||
_fluid: String,
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl WasmExpansionValve {
|
||||
/// Create a new expansion valve.
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(fluid: String) -> Result<WasmExpansionValve, JsValue> {
|
||||
Ok(WasmExpansionValve { _fluid: fluid })
|
||||
}
|
||||
|
||||
/// Get component name.
|
||||
pub fn name(&self) -> String {
|
||||
"ExpansionValve".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
/// WASM wrapper for Economizer component (stub).
|
||||
#[wasm_bindgen]
|
||||
pub struct WasmEconomizer {
|
||||
_fluid: String,
|
||||
_ua: f64,
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl WasmEconomizer {
|
||||
/// Create a new economizer.
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(fluid: String, ua: f64) -> Result<WasmEconomizer, JsValue> {
|
||||
Ok(WasmEconomizer {
|
||||
_fluid: fluid,
|
||||
_ua: ua,
|
||||
})
|
||||
}
|
||||
|
||||
/// Get component name.
|
||||
pub fn name(&self) -> String {
|
||||
"Economizer".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn test_compressor_creation() {
|
||||
let compressor = WasmCompressor::new("R134a".to_string());
|
||||
assert!(compressor.is_ok());
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn test_condenser_creation() {
|
||||
let condenser = WasmCondenser::new("R134a".to_string(), 1000.0);
|
||||
assert!(condenser.is_ok());
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn test_evaporator_creation() {
|
||||
let evaporator = WasmEvaporator::new("R134a".to_string(), 800.0);
|
||||
assert!(evaporator.is_ok());
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn test_expansion_valve_creation() {
|
||||
let valve = WasmExpansionValve::new("R134a".to_string());
|
||||
assert!(valve.is_ok());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user