-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex2d.html
More file actions
511 lines (473 loc) · 24 KB
/
Copy pathindex2d.html
File metadata and controls
511 lines (473 loc) · 24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>2D Euler Laboratory</title>
<link rel="stylesheet" href="lab.css">
<!-- React + Babel from CDN -->
<script crossorigin src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<script>
// Force the classic JSX runtime (React.createElement). Recent @babel/standalone
// defaults preset-react to the *automatic* runtime, which emits an
// `import ... "react/jsx-runtime"` that a non-module page with UMD React can't
// resolve — leaving the page stuck on "Loading...". Registering a classic-runtime
// preset keeps everything buildless and dependency-free.
Babel.registerPreset('react-classic', {
presets: [[Babel.availablePresets['react'], { runtime: 'classic' }]]
});
</script>
<!-- 2D solver (math layer, no DOM). -->
<script src="solver2d.js"></script>
</head>
<body>
<div id="root">
<div style="padding: 40px; font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; color: #98a0ab;">
Loading...
</div>
</div>
<script type="text/babel" data-presets="react-classic">
const { useState, useEffect, useMemo, useRef, useCallback } = React;
// ---------- Warm 4-stop perceptual colormap (cream → gold → rust → near-black) ----------
// Matches the existing 1D lab's palette. norm in [0, 1].
const STOPS = [
[247, 242, 227],
[218, 178, 98],
[173, 88, 62],
[ 50, 34, 30]
];
function colormap(norm, out, offset) {
const t = Math.max(0, Math.min(1, norm));
const seg = t * 3;
const i = Math.min(2, Math.floor(seg));
const f = seg - i;
const a = STOPS[i], b = STOPS[i + 1];
out[offset ] = a[0] + (b[0] - a[0]) * f;
out[offset + 1] = a[1] + (b[1] - a[1]) * f;
out[offset + 2] = a[2] + (b[2] - a[2]) * f;
out[offset + 3] = 255;
}
// ---------- 2D heatmap on a canvas ----------
function Heatmap({ result, mode, busy }) {
const canvasRef = useRef(null);
useEffect(() => {
const cv = canvasRef.current;
if (!cv || !result) return;
const { Nx, Ny } = result;
// Pick the field according to view mode.
let field, label;
if (mode === "pressure") { field = result.p; label = "p"; }
else if (mode === "Mach") { field = result.M; label = "M"; }
else if (mode === "schlieren") {
// sqrt(|∇rho|^2) on the interior with one-sided differences at the edges.
const f = new Float64Array(Nx * Ny);
for (let j = 0; j < Ny; j++) {
for (let i = 0; i < Nx; i++) {
const iL = Math.max(0, i - 1), iR = Math.min(Nx - 1, i + 1);
const jB = Math.max(0, j - 1), jT = Math.min(Ny - 1, j + 1);
const gx = result.rho[j * Nx + iR] - result.rho[j * Nx + iL];
const gy = result.rho[jT * Nx + i] - result.rho[jB * Nx + i];
f[j * Nx + i] = Math.sqrt(Math.sqrt(gx * gx + gy * gy));
}
}
field = f; label = "|∇ρ|";
} else { field = result.rho; label = "ρ"; }
let minV = Infinity, maxV = -Infinity;
for (let k = 0; k < field.length; k++) {
if (field[k] < minV) minV = field[k];
if (field[k] > maxV) maxV = field[k];
}
const range = Math.max(maxV - minV, 1e-12);
// Render the heatmap as ImageData. Pixel-perfect mapping: 1 grid cell = 1 pixel.
cv.width = Nx; cv.height = Ny;
const ctx = cv.getContext("2d");
const img = ctx.createImageData(Nx, Ny);
const data = img.data;
// Flip y so that increasing j goes upward in the displayed image.
for (let j = 0; j < Ny; j++) {
const srcRow = j * Nx;
const dstRow = (Ny - 1 - j) * Nx;
for (let i = 0; i < Nx; i++) {
const norm = (field[srcRow + i] - minV) / range;
colormap(norm, data, (dstRow + i) * 4);
}
}
ctx.putImageData(img, 0, 0);
// Stretch via CSS to the canvas display size; let imageSmoothing off look pixelated.
cv.style.imageRendering = "pixelated";
// Tiny min/max readout overlay (in the caption div, not on the canvas).
cv.dataset.label = label;
cv.dataset.min = minV.toExponential(2);
cv.dataset.max = maxV.toExponential(2);
}, [result, mode]);
return (
<div style={{ position: "relative", background: "#1c1a17", padding: 6 }}>
<canvas ref={canvasRef}
style={{ display: "block", width: "100%", height: "auto",
aspectRatio: result ? (result.Nx + "/" + result.Ny) : "1/1",
background: "#1c1a17", opacity: busy ? 0.55 : 1, transition: "opacity 120ms" }} />
</div>
);
}
// ---------- SVG line plot (1D slice through the 2D field) ----------
function LinePlot({ x, y, label, color }) {
const W = 360, H = 200;
const pad = { l: 48, r: 12, t: 24, b: 28 };
const pw = W - pad.l - pad.r, ph = H - pad.t - pad.b;
let yMin = Infinity, yMax = -Infinity;
for (let i = 0; i < y.length; i++) {
if (Number.isFinite(y[i])) {
if (y[i] < yMin) yMin = y[i];
if (y[i] > yMax) yMax = y[i];
}
}
if (!Number.isFinite(yMin)) { yMin = 0; yMax = 1; }
const yPad = Math.max((yMax - yMin) * 0.08, 1e-6);
const yLo = yMin - yPad, yHi = yMax + yPad;
const xMin = x[0], xMax = x[x.length - 1];
const toX = v => pad.l + ((v - xMin) / (xMax - xMin)) * pw;
const toY = v => pad.t + (1 - (v - yLo) / (yHi - yLo)) * ph;
let path = "";
for (let i = 0; i < x.length; i++) {
path += (i === 0 ? "M" : "L") + toX(x[i]).toFixed(2) + " " + toY(y[i]).toFixed(2);
}
const fmt = v => {
const a = Math.abs(v);
if (a === 0) return "0";
if (a < 0.01 || a >= 1000) return v.toExponential(1);
return v.toFixed(a < 1 ? 3 : 2);
};
return (
<svg viewBox={"0 0 " + W + " " + H} style={{ display: "block", width: "100%" }}>
<rect x={pad.l} y={pad.t} width={pw} height={ph} fill="#f7f2e3" stroke="#1c1a17" strokeWidth="0.6" />
{[0.25, 0.5, 0.75].map((f, i) => (
<line key={"v" + i} x1={pad.l + f * pw} x2={pad.l + f * pw} y1={pad.t} y2={pad.t + ph}
stroke="#c8c0aa" strokeWidth="0.4" strokeDasharray="2 3" />
))}
{[0.25, 0.5, 0.75].map((f, i) => (
<line key={"h" + i} x1={pad.l} x2={pad.l + pw} y1={pad.t + f * ph} y2={pad.t + f * ph}
stroke="#c8c0aa" strokeWidth="0.4" strokeDasharray="2 3" />
))}
<path d={path} fill="none" stroke={color} strokeWidth="1.6" strokeLinejoin="round" />
<text x={pad.l} y={pad.t - 8} fontFamily="ui-serif, 'Iowan Old Style', Palatino, Georgia, serif" fontSize="13" fontStyle="italic" fill="#1c1a17">{label}</text>
<text x={pad.l - 6} y={toY(yHi) + 4} fontFamily="ui-monospace, 'SF Mono', Menlo, Consolas, monospace" fontSize="9" fill="#5a5547" textAnchor="end">{fmt(yHi)}</text>
<text x={pad.l - 6} y={toY(yLo) + 4} fontFamily="ui-monospace, 'SF Mono', Menlo, Consolas, monospace" fontSize="9" fill="#5a5547" textAnchor="end">{fmt(yLo)}</text>
<text x={toX(xMin)} y={pad.t + ph + 14} fontFamily="ui-monospace, 'SF Mono', Menlo, Consolas, monospace" fontSize="9" fill="#5a5547" textAnchor="start">{xMin.toFixed(2)}</text>
<text x={toX(xMax)} y={pad.t + ph + 14} fontFamily="ui-monospace, 'SF Mono', Menlo, Consolas, monospace" fontSize="9" fill="#5a5547" textAnchor="end">{xMax.toFixed(2)}</text>
</svg>
);
}
// ---------- Numeric input ----------
function NumField({ label, value, onChange, step }) {
return (
<label style={{ display: "flex", flexDirection: "column", gap: 3, fontFamily: "ui-monospace, 'SF Mono', Menlo, Consolas, monospace", fontSize: 11, color: "var(--ink)" }}>
<span style={{ letterSpacing: "0.08em", textTransform: "uppercase", color: "var(--muted)", fontSize: 9 }}>{label}</span>
<input type="number" value={value} step={step || 0.1}
onChange={e => onChange(parseFloat(e.target.value))}
style={{ fontFamily: "ui-monospace, 'SF Mono', Menlo, Consolas, monospace", fontSize: 13, padding: "5px 7px",
background: "var(--field)", border: "1px solid var(--faint)", color: "var(--ink)",
borderRadius: 0, outline: "none", width: "100%" }} />
</label>
);
}
// ---------- Main app ----------
function App() {
// Default preset = Sod-radial
const presetName0 = "Sod-radial";
const p0 = PRESETS2D[presetName0];
const [presetName, setPresetName] = useState(presetName0);
const [Nx, setNx] = useState(p0.N);
const [Ny, setNy] = useState(p0.N);
const [Lx, setLx] = useState(p0.Lx);
const [Ly, setLy] = useState(p0.Ly);
const [gamma, setGamma] = useState(p0.gamma);
const [cfl, setCfl] = useState(p0.cfl);
const [tEnd, setTEnd] = useState(p0.tEnd);
const [flux, setFlux] = useState("HLLC");
const [viewMode, setViewMode] = useState("density");
const [showSlices, setShowSlices] = useState(true);
const [result, setResult] = useState(null);
const [info, setInfo] = useState({ t: 0, step: 0, ms: 0 });
const [busy, setBusy] = useState(false);
const [err, setErr] = useState(null);
const [animating, setAnimating] = useState(false);
const stateRef = useRef(null);
const rafRef = useRef(null);
const params = useMemo(() => ({
Nx, Ny, Lx, Ly, gamma, cfl, flux,
initFn: PRESETS2D[presetName].init
}), [Nx, Ny, Lx, Ly, gamma, cfl, flux, presetName]);
const validate = () => {
if (gamma <= 1) return "gamma must be > 1.";
if (cfl <= 0 || cfl > 0.9) return "CFL must be in (0, 0.9].";
if (Nx < 20 || Nx > 400) return "Nx must be in [20, 400].";
if (Ny < 20 || Ny > 400) return "Ny must be in [20, 400].";
if (tEnd <= 0) return "t_end must be positive.";
return null;
};
const stopAnim = () => {
if (rafRef.current) cancelAnimationFrame(rafRef.current);
rafRef.current = null;
setAnimating(false);
};
const runFinal = useCallback(() => {
stopAnim();
const e = validate(); if (e) { setErr(e); return; }
setErr(null); setBusy(true);
// Yield to let "computing..." render before the synchronous solve.
setTimeout(() => {
const t0 = performance.now();
let s = initState2D(params);
s = stepUntil2D(s, tEnd);
const ms = performance.now() - t0;
setResult(extract2D(s));
setInfo({ t: s.t, step: s.step, ms });
setBusy(false);
}, 10);
}, [params, tEnd]);
const animate = () => {
stopAnim();
const e = validate(); if (e) { setErr(e); return; }
setErr(null);
const wallStart = performance.now();
let s = initState2D(params);
stateRef.current = s;
setResult(extract2D(s));
setInfo({ t: 0, step: 0, ms: 0 });
setAnimating(true);
// Time-march in chunks of CFL-limited steps so each rAF tick stays responsive.
// We aim for ~20 frames per simulation regardless of step count.
const FRAMES = 40;
let frame = 0;
const tick = () => {
frame++;
const target = Math.min(tEnd, (frame / FRAMES) * tEnd);
stateRef.current = stepUntil2D(stateRef.current, target);
setResult(extract2D(stateRef.current));
setInfo({ t: stateRef.current.t, step: stateRef.current.step,
ms: performance.now() - wallStart });
if (stateRef.current.t < tEnd) {
rafRef.current = requestAnimationFrame(tick);
} else {
rafRef.current = null;
setAnimating(false);
}
};
rafRef.current = requestAnimationFrame(tick);
};
// Initial render on mount
useEffect(() => { runFinal(); /* eslint-disable-next-line */ }, []);
const loadPreset = name => {
stopAnim();
const p = PRESETS2D[name];
setPresetName(name);
setNx(p.N); setNy(p.N);
setLx(p.Lx); setLy(p.Ly);
setGamma(p.gamma); setCfl(p.cfl); setTEnd(p.tEnd);
};
// Slice plots: x-slice through the y-midline, y-slice through the x-midline.
const slices = useMemo(() => {
if (!result || !showSlices) return null;
const jMid = Math.floor(result.Ny / 2);
const iMid = Math.floor(result.Nx / 2);
return {
xs: result.xs, ys: result.ys,
rhoX: slice2D(result.rho, result.Nx, result.Ny, "x", jMid),
pX: slice2D(result.p, result.Nx, result.Ny, "x", jMid),
rhoY: slice2D(result.rho, result.Nx, result.Ny, "y", iMid),
pY: slice2D(result.p, result.Nx, result.Ny, "y", iMid),
jMid, iMid
};
}, [result, showSlices]);
const C = { rho: "#8b3a2f", p: "#4a5d23" };
const fieldLabel = viewMode === "schlieren" ? "|∇ρ| (schlieren)" :
viewMode === "pressure" ? "pressure" :
viewMode === "Mach" ? "Mach" : "density";
return (
<div className="grain" style={{ minHeight: "100vh", background: "var(--bg)", color: "var(--ink)",
fontFamily: "ui-monospace, 'SF Mono', Menlo, Consolas, monospace" }}>
<div style={{ display: "flex", alignItems: "center", gap: 0,
borderBottom: "1.5px solid var(--line)", background: "var(--surface)",
padding: "0 22px", position: "sticky", top: 0, zIndex: 10 }}>
<span className="smallcaps" style={{ fontFamily: "ui-serif, 'Iowan Old Style', Palatino, Georgia, serif", fontStyle: "italic",
fontSize: 13, color: "var(--ink)", padding: "10px 14px 10px 0" }}>
Euler Lab
</span>
<a href="index.html" className="tablink" style={{ fontSize: 11, letterSpacing: "0.08em",
textTransform: "uppercase", padding: "10px 18px 10px 0", borderBottom: "none" }}>
← 1D Shock Tube + Nozzle
</a>
<span style={{ fontSize: 11, letterSpacing: "0.08em", textTransform: "uppercase",
padding: "10px 0", marginLeft: "auto", color: "var(--accent)", fontWeight: 700,
borderBottom: "2.5px solid var(--accent)" }}>
2D Cartesian
</span>
</div>
<details style={{ padding: "8px 22px 0", fontSize: 11, color: "var(--muted)" }}>
<summary style={{ cursor: "pointer", letterSpacing: "0.06em", textTransform: "uppercase", fontSize: 10 }}>
what am I looking at?
</summary>
<p style={{ margin: "6px 0 0", maxWidth: 760, lineHeight: 1.5 }}>
Full 2D compressible Euler on a Cartesian grid. Pick a <i>preset</i> initial condition
(radial Sod, a four-quadrant 2D Riemann problem, the Sedov point blast, or a Kelvin–Helmholtz
shear layer), choose a Riemann <i>flux</i>, then <i>run</i> or <i>animate</i>. The heatmap shows
the chosen field over the whole grid; the line-outs cut through the x- and y-midlines so you can
read wave structure quantitatively. The <b>← 1D</b> link switches to the shock-tube + nozzle lab.
</p>
</details>
<div style={{ padding: "16px 22px 36px" }}>
<header style={{ borderBottom: "1.5px solid var(--line)", paddingBottom: 10, marginBottom: 16 }}>
<div style={{ display: "flex", justifyContent: "space-between", alignItems: "baseline", flexWrap: "wrap", gap: 8 }}>
<h1 style={{ fontFamily: "ui-serif, 'Iowan Old Style', Palatino, Georgia, serif", fontWeight: 600, fontStyle: "italic", fontSize: 34, lineHeight: 1, margin: 0 }}>
2D Euler <span style={{ fontStyle: "normal", fontWeight: 400 }}>{"· cartesian laboratory"}</span>
</h1>
<span className="smallcaps" style={{ fontSize: 10, color: "var(--muted)" }}>{flux + " · MUSCL · SSP-RK2"}</span>
</div>
<p style={{ margin: "6px 0 0", fontSize: 11, color: "var(--muted)", maxWidth: 760 }}>
Pick a 2D initial condition, choose a Riemann flux, and time-march. The heatmap renders the
chosen field across the whole grid; the line-out plots cut through the x- and y-midlines so
you can read the wave structure quantitatively.
</p>
</header>
<div style={{ display: "flex", flexWrap: "wrap", gap: 6, marginBottom: 14, alignItems: "center" }}>
<span className="smallcaps" style={{ fontSize: 10, color: "var(--muted)", marginRight: 4 }}>{"presets ›"}</span>
{Object.keys(PRESETS2D).map(name => (
<button key={name} className="btn" onClick={() => loadPreset(name)}
style={presetName === name ? { background: "var(--accent)", color: "var(--accent-ink)" } : {}}>{name}</button>
))}
</div>
<div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 14, marginBottom: 16 }}>
<fieldset style={{ border: "1px solid var(--faint)", padding: "10px 12px 12px", margin: 0 }}>
<legend className="smallcaps" style={{ fontFamily: "ui-serif, 'Iowan Old Style', Palatino, Georgia, serif", fontStyle: "italic", fontSize: 13, padding: "0 6px" }}>
grid
</legend>
<div style={{ display: "grid", gridTemplateColumns: "1fr 1fr 1fr 1fr", gap: 8 }}>
<NumField label="Nx" value={Nx} onChange={v => setNx(Math.round(v))} step={20} />
<NumField label="Ny" value={Ny} onChange={v => setNy(Math.round(v))} step={20} />
<NumField label="Lx" value={Lx} onChange={setLx} step={0.1} />
<NumField label="Ly" value={Ly} onChange={setLy} step={0.1} />
</div>
</fieldset>
<fieldset style={{ border: "1px solid var(--faint)", padding: "10px 12px 12px", margin: 0 }}>
<legend className="smallcaps" style={{ fontFamily: "ui-serif, 'Iowan Old Style', Palatino, Georgia, serif", fontStyle: "italic", fontSize: 13, padding: "0 6px" }}>
numerics
</legend>
<div style={{ display: "grid", gridTemplateColumns: "1fr 1fr 1fr", gap: 8 }}>
<NumField label="gamma" value={gamma} onChange={setGamma} step={0.05} />
<NumField label="CFL" value={cfl} onChange={setCfl} step={0.05} />
<NumField label="t end" value={tEnd} onChange={setTEnd} step={0.05} />
</div>
</fieldset>
</div>
<div style={{ display: "flex", flexWrap: "wrap", gap: 10, alignItems: "center", marginBottom: 14, padding: "10px 12px",
background: "var(--elevated)", color: "var(--ink)", borderRadius: 10 }}>
<label style={{ display: "flex", alignItems: "center", gap: 6, fontSize: 10, letterSpacing: "0.08em", textTransform: "uppercase" }}>
<span>flux</span>
<select value={flux} onChange={e => setFlux(e.target.value)} style={{ background: "var(--field)", color: "var(--ink)" }}>
<option value="HLLC">HLLC</option>
<option value="HLL">HLL</option>
<option value="Roe">Roe</option>
<option value="Rusanov">Rusanov</option>
</select>
</label>
<label style={{ display: "flex", alignItems: "center", gap: 6, fontSize: 10, letterSpacing: "0.08em", textTransform: "uppercase" }}>
<span>view</span>
<select value={viewMode} onChange={e => setViewMode(e.target.value)} style={{ background: "var(--field)", color: "var(--ink)" }}>
<option value="density">density</option>
<option value="schlieren">schlieren</option>
<option value="pressure">pressure</option>
<option value="Mach">Mach</option>
</select>
</label>
<label style={{ display: "flex", alignItems: "center", gap: 6, fontSize: 10, letterSpacing: "0.08em", textTransform: "uppercase", cursor: "pointer" }}>
<input type="checkbox" checked={showSlices} onChange={e => setShowSlices(e.target.checked)} style={{ accentColor: "var(--accent)" }} />
<span>centerline slices</span>
</label>
<button className="btn btn-primary" onClick={runFinal} disabled={busy || animating}>
{busy ? "computing..." : "run to t_end"}
</button>
<button className="btn" onClick={animate} disabled={busy || animating}
style={{ background: animating ? "var(--accent-2)" : "var(--field)", color: animating ? "var(--accent-ink)" : "var(--ink)" }}>
{animating ? "animating..." : "animate"}
</button>
{animating && <button className="btn" onClick={stopAnim} style={{ background: "var(--field)", color: "var(--ink)" }}>stop</button>}
<div style={{ marginLeft: "auto", fontSize: 11, display: "flex", gap: 18, color: "var(--ink)" }}>
<span><span style={{ color: "var(--muted)" }}>t = </span>{info.t.toFixed(4)}</span>
<span><span style={{ color: "var(--muted)" }}>steps = </span>{info.step}</span>
<span><span style={{ color: "var(--muted)" }}>wall = </span>{info.ms.toFixed(0)} ms</span>
</div>
</div>
{err && (
<div style={{ padding: "8px 12px", border: "1px solid var(--danger)", background: "var(--danger-bg)", color: "var(--accent)",
fontSize: 11, marginBottom: 12 }}>
! {err}
</div>
)}
<div style={{ display: "grid", gridTemplateColumns: showSlices ? "1.6fr 1fr" : "1fr", gap: 14 }}>
<div>
<div className="smallcaps" style={{ fontFamily: "ui-serif, 'Iowan Old Style', Palatino, Georgia, serif", fontStyle: "italic", fontSize: 13, color: "var(--ink)", marginBottom: 4 }}>
{fieldLabel} field {"· " + Nx + " × " + Ny}
</div>
{result && <Heatmap result={result} mode={viewMode} busy={busy} />}
</div>
{showSlices && slices && (
<div style={{ display: "grid", gridTemplateRows: "1fr 1fr 1fr 1fr", gap: 10, background: "var(--elevated)", padding: 10, borderRadius: 12 }}>
<div style={{ background: "#efe9d8", padding: "6px 8px 3px", borderRadius: 8 }}>
<LinePlot x={slices.xs} y={slices.rhoX}
label={"density along y = " + (slices.ys[slices.jMid] || 0).toFixed(3)}
color={C.rho} />
</div>
<div style={{ background: "#efe9d8", padding: "6px 8px 3px", borderRadius: 8 }}>
<LinePlot x={slices.xs} y={slices.pX}
label={"pressure along y = " + (slices.ys[slices.jMid] || 0).toFixed(3)}
color={C.p} />
</div>
<div style={{ background: "#efe9d8", padding: "6px 8px 3px", borderRadius: 8 }}>
<LinePlot x={slices.ys} y={slices.rhoY}
label={"density along x = " + (slices.xs[slices.iMid] || 0).toFixed(3)}
color={C.rho} />
</div>
<div style={{ background: "#efe9d8", padding: "6px 8px 3px", borderRadius: 8 }}>
<LinePlot x={slices.ys} y={slices.pY}
label={"pressure along x = " + (slices.xs[slices.iMid] || 0).toFixed(3)}
color={C.p} />
</div>
</div>
)}
</div>
<footer style={{ marginTop: 16, paddingTop: 10, borderTop: "1px solid var(--line)", fontSize: 10, color: "var(--muted)",
display: "flex", justifyContent: "space-between", flexWrap: "wrap", gap: 8 }}>
<span>dU/dt + dF/dx + dG/dy = 0 {"·"} U = [rho, rho*u, rho*v, E] {"·"} ideal gas</span>
<span className="smallcaps">finite volume {"·"} 2D cartesian {"·"} transmissive BCs</span>
</footer>
</div>
</div>
);
}
// Idempotent mount: reuse a single root so a re-run can never double-mount.
if (!window.__eulerRoot) {
window.__eulerRoot = ReactDOM.createRoot(document.getElementById("root"));
}
window.__eulerRoot.render(<App />);
</script>
<!-- Resilience net (additive, cosmetic-neutral): if @babel/standalone finishes
loading AFTER DOMContentLoaded, its automatic transform of the text/babel
script never fires and the page stays on "Loading...". Kick it manually.
No-op on the normal path (guarded on the "Loading" placeholder). -->
<script>
(function ensureBabelRuns(tries){
var root = document.getElementById('root');
if (!root) return;
if (/Loading\.\.\./.test(root.textContent) && window.Babel && window.React && window.ReactDOM) {
try { window.Babel.transformScriptTags(); } catch (e) {}
}
root = document.getElementById('root');
if (root && /Loading\.\.\./.test(root.textContent) && tries < 60) {
setTimeout(function(){ ensureBabelRuns(tries + 1); }, 120);
}
})(0);
</script>
</body>
</html>