5127df5fastandaccurate: PDE solver benchmarks, laplace-dirichlet-2d with MFS and Nystrom DLP solversJeremy Magland 1// Problem: laplace-dirichlet-2d.
2// The canonical statement lives in docs/problems/laplace-dirichlet-2d.md.
3// This module defines the official instances and the canonical spec object
4// that identifies a (problem, instance) pair in results and, later, in
5// cache keys.
7export const PROBLEM_ID = "laplace-dirichlet-2d";
8export const PROBLEM_VERSION = 1;
10export interface Laplace2dInstance {
11 /** Short stable identifier used in results and URLs. */
12 id: string;
13 label: string;
ad5dc23Three new instances, near-field target sets, and an adaptive timing policyJeremy Magland 14 /** Which boundary family the instance draws from. "star", the default,
15 * is r(t) = 1 + a cos(k t). "rounded-square" is the superellipse
16 * |x|^p + |y|^p = 1, four nearly straight sides meeting at four rounded
17 * corners whose radius falls off like 1.4/p; it is analytic for even p,
18 * so the interface a solver sees is unchanged. */
19 shape?: "star" | "rounded-square";
20 /** Boundary r(t) = 1 + a cos(k t) for the star family; both are 0 and
21 * unused for rounded-square. */
5127df5fastandaccurate: PDE solver benchmarks, laplace-dirichlet-2d with MFS and Nystrom DLP solversJeremy Magland 22 a: number;
23 k: number;
ad5dc23Three new instances, near-field target sets, and an adaptive timing policyJeremy Magland 24 /** Corner sharpness of the rounded-square family (an even integer). */
25 p?: number;
59058e5Add chunkie-dlp solver: mip package support in the harness, curl-backed file I/O for nodeJeremy Magland 26 /** Distance of the exact solution's sources beyond the boundary. */
5127df5fastandaccurate: PDE solver benchmarks, laplace-dirichlet-2d with MFS and Nystrom DLP solversJeremy Magland 27 d: number;
ad5dc23Three new instances, near-field target sets, and an adaptive timing policyJeremy Magland 28 /** Whether the instance carries the near-boundary target set in addition
29 * to the standard evaluation points: points a few thousandths inside the
30 * boundary along the inward normal, where a quadrature rule with no
31 * near-field correction loses its accuracy. */
32 nearBoundary?: boolean;
5127df5fastandaccurate: PDE solver benchmarks, laplace-dirichlet-2d with MFS and Nystrom DLP solversJeremy Magland 33 description: string;
34}
ad5dc23Three new instances, near-field target sets, and an adaptive timing policyJeremy Magland 36/** Whether the instance has corners, and so carries near-corner
37 * evaluation points in addition to the standard set. */
38export function hasCorners(inst: Laplace2dInstance): boolean {
39 return inst.shape === "rounded-square";
40}
42/** Whether the instance carries the near-boundary target set. */
43export function hasNearBoundary(inst: Laplace2dInstance): boolean {
44 return inst.nearBoundary === true;
45}
5127df5fastandaccurate: PDE solver benchmarks, laplace-dirichlet-2d with MFS and Nystrom DLP solversJeremy Magland 47export const INSTANCES: Laplace2dInstance[] = [
48 {
49 id: "disk-easy",
50 label: "Disk, distant sources",
51 a: 0,
52 k: 0,
53 d: 0.5,
54 description:
55 "The unit disk with sources half a radius beyond the boundary. " +
56 "Every reasonable method should reach high accuracy quickly.",
57 },
58 {
59 id: "star-medium",
60 label: "3-lobe star, moderate sources",
61 a: 0.2,
62 k: 3,
63 d: 0.4,
64 description:
65 "A gently star-shaped domain; the data continues comfortably past " +
66 "the boundary, so geometric convergence is attainable but the " +
67 "geometry is no longer trivial.",
68 },
69 {
70 id: "star-hard",
71 label: "5-lobe star, close sources",
72 a: 0.3,
73 k: 5,
74 d: 0.08,
75 description:
76 "A wavier domain with sources only 0.08 beyond the boundary. The " +
77 "data barely continues past the boundary, which defeats methods " +
78 "whose representation assumes it does.",
79 },
ad5dc23Three new instances, near-field target sets, and an adaptive timing policyJeremy Magland 80 {
81 id: "flower-15",
82 label: "15-lobe flower, complex geometry",
83 a: 0.2,
84 k: 15,
85 d: 0.25,
86 description:
87 "Fifteen lobes, with boundary curvature up to 69 (radius 0.014) " +
88 "against 13.9 on star-hard. Here the sources sit a full 0.25 from " +
89 "the boundary, so the data continues comfortably and the difficulty " +
90 "is the geometry alone: a method must resolve a boundary whose " +
91 "features are twenty times smaller than the domain, and the " +
92 "evaluation points, at a fixed fraction of the local radius, fall " +
93 "within 0.03 of it because the boundary runs nearly radially along " +
94 "the flanks of the lobes.",
95 },
96 {
97 id: "square-corners",
98 label: "Rounded square, targets in the corners",
99 shape: "rounded-square",
100 p: 100,
101 a: 0,
102 k: 0,
103 d: 0.25,
104 description:
105 "A square with corners rounded to a radius of 0.014, one percent of " +
106 "its side, and sides that are straight to within a thousandth. " +
107 "Unlike the star instances, the difficulty is local: four small " +
108 "patches of the boundary need everything the discretization has, and " +
109 "the rest needs almost nothing. This instance also carries sixteen " +
110 "extra evaluation points, four at each corner, at 0.005, 0.01, 0.02 " +
111 "and 0.05 inside along the diagonal. The closest sits well within " +
112 "the corner's own radius, which is where a quadrature rule with no " +
113 "near-field correction gives up: the reported error on this instance " +
114 "is normally attained at those points rather than in the bulk.",
115 },
116 {
117 id: "star-nearfield",
118 label: "5-lobe star, targets against the boundary",
119 a: 0.3,
120 k: 5,
121 d: 0.08,
122 nearBoundary: true,
123 description:
124 "The domain and the data of star-hard, asked a different question. " +
125 "Besides the standard evaluation points it carries 32 targets 0.005 " +
126 "to 0.05 inside the boundary, along the inward normal at eight " +
127 "places around the curve. The closest of them is about half a node " +
128 "spacing from the boundary at the resolutions these sweeps reach, " +
129 "and that is where a quadrature rule with no near-field correction " +
130 "stops converging: the error of the plain periodic trapezoid rule " +
131 "at a target a distance delta inside behaves like " +
132 "exp(-2 pi delta / h) in the node spacing h, so it can hold in the " +
133 "bulk long after it has failed here. Because the geometry and the " +
134 "sources are exactly those of star-hard, the difference between the " +
135 "two instances measures one thing only: whether a method can " +
136 "evaluate its own representation close to the boundary.",
137 },
5127df5fastandaccurate: PDE solver benchmarks, laplace-dirichlet-2d with MFS and Nystrom DLP solversJeremy Magland 138];
3452f1bDefault to star-hard; extend the mfs sweep into its conditioning-limited regimeJeremy Magland 140/** The instance a visitor sees first: the one that separates the methods
141 * most sharply. */
142export const DEFAULT_INSTANCE = "star-hard";
5127df5fastandaccurate: PDE solver benchmarks, laplace-dirichlet-2d with MFS and Nystrom DLP solversJeremy Magland 144export function getInstance(id: string): Laplace2dInstance {
145 const inst = INSTANCES.find((i) => i.id === id);
146 if (!inst) throw new Error(`Unknown instance: ${id}`);
147 return inst;
148}
150/**
151 * The canonical spec object for an instance. Serialized with sorted keys,
152 * this string identifies the instance exactly (results carry it, and a
153 * future artifact cache hashes it).
154 */
155export function canonicalSpec(inst: Laplace2dInstance) {
ad5dc23Three new instances, near-field target sets, and an adaptive timing policyJeremy Magland 156 const base = {
5127df5fastandaccurate: PDE solver benchmarks, laplace-dirichlet-2d with MFS and Nystrom DLP solversJeremy Magland 157 a: inst.a,
158 d: inst.d,
159 instance: inst.id,
160 k: inst.k,
161 problem: PROBLEM_ID,
162 problemVersion: PROBLEM_VERSION,
163 };
ad5dc23Three new instances, near-field target sets, and an adaptive timing policyJeremy Magland 164 // The shape keys appear only for instances that are not from the star
165 // family, and nearBoundary only where it is set, so that the spec
166 // strings and hashes of the instances that existed before each of those
167 // fields are exactly what they were.
168 const shaped =
169 !inst.shape || inst.shape === "star"
170 ? base
171 : { ...base, p: inst.p, shape: inst.shape };
172 if (!inst.nearBoundary) return shaped;
173 return { ...shaped, nearBoundary: true };
5127df5fastandaccurate: PDE solver benchmarks, laplace-dirichlet-2d with MFS and Nystrom DLP solversJeremy Magland 174}
176export function canonicalSpecJson(inst: Laplace2dInstance): string {
177 const spec = canonicalSpec(inst);
178 const keys = Object.keys(spec).sort();
179 return JSON.stringify(spec, keys);
180}