Update project structure and configurations
This commit is contained in:
@@ -37,97 +37,122 @@
|
||||
border-radius: 4px;
|
||||
overflow-x: auto;
|
||||
}
|
||||
.loading {
|
||||
color: #666;
|
||||
}
|
||||
.error {
|
||||
color: #dc3545;
|
||||
}
|
||||
.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
|
||||
import init, {
|
||||
version,
|
||||
list_available_fluids,
|
||||
WasmSystem,
|
||||
WasmCompressor,
|
||||
WasmCondenser,
|
||||
WasmEvaporator,
|
||||
WasmExpansionValve,
|
||||
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>
|
||||
<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);
|
||||
|
||||
|
||||
// Create components
|
||||
const compressor = new WasmCompressor(
|
||||
"R134a", 2900.0, 0.0001, 0.85,
|
||||
0.85, 2.5, 500.0, 1500.0, -2.5,
|
||||
1.8, 600.0, 1600.0, -3.0, 2.0
|
||||
).into_component();
|
||||
const condenser = new WasmCondenser(5000.0).into_component();
|
||||
const evaporator = new WasmEvaporator(3000.0).into_component();
|
||||
const valve = new WasmExpansionValve("R134a", 0.0).into_component();
|
||||
|
||||
// Add to system
|
||||
const c = system.add_component(compressor);
|
||||
const cd = system.add_component(condenser);
|
||||
const e = system.add_component(evaporator);
|
||||
const v = system.add_component(valve);
|
||||
|
||||
// Connect cycle
|
||||
system.add_edge(c, cd);
|
||||
system.add_edge(cd, v);
|
||||
system.add_edge(v, e);
|
||||
system.add_edge(e, c);
|
||||
system.finalize();
|
||||
|
||||
// Solve
|
||||
const config = new WasmFallbackConfig();
|
||||
const state = system.solve(config);
|
||||
const endTime = performance.now();
|
||||
|
||||
|
||||
let nodeInfo = '';
|
||||
if (state.converged) {
|
||||
const nodeState = system.get_node_result(0);
|
||||
nodeInfo = `<h3>Node 0 State:</h3><pre>${nodeState.toJson()}</pre>`;
|
||||
}
|
||||
|
||||
resultDiv.innerHTML = `
|
||||
<p><strong>Converged:</strong> ${state.converged ? '✓' : '✗'}</p>
|
||||
<p><strong>Converged:</strong> ${state.converged ? 'Yes' : 'No'}</p>
|
||||
<p><strong>Status:</strong> ${state.status}</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>
|
||||
<h3>Result JSON:</h3>
|
||||
<pre>${state.toJson()}</pre>
|
||||
${nodeInfo}
|
||||
`;
|
||||
|
||||
|
||||
} catch (err) {
|
||||
resultDiv.innerHTML = `<p class="error">Error: ${err.message}</p>`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
setup();
|
||||
</script>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user