- 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.
3.5 KiB
3.5 KiB
Entropyk WebAssembly Bindings
WebAssembly bindings for the Entropyk thermodynamic simulation library.
Features
- Browser-native execution: Run thermodynamic simulations directly in the browser
- TabularBackend: Pre-computed fluid tables for fast property lookups (100x faster than direct EOS calls)
- Zero server dependency: No backend required - runs entirely client-side
- Type-safe: Full TypeScript definitions included
- JSON serialization: All results are JSON-serializable for easy integration
Installation
npm install @entropyk/wasm
Quick Start
import init, {
WasmSystem,
WasmCompressor,
WasmCondenser,
WasmEvaporator,
WasmExpansionValve,
WasmFallbackConfig
} from '@entropyk/wasm';
// Initialize the WASM module
await init();
// Create components
const compressor = new WasmCompressor("R134a");
const condenser = new WasmCondenser("R134a", 1000.0);
const evaporator = new WasmEvaporator("R134a", 800.0);
const valve = new WasmExpansionValve("R134a");
// Create system
const system = new WasmSystem();
// Configure solver
const config = new WasmFallbackConfig();
config.timeout_ms(1000);
// Solve
const result = system.solve(config);
console.log(result.toJson());
// {
// "converged": true,
// "iterations": 12,
// "final_residual": 1e-8,
// "solve_time_ms": 45
// }
API Reference
Core Types
WasmPressure- Pressure in Pascals or barWasmTemperature- Temperature in Kelvin or CelsiusWasmEnthalpy- Enthalpy in J/kg or kJ/kgWasmMassFlow- Mass flow rate in kg/s
Components
WasmCompressor- AHRI 540 compressor modelWasmCondenser- Heat rejection heat exchangerWasmEvaporator- Heat absorption heat exchangerWasmExpansionValve- Isenthalpic expansion deviceWasmEconomizer- Internal heat exchanger
Solver
WasmSystem- Thermodynamic system containerWasmNewtonConfig- Newton-Raphson solver configurationWasmPicardConfig- Sequential substitution solver configurationWasmFallbackConfig- Intelligent fallback solver configurationWasmConvergedState- Solver result
Build Requirements
- Rust 1.70+
- wasm-pack:
cargo install wasm-pack - wasm32 target:
rustup target add wasm32-unknown-unknown
Building from Source
# Clone the repository
git clone https://github.com/entropyk/entropyk.git
cd entropyk/bindings/wasm
# Build for browsers
npm run build
# Build for Node.js
npm run build:node
# Run tests
npm test
Performance
| Operation | Target | Typical |
|---|---|---|
| Simple cycle solve | < 100ms | 30-50ms |
| Property query | < 1μs | ~0.5μs |
| Cold start | < 500ms | 200-300ms |
Limitations
- CoolProp unavailable: The WASM build uses TabularBackend with pre-computed tables. CoolProp C++ cannot compile to WebAssembly.
- Limited fluid library: By default, only R134a is embedded. Additional fluids can be loaded from JSON tables.
Loading Custom Fluid Tables
import { load_fluid_table } from '@entropyk/wasm';
// Load a custom fluid table (generated from the entropyk CLI)
const r410aTable = await fetch('/path/to/r410a.json').then(r => r.text());
await load_fluid_table(r410aTable);
Browser Compatibility
- Chrome/Edge 80+
- Firefox 75+
- Safari 14+
- Node.js 14+
License
MIT OR Apache-2.0