import { useEffect, useState } from "react"; import { FD_METHOD, buildPlanBundle, parseFdPlan, type FdPlan } from "@plate-lab/core"; import { useRunner } from "@plate-lab/components"; import { tutorialSpec } from "./tutorialSpec"; const GRIDS: [number, number][] = [ [16, 11], [31, 21], [61, 41], [121, 81], ]; /** plate_fd_plan evaluated for a sequence of grids: the numbers come from numbl, not from a formula typed here. */ export function RefinementTable() { const runner = useRunner(); const [rows, setRows] = useState<(FdPlan | null)[]>(GRIDS.map(() => null)); useEffect(() => { let cancelled = false; (async () => { const out: (FdPlan | null)[] = []; for (const [nx, ny] of GRIDS) { const s = tutorialSpec(); s.fd.nx = nx; s.fd.ny = ny; s.fd.duration = 0.01; const r = await runner.run({ bundle: buildPlanBundle(s, FD_METHOD)! }); out.push(r.ok ? parseFdPlan(r.value) : null); if (!cancelled) setRows([...out, ...GRIDS.slice(out.length).map(() => null)]); } })(); return () => { cancelled = true; }; }, [runner]); return (
| grid | dx [mm] | dt_max [µs] | steps | cell-steps |
|---|---|---|---|---|
| {nx} × {ny} | {p ? (p.dx * 1000).toFixed(1) : "…"} | {p && p.dt_max !== undefined ? (p.dt_max * 1e6).toPrecision(3) : "…"} | {p ? p.nsteps.toLocaleString() : "…"} | {p ? p.cell_steps.toExponential(2) : "…"} |