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:
134
bindings/wasm/examples/browser/index.html
Normal file
134
bindings/wasm/examples/browser/index.html
Normal file
@@ -0,0 +1,134 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Entropyk WASM Demo</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
|
||||
max-width: 800px;
|
||||
margin: 50px auto;
|
||||
padding: 0 20px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.card {
|
||||
background: #f5f5f5;
|
||||
border-radius: 8px;
|
||||
padding: 20px;
|
||||
margin: 20px 0;
|
||||
}
|
||||
button {
|
||||
background: #007bff;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 10px 20px;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 16px;
|
||||
}
|
||||
button:hover {
|
||||
background: #0056b3;
|
||||
}
|
||||
pre {
|
||||
background: #2d2d2d;
|
||||
color: #f8f8f2;
|
||||
padding: 15px;
|
||||
border-radius: 4px;
|
||||
overflow-x: auto;
|
||||
}
|
||||
.loading {
|
||||
color: #666;
|
||||
}
|
||||
.error {
|
||||
color: #dc3545;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Entropyk WebAssembly Demo</h1>
|
||||
<p>Thermodynamic cycle simulation running entirely in your browser!</p>
|
||||
|
||||
<div class="card">
|
||||
<h2>System Information</h2>
|
||||
<div id="info" class="loading">Loading WASM module...</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<h2>Run Simulation</h2>
|
||||
<button id="runBtn" disabled>Run Simple Cycle</button>
|
||||
<div id="result" style="margin-top: 20px;"></div>
|
||||
</div>
|
||||
|
||||
<script type="module">
|
||||
import init, {
|
||||
version,
|
||||
list_available_fluids,
|
||||
WasmSystem,
|
||||
WasmPressure,
|
||||
WasmTemperature,
|
||||
WasmFallbackConfig
|
||||
} from './pkg/entropyk_wasm.js';
|
||||
|
||||
let initialized = false;
|
||||
|
||||
async function setup() {
|
||||
try {
|
||||
await init();
|
||||
initialized = true;
|
||||
|
||||
const infoDiv = document.getElementById('info');
|
||||
const runBtn = document.getElementById('runBtn');
|
||||
|
||||
infoDiv.innerHTML = `
|
||||
<p><strong>Version:</strong> ${version()}</p>
|
||||
<p><strong>Available Fluids:</strong> ${list_available_fluids().join(', ')}</p>
|
||||
<p style="color: green;">✓ WASM module loaded successfully</p>
|
||||
`;
|
||||
|
||||
runBtn.disabled = false;
|
||||
runBtn.onclick = runSimulation;
|
||||
|
||||
} catch (err) {
|
||||
document.getElementById('info').innerHTML = `
|
||||
<p class="error">Failed to load WASM: ${err.message}</p>
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
function runSimulation() {
|
||||
const resultDiv = document.getElementById('result');
|
||||
resultDiv.innerHTML = '<p class="loading">Running simulation...</p>';
|
||||
|
||||
try {
|
||||
const startTime = performance.now();
|
||||
|
||||
// Create system
|
||||
const system = new WasmSystem();
|
||||
|
||||
// Configure solver
|
||||
const config = new WasmFallbackConfig();
|
||||
config.timeout_ms(1000);
|
||||
|
||||
// Solve
|
||||
const state = system.solve(config);
|
||||
const endTime = performance.now();
|
||||
|
||||
resultDiv.innerHTML = `
|
||||
<p><strong>Converged:</strong> ${state.converged ? '✓' : '✗'}</p>
|
||||
<p><strong>Iterations:</strong> ${state.iterations}</p>
|
||||
<p><strong>Final Residual:</strong> ${state.final_residual.toExponential(2)}</p>
|
||||
<p><strong>Solve Time:</strong> ${(endTime - startTime).toFixed(2)} ms</p>
|
||||
<h3>JSON Output:</h3>
|
||||
<pre>${state.toJson()}</pre>
|
||||
`;
|
||||
|
||||
} catch (err) {
|
||||
resultDiv.innerHTML = `<p class="error">Error: ${err.message}</p>`;
|
||||
}
|
||||
}
|
||||
|
||||
setup();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user