/ tutorials / laplace-dirichlet
Sign in
tutorials / laplace-dirichlet
laplace-dirichlet / src / chapters / ch05 / chapter.ts
72 lines · 2.4 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 '../twodim/driver.m?raw'
4import script from './fivepoint.m?raw'
5import text from './text.md?raw'
6import { Fields2D, type Single2DOut } from '../twodim/panels.tsx'
7import { Convergence, fmtErr, type SweepOut } from '../onedim/panels.tsx'
8import { EXACT2D_CONTROL } from '../shared.ts'
9import type { Control } from '../../ui/types.ts'
11const PAR_CONTROL: Control = {
12 kind: 'slider',
13 key: 'par',
14 label: 'shape parameter',
15 min: 1,
16 max: 8,
17 step: 1,
18 format: (v) => String(v),
21export const ch05: Chapter = {
22 id: 'five-point',
23 nav: 'The five-point Laplacian',
24 part: 'Two dimensions',
25 title: 'The five-point Laplacian',
26 blurb: 'Harmonic functions as ground truth, the standard stencil, and the cost of solving the system as it comes.',
27 text,
28 labs: [
29 {
30 id: 'solve',
31 title: 'One solve, and the error field',
32 caption:
33 'The shape parameter is the degree k for poly, the wavenumber k for wave, and the distance from the square for log.',
34 driver,
35 script,
36 editorOpen: true,
37 controls: [
38 EXACT2D_CONTROL,
39 PAR_CONTROL,
40 { kind: 'slider', key: 'N', label: 'N', values: [8, 12, 16, 24, 32, 40], min: 8, max: 40 },
41 ],
42 defaults: { kind: 'expsin', par: 1, mode: 'single', mid: 1, N: 24, maxpix: 97 },
43 render: (d: Single2DOut) => createElement(Fields2D, { data: d }),
44 summary: (d: Single2DOut) => [
45 { label: 'unknowns', value: String(d.unknowns) },
46 { label: 'max error', value: fmtErr(d.maxerr) },
47 ],
48 },
49 {
50 id: 'cost',
51 title: 'Second order, at O(N⁶)',
52 caption: 'Five resolutions. The last one is a 2209 by 2209 dense solve and takes a few seconds in a browser.',
53 driver,
54 script,
55 manual: true,
56 controls: [EXACT2D_CONTROL, PAR_CONTROL],
57 defaults: { kind: 'expsin', par: 1, mode: 'sweep', ns: [4, 8, 16, 32, 48], nmaxs: [48], timed: 1 },
58 render: (d: SweepOut) =>
59 createElement(Convergence, {
60 data: d,
61 style: { slots: ['fd2'], refs: [{ p: -2, label: 'slope −2' }] },
62 }),
63 summary: (d: SweepOut) => [
64 { label: 'finest error', value: fmtErr(d.E[0][d.E[0].length - 1]) },
65 {
66 label: 'time for that',
67 value: `${((d.T[0][d.T[0].length - 1] ?? 0) / 1000).toFixed(2)} s`,
68 },
69 ],
70 },
71 ],
↑↓ move↵openescclose