import { createElement } from 'react' import type { Chapter } from '../../ui/types.ts' import driver from '../onedim/driver.m?raw' import script from './fd2.m?raw' import text from './text.md?raw' import { Convergence, Solution1D, fmtErr, type SingleOut, type SweepOut } from '../onedim/panels.tsx' import { KIND_CONTROL, NS_1D } from '../shared.ts' export const ch01: Chapter = { id: 'manufactured', nav: 'Ground truth by construction', part: 'One dimension', title: 'Ground truth by construction', blurb: 'The one-dimensional model problem, the method of manufactured solutions, and the three-point difference scheme.', text, labs: [ { id: 'first', title: 'One solve', caption: 'Move the resolution and change the solution being manufactured.', driver, script, controls: [ KIND_CONTROL, { kind: 'slider', key: 'N', label: 'intervals N', min: 4, max: 128, values: [4, 8, 12, 16, 24, 32, 48, 64, 96, 128, 256], }, ], defaults: { kind: 'smooth', mode: 'single', mid: 1, N: 16, ngrid: 700 }, editorOpen: true, render: (d: SingleOut) => createElement(Solution1D, { data: d }), summary: (d: SingleOut) => [ { label: 'unknowns', value: String(d.n - 1) }, { label: 'max error', value: fmtErr(d.maxerr) }, ], }, { id: 'refine', title: 'Refinement study', caption: 'The same script, run over a sequence of meshes, with the observed order beside each error.', driver, script, controls: [KIND_CONTROL], defaults: { kind: 'smooth', mode: 'sweep', ns: NS_1D, nmaxs: [1e9, 1e9], timed: 0 }, render: (d: SweepOut) => createElement(Convergence, { data: d, style: { slots: ['fd2'], refs: [{ p: -2, label: 'slope -2' }] }, }), summary: (d: SweepOut) => { const q = d.orders[0][d.orders[0].length - 1] return [ { label: 'finest error', value: fmtErr(d.E[0][d.E[0].length - 1]) }, { label: 'observed order', value: q == null ? '--' : q.toFixed(2) }, ] }, }, ], }