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;
14 /** Boundary r(t) = 1 + a cos(k t). */
15 a: number;
16 k: number;
17 /** Distance of the exact solution's sources beyond the boundary. */
18 d: number;
19 description: string;
20}
22export const INSTANCES: Laplace2dInstance[] = [
23 {
24 id: "disk-easy",
25 label: "Disk, distant sources",
26 a: 0,
27 k: 0,
28 d: 0.5,
29 description:
30 "The unit disk with sources half a radius beyond the boundary. " +
31 "Every reasonable method should reach high accuracy quickly.",
32 },
33 {
34 id: "star-medium",
35 label: "3-lobe star, moderate sources",
36 a: 0.2,
37 k: 3,
38 d: 0.4,
39 description:
40 "A gently star-shaped domain; the data continues comfortably past " +
41 "the boundary, so geometric convergence is attainable but the " +
42 "geometry is no longer trivial.",
43 },
44 {
45 id: "star-hard",
46 label: "5-lobe star, close sources",
47 a: 0.3,
48 k: 5,
49 d: 0.08,
50 description:
51 "A wavier domain with sources only 0.08 beyond the boundary. The " +
52 "data barely continues past the boundary, which defeats methods " +
53 "whose representation assumes it does.",
54 },
55];
57/** The instance a visitor sees first: the one that separates the methods
58 * most sharply. */
59export const DEFAULT_INSTANCE = "star-hard";
61export function getInstance(id: string): Laplace2dInstance {
62 const inst = INSTANCES.find((i) => i.id === id);
63 if (!inst) throw new Error(`Unknown instance: ${id}`);
64 return inst;
65}
67/**
68 * The canonical spec object for an instance. Serialized with sorted keys,
69 * this string identifies the instance exactly (results carry it, and a
70 * future artifact cache hashes it).
71 */
72export function canonicalSpec(inst: Laplace2dInstance) {
73 return {
74 a: inst.a,
75 d: inst.d,
76 instance: inst.id,
77 k: inst.k,
78 problem: PROBLEM_ID,
79 problemVersion: PROBLEM_VERSION,
80 };
81}
83export function canonicalSpecJson(inst: Laplace2dInstance): string {
84 const spec = canonicalSpec(inst);
85 const keys = Object.keys(spec).sort();
86 return JSON.stringify(spec, keys);
87}