/ tutorials / laplace-dirichlet
Sign in
tutorials / laplace-dirichlet
laplace-dirichlet / src / chapters / ch01 / chapter.ts
65 lines · 2.1 KBCodeBlameHistory
088be4cAn interactive tutorial on the Dirichlet problem, accuracy against costJeremy Magland 1import { createElement } from 'react'
2import type { Chapter } from '../../ui/types.ts'
3import driver from '../onedim/driver.m?raw'
4import script from './fd2.m?raw'
5import text from './text.md?raw'
6import { Convergence, Solution1D, fmtErr, type SingleOut, type SweepOut } from '../onedim/panels.tsx'
7import { KIND_CONTROL, NS_1D } from '../shared.ts'
9export const ch01: Chapter = {
10 id: 'manufactured',
11 nav: 'Ground truth by construction',
12 part: 'One dimension',
13 title: 'Ground truth by construction',
14 blurb:
15 'The one-dimensional model problem, the method of manufactured solutions, and the three-point difference scheme.',
16 text,
17 labs: [
18 {
19 id: 'first',
20 title: 'One solve',
21 caption: 'Move the resolution and change the solution being manufactured.',
22 driver,
23 script,
24 controls: [
25 KIND_CONTROL,
26 {
27 kind: 'slider',
28 key: 'N',
29 label: 'intervals N',
30 min: 4,
31 max: 128,
32 values: [4, 8, 12, 16, 24, 32, 48, 64, 96, 128, 256],
33 },
34 ],
35 defaults: { kind: 'smooth', mode: 'single', mid: 1, N: 16, ngrid: 700 },
36 editorOpen: true,
37 render: (d: SingleOut) => createElement(Solution1D, { data: d }),
38 summary: (d: SingleOut) => [
39 { label: 'unknowns', value: String(d.n - 1) },
40 { label: 'max error', value: fmtErr(d.maxerr) },
41 ],
42 },
43 {
44 id: 'refine',
45 title: 'Refinement study',
46 caption: 'The same script, run over a sequence of meshes, with the observed order beside each error.',
47 driver,
48 script,
49 controls: [KIND_CONTROL],
50 defaults: { kind: 'smooth', mode: 'sweep', ns: NS_1D, nmaxs: [1e9, 1e9], timed: 0 },
51 render: (d: SweepOut) =>
52 createElement(Convergence, {
53 data: d,
54 style: { slots: ['fd2'], refs: [{ p: -2, label: 'slope -2' }] },
55 }),
56 summary: (d: SweepOut) => {
57 const q = d.orders[0][d.orders[0].length - 1]
58 return [
59 { label: 'finest error', value: fmtErr(d.E[0][d.E[0].length - 1]) },
60 { label: 'observed order', value: q == null ? '--' : q.toFixed(2) },
61 ]
62 },
63 },
64 ],
↑↓ move↵openescclose