/ proof-of-concept / plate-mechanics-sim
Sign in
proof-of-concept / plate-mechanics-sim
plate-mechanics-sim / apps / tutorials / src / embeds / RefinementTable.tsx
70 lines · 2.3 KBCodeBlameHistory
2546961Plate mechanics lab: Kirchhoff-Love plates solved by numbl in the browserJeremy Magland 1import { useEffect, useState } from "react";
2import { FD_METHOD, buildPlanBundle, parseFdPlan, type FdPlan } from "@plate-lab/core";
3import { useRunner } from "@plate-lab/components";
4import { tutorialSpec } from "./tutorialSpec";
6const GRIDS: [number, number][] = [
7 [16, 11],
8 [31, 21],
9 [61, 41],
10 [121, 81],
11];
13/** plate_fd_plan evaluated for a sequence of grids: the numbers come from numbl, not from a formula typed here. */
14export function RefinementTable() {
15 const runner = useRunner();
16 const [rows, setRows] = useState<(FdPlan | null)[]>(GRIDS.map(() => null));
17 useEffect(() => {
18 let cancelled = false;
19 (async () => {
20 const out: (FdPlan | null)[] = [];
21 for (const [nx, ny] of GRIDS) {
22 const s = tutorialSpec();
23 s.fd.nx = nx;
24 s.fd.ny = ny;
25 s.fd.duration = 0.01;
26 const r = await runner.run({ bundle: buildPlanBundle(s, FD_METHOD)! });
27 out.push(r.ok ? parseFdPlan(r.value) : null);
28 if (!cancelled) setRows([...out, ...GRIDS.slice(out.length).map(() => null)]);
29 }
30 })();
31 return () => {
32 cancelled = true;
33 };
34 }, [runner]);
35 return (
36 <div className="embed">
37 <div className="embed-title">Cost of 10 ms of simulated time on the default steel plate, from plate_fd_plan</div>
38 <table>
39 <thead>
40 <tr>
41 <th>grid</th>
42 <th>dx [mm]</th>
43 <th>dt_max [µs]</th>
44 <th>steps</th>
45 <th>cell-steps</th>
46 </tr>
47 </thead>
48 <tbody>
49 {GRIDS.map(([nx, ny], i) => {
50 const p = rows[i];
51 return (
52 <tr key={nx}>
53 <td>
54 {nx} × {ny}
55 </td>
56 <td>{p ? (p.dx * 1000).toFixed(1) : "…"}</td>
57 <td>{p && p.dt_max !== undefined ? (p.dt_max * 1e6).toPrecision(3) : "…"}</td>
58 <td>{p ? p.nsteps.toLocaleString() : "…"}</td>
59 <td>{p ? p.cell_steps.toExponential(2) : "…"}</td>
60 </tr>
61 );
62 })}
63 </tbody>
64 </table>
65 <div className="pl-small pl-muted" style={{ marginTop: 6 }}>
66 Halving dx quarters dt and quadruples the node count: sixteen times the work per unit of simulated time.
67 </div>
68 </div>
69 );
↑↓ move↵openescclose