Beam step 3: mode bars, mode history, mode energies, note's mode heat map; mode history and mode bars shared in src/common/
11 changed files+187−88
README.mdmodified+1−1View file
@@ -5,7 +5,7 @@ Interactive apps for "Listening for chaos": struck dynamical systems heard as so
55 - `src/double-pendulum/`: double pendulum ([README](src/double-pendulum/README.md)), served at `/double-pendulum/`.
66 - `src/fput-chain/`: FPUT-beta chain ([README](src/fput-chain/README.md)), served at `/fput-chain/`.
77 - `src/beam/`: beam with bending stiffness ([README](src/beam/README.md)), served at `/beam/`.
8-- `src/common/`: code shared by the apps (help dialogs, chart cursor, WAV export, note player, note render loop, mute button, number formats, canvas sizing, λ vs E scatter, strip charts, whole-note spectrogram, Lyapunov exponent by the two-trajectory method with a per-app `Shadow`; Poincare section orbits, their worker, the precomputed atlas and the section panel, with a per-app `Section` and panel configuration) and `style.css`, the shared styles. Each app's `main.ts` imports `../common/style.css` and then its own `style.css`, so app rules come after the shared ones in dev and in the build.
8+- `src/common/`: code shared by the apps (help dialogs, chart cursor, WAV export, note player, note render loop, mode bars and mode-energy heat maps, index colors, mute button, number formats, canvas sizing, λ vs E scatter, strip charts, whole-note spectrogram, Lyapunov exponent by the two-trajectory method with a per-app `Shadow`; Poincare section orbits, their worker, the precomputed atlas and the section panel, with a per-app `Section` and panel configuration) and `style.css`, the shared styles. Each app's `main.ts` imports `../common/style.css` and then its own `style.css`, so app rules come after the shared ones in dev and in the build.
99 - `src/index.html`: landing page linking the apps.
1010
1111 Live site: https://chaos-apps--listening-for-chaos.vault1-sites.magland.org/ (built and deployed by `.github/workflows/pages.yml` on every push to main).
src/beam/README.mdmodified+5−5View file
@@ -1,10 +1,10 @@
11 # beam
22
3-Struck beam with bending stiffness, step 3 of "Listening for chaos" (after double-pendulum and fput-chain). Work in progress: step 1 (physics, animation, sped-up note with spectrogram), step 2 (Lyapunov exponent).
3+Struck beam with bending stiffness, step 3 of "Listening for chaos" (after double-pendulum and fput-chain). Work in progress: step 1 (physics, animation, sped-up note with spectrogram), step 2 (Lyapunov exponent), step 3 (mode bars and mode histories).
44
5-Current state: N masses (2 to 64, default 8) on vertical rails, moving sideways only, with tension k, bending κ and a stretching nonlinearity k3 (below). Ends (a select next to Masses; changing it returns the beam to rest): clamped–clamped (default), pinned–pinned, or cantilever (clamped at the left, free at the right). Strike gives energy E (log slider, 10 µJ to 100 J, default 2.51 J) as velocity, on one mass alone (default mass 2) or in the shape of one normal mode. The card draws the beam from the side, displacements scaled to fit (scale given), with rails as faint lines, a hatched wall for a clamp and a triangle for a pin, plus the time, energy and relative energy error. A "Real time" card on the right has chart chips (`../common/traces.ts`): Lyapunov (on; the largest Lyapunov exponent over the last 10 s and since the strike, last 60 s shown, the first 5 s after a strike left out of the y range) and Energy error (off). The exponent is the two-trajectory method of `../common/lyapunov.ts` with the beam's shadow in `lyapunov.ts`: a hidden second beam 1e-8 away, displacements in units of A / sqrt(N) and momenta in units of m omega_1 A / sqrt(N), A the mode-1 amplitude at the nonlinear scale. Speed 0.1x to 20x real time; Pause or space. Parameters (m, k, κ, k3, a, τ, stretching form) fold out with derived values (mode frequencies, ratios to mode 1, the nonlinear scale, integrator step); Apply returns the beam to rest.
5+Current state: N masses (2 to 64, default 8) on vertical rails, moving sideways only, with tension k, bending κ and a stretching nonlinearity k3 (below). Ends (a select next to Masses; changing it returns the beam to rest): clamped–clamped (default), pinned–pinned, or cantilever (clamped at the left, free at the right). Strike gives energy E (log slider, 10 µJ to 100 J, default 2.51 J) as velocity, on one mass alone (default mass 2) or in the shape of one normal mode. The card draws the beam from the side, displacements scaled to fit (scale given), with rails as faint lines, a hatched wall for a clamp and a triangle for a pin, plus the time, energy and relative energy error. A "Real time" card on the right has chips: Mode bars (on; the current harmonic energy of each mode relative to the strike, log scale over 12 decades, with the number of modes sharing the energy, 1 / sum (E_n / sum E)^2, and the mode frequency range; `../common/modebars.ts`), Mode history (off; each mode's share of the harmonic energy over the last 300 s as a heat map, mode 1 at the bottom; `LiveModeHistory` in `../common/modehistory.ts`), and charts (`../common/traces.ts`): Lyapunov (on; the largest Lyapunov exponent over the last 10 s and since the strike, last 60 s shown, the first 5 s after a strike left out of the y range) Mode energies (off; log, last 60 s, values below 1e-12 of the strike left out) and Energy error (off). The exponent is the two-trajectory method of `../common/lyapunov.ts` with the beam's shadow in `lyapunov.ts`: a hidden second beam 1e-8 away, displacements in units of A / sqrt(N) and momenta in units of m omega_1 A / sqrt(N), A the mode-1 amplitude at the nonlinear scale. Speed 0.1x to 20x real time; Pause or space. Parameters (m, k, κ, k3, a, τ, stretching form) fold out with derived values (mode frequencies, ratios to mode 1, the nonlinear scale, integrator step); Apply returns the beam to rest.
66
7-"Sped up · listen" (as in fput-chain): each Strike renders the same strike in a worker (`render-worker.ts`), sped up so the lowest mode sounds at the Pitch (5 to 1000 Hz, default 100), and plays it; the page starts muted. A damped note is the whole decay to -60 dB. A red warning shows when the top mode is above half the sample rate (it would alias). Signals (`signals.ts`): velocity (default), displacement or acceleration of mass j (default 2), or the sum of accelerations (the net force of the supports). Replay, Save WAV (named e.g. beam-clamped-local-N8-mass2-2.51J-v2-100Hz.wav), spectrogram over the whole note with dashed lines at the mode pitches. Chips: Spectrogram (on), Lyapunov (on; the note's exponent over the last 10 s of physical time, from a shadow run in the worker; the first 5 s of physical time left out of the y range; the shadow runs only while this chart is shown, as it doubles the cost) and Energy (log). The three span the whole note and share one cursor (playhead while playing; hover, click to pin). The render loop is shared with fput-chain (`../common/note-render.ts`). The status line gives the render time (default note 1.0 to 1.4 s with the shadow, 0.6 s without).
7+"Sped up · listen" (as in fput-chain): each Strike renders the same strike in a worker (`render-worker.ts`), sped up so the lowest mode sounds at the Pitch (5 to 1000 Hz, default 100), and plays it; the page starts muted. A damped note is the whole decay to -60 dB. A red warning shows when the top mode is above half the sample rate (it would alias). Signals (`signals.ts`): velocity (default), displacement or acceleration of mass j (default 2), or the sum of accelerations (the net force of the supports). Replay, Save WAV (named e.g. beam-clamped-local-N8-mass2-2.51J-v2-100Hz.wav), spectrogram over the whole note with dashed lines at the mode pitches. Chips: Spectrogram (on), Modes (off; the note's mode-energy shares over the whole note, one column per 256 samples, from the worker; `ModeHistory` in `../common/modehistory.ts`), Lyapunov (on; the note's exponent over the last 10 s of physical time, from a shadow run in the worker; the first 5 s of physical time left out of the y range; the shadow runs only while this chart is shown, as it doubles the cost) and Energy (log). They span the whole note and share one cursor (playhead while playing; hover, click to pin). The render loop is shared with fput-chain (`../common/note-render.ts`). The status line gives the render time (default note 1.0 to 1.4 s with the shadow, 0.6 s without).
88
99 Live site: https://chaos-apps--listening-for-chaos.vault1-sites.magland.org/beam/ (part of the chaos-apps site).
1010
@@ -18,7 +18,7 @@ Live site: https://chaos-apps--listening-for-chaos.vault1-sites.magland.org/beam
1818 - Nonlinear scale: the energy of mode 1 alone at the amplitude where its stretching energy equals its linear energy (N = 8, local: clamped 176 mJ, pinned 8.7 mJ, cantilever 1.1 mJ).
1919 - Damping: drag proportional to mass, every mode's amplitude decays as exp(-t / τ); applied exactly in half steps around each Verlet step, dissipated energy in W.
2020 - Integrator: velocity Verlet, step 0.03 / omega_eff, omega_eff^2 = (Kmax + 12 k3 d^2) / m, Kmax the top eigenvalue of the stiffness matrix and d = (4 E / k3)^(1/4) (Kirchhoff: the k3 term over sqrt(nS)). Relative energy error <= 8e-5 over 200 mode-1 periods, all ends and both forms, 10 mJ to 100 J.
21-- Default note (clamped, local, 2.51 J on mass 2, τ 540 s, 100 Hz): λ ~0.27 /s at the strike (λ T1 ~1.3), falling into the noise of the 10 s window (±0.05 /s) by ~1.6 s of sound (E ~0.14 J), as the spectrogram resolves into lines. Kirchhoff at the same strike: ~0.04 /s, then noise. A 50 mJ strike: noise throughout. Cantilever: ~0.2 /s for the first ~0.3 s of its 1.3 s note.
21+- Default note (clamped, local, 2.51 J on mass 2, τ 540 s, 100 Hz): λ ~0.27 /s at the strike (λ T1 ~1.3), falling into the noise of the 10 s window (±0.05 /s) by ~1.6 s of sound (E ~0.14 J), as the spectrogram resolves into lines. Kirchhoff at the same strike: ~0.04 /s, then noise. A 50 mJ strike: noise throughout. Cantilever: ~0.2 /s for the first ~0.3 s of its 1.3 s note. On Modes, the shares shuffle while λ is up and freeze into steady stripes as it falls (~2 s of sound); on Mode bars about 6 to 7 of the 8 modes share the energy early on.
2222 - First look (offline, N = 8, hammer on mass 2, no damping, two-trajectory Lyapunov exponent times the mode-1 period T1): local stretching is chaotic from ~1 J (clamped 0.57 at 1 J, 3.3 at 10 J; pinned 1.8 at 1 J; cantilever 1.2 at 0.1 J). Kirchhoff is much less chaotic at the same energy (clamped 0.04 at 1 J, 0.24 at 10 J; pinned ~0 up to 1 J, 0.09 at 10 J).
2323
24-Code: `beam.ts` (physics, modes, strikes), `main.ts` (page), `signals.ts`, `render-worker.ts`, `lyapunov.ts` (shadow); shared: `../common/note-render.ts`, `../common/lyapunov.ts`, `../common/traces.ts`, `../common/cursor.ts`, `../common/sound.ts`, `../common/spectrogram.ts`, `../common/wav.ts`, `../common/mute.ts`, `../common/format.ts`, `../common/canvas.ts`, `../common/help.ts`.
24+Code: `beam.ts` (physics, modes, strikes), `main.ts` (page), `signals.ts`, `render-worker.ts`, `lyapunov.ts` (shadow); shared: `../common/note-render.ts`, `../common/modebars.ts`, `../common/modehistory.ts`, `../common/lyapunov.ts`, `../common/traces.ts`, `../common/cursor.ts`, `../common/sound.ts`, `../common/spectrogram.ts`, `../common/wav.ts`, `../common/mute.ts`, `../common/format.ts`, `../common/canvas.ts`, `../common/help.ts`.
src/beam/index.htmlmodified+14−2View file
@@ -72,7 +72,16 @@
7272 </section>
7373 <section class="card">
7474 <div class="card-head">Real time <button type="button" class="help" data-help="realtime" title="About the real-time charts" aria-label="About the real-time charts">?</button></div>
75- <div id="toggles" class="chips"></div>
75+ <div class="chips">
76+ <label class="chip"><input id="bars-toggle" type="checkbox" checked /><span>Mode bars</span></label>
77+ <label class="chip" title="Each mode's share of the energy over the last 300 s"><input id="live-modes-toggle" type="checkbox" /><span>Mode history</span></label>
78+ <span id="toggles"></span>
79+ </div>
80+ <figure id="bars">
81+ <canvas id="modes"></canvas>
82+ <div id="mode-stats" class="num muted"></div>
83+ </figure>
84+ <figure id="live-modes-fig" hidden><div id="live-modes"></div></figure>
7685 <div id="traces"></div>
7786 </section>
7887 </div>
@@ -87,6 +96,7 @@
8796 <button id="save-wav" type="button" disabled title="Save the last note as a WAV file">Save WAV</button>
8897 <span id="sound-chips" class="chips">
8998 <label class="chip"><input id="spec-toggle" type="checkbox" checked /><span>Spectrogram</span></label>
99+ <label class="chip" title="Each mode's share of the energy over the note"><input id="modes-toggle" type="checkbox" /><span>Modes</span></label>
90100 </span>
91101 </div>
92102 <div class="row">
@@ -97,6 +107,7 @@
97107 <div class="row"><span id="sound-status" class="muted"></span></div>
98108 <p id="sound-hint" class="muted">Strike to hear the whole decay.</p>
99109 <figure id="spec-fig"><div id="spectrogram"></div></figure>
110+ <figure id="modes-fig" hidden><div id="mode-history"></div></figure>
100111 <div id="sound-traces"></div>
101112 </details>
102113 </main>
@@ -119,11 +130,12 @@
119130 <h2>Real time</h2>
120131 <p>Charts of the beam on the left, on the same clock. Click a chip to show or hide one; hover to read values, click to pin the cursor.</p>
121132 <p>Lyapunov is the rate (1/s) at which nearby motions separate, measured with a hidden second beam kept a tiny distance away: positive for chaos, near 0 for regular motion. Shown over the last 10 s and since the strike; the first 5 s are left out of the y range. Energy error should stay tiny.</p>
133+ <p>Mode bars show the energy in each normal mode now, relative to the strike, with the number of modes sharing it; Mode energies show the same over time, and Mode history each mode's share as a heat map over the last 300 s (mode 1 at the bottom).</p>
122134 </template>
123135 <template id="help-sound">
124136 <h2>Sped up · listen</h2>
125137 <p>A copy of the same strike, run fast enough to be heard: Pitch sets where the lowest normal mode lands, and the whole decay plays in a few seconds. While this panel is open each Strike plays a note; Replay plays the last one again with the current settings.</p>
126- <p>Save WAV saves the last note as heard (16-bit mono, normalized). Signal chooses what is heard. The charts span the whole note: the spectrogram, with dashed lines at the normal-mode pitches, the Lyapunov exponent over the last 10 s of the beam's own time, and the energy. A warning shows when the top mode is above half the sample rate and would alias.</p>
138+ <p>Save WAV saves the last note as heard (16-bit mono, normalized). Signal chooses what is heard. The charts span the whole note: the spectrogram, with dashed lines at the normal-mode pitches, the Lyapunov exponent over the last 10 s of the beam's own time, the energy, and Modes, each mode's share of the energy as a heat map (mode 1 at the bottom). A warning shows when the top mode is above half the sample rate and would alias.</p>
127139 </template>
128140 <script type="module" src="./main.ts"></script>
129141 </body>
src/beam/main.tsmodified+73−17View file
@@ -4,11 +4,13 @@ import {
44 Modes, Verlet, copyState, energy, newState, nonlinearScale, stepFor, strikeMass, strikeMode,
55 type Ends, type Params, type State, type Stretch,
66 } from "./beam";
7-import { fit } from "../common/canvas";
7+import { fit, indexColor } from "../common/canvas";
88 import { newCursor } from "../common/cursor";
99 import { fmtDuration, fmtEnergy, fmtLength } from "../common/format";
1010 import { setupHelp } from "../common/help";
1111 import { Lyapunov } from "../common/lyapunov";
12+import { drawModeBars } from "../common/modebars";
13+import { LiveModeHistory, ModeHistory } from "../common/modehistory";
1214 import { setupMute } from "../common/mute";
1315 import { DIAG_EVERY, END_RATIO, LYAP_WINDOW, UNDAMPED_LENGTH } from "../common/note-render";
1416 import { Player } from "../common/sound";
@@ -49,11 +51,8 @@ let t = 0;
4951 let running = false;
5052 let ampl = 0; // recent largest |u|, for scaling the drawing
5153 let lastStrike: State | null = null; // state right after the last strike (for the sound)
54+let Ek = new Float64Array(0); // mode energies at the last sample or draw
5255
53-// Colors by index k of n: a few fixed colors, a blue-to-red sweep for more.
54-const PALETTE = ["#2f5d8a", "#c8742c", "#4a8c5c", "#a8476e"];
55-const indexColor = (k: number, n: number) =>
56- n <= PALETTE.length ? PALETTE[k] : `hsl(${215 - (215 * k) / (n - 1)}, 55%, 45%)`;
5756
5857 const strikeEnergy = () => 10 ** Number(energyInput.value);
5958 const showEnergy = () => (energyValue.textContent = fmtEnergy(strikeEnergy()));
@@ -92,8 +91,11 @@ document.getElementById("strike")!.addEventListener("click", () => {
9291 t = 0;
9392 ampl = 0;
9493 lyap.start(shadowOf(P, modes, s), t);
94+ modes.energies(s, Ek);
9595 traces.clear();
9696 traces.sample(t);
97+ liveModes.clear(P.N);
98+ liveModes.sample(t, Ek);
9799 replayButton.disabled = false;
98100 renderNote();
99101 pauseButton.disabled = false;
@@ -111,22 +113,57 @@ const lyap = new Lyapunov(LYAP_WINDOW);
111113 // values swing widely before they settle.
112114 const LYAP_SKIP = 5;
113115
114-// Real-time charts of the beam, sampled every SAMPLE_DT.
115-const traces = new TracePanel(
116- document.getElementById("toggles")!,
117- document.getElementById("traces")!,
118- [
116+// Real-time charts of the beam, sampled every SAMPLE_DT. The mode-energy
117+// chart has one series per mode, so the panel is rebuilt with the parameters
118+// (keeping which charts are on).
119+const togglesEl = document.getElementById("toggles")!;
120+const chartsEl = document.getElementById("traces")!;
121+let traces: TracePanel;
122+function buildTraces(shown: string[]) {
123+ togglesEl.replaceChildren();
124+ chartsEl.replaceChildren();
125+ const g = [
119126 {
120- label: "Lyapunov", unit: "1/s", window: 60, skip: () => LYAP_SKIP, shown: true,
127+ label: "Lyapunov", unit: "1/s", window: 60, skip: () => LYAP_SKIP,
121128 series: [
122129 { label: "λ 10 s", value: () => lyap.windowed() },
123130 { label: "λ since strike", value: () => lyap.mean() },
124131 ],
125132 },
133+ {
134+ // Energies far below the strike's (round-off level) are left out.
135+ label: "Mode energies", unit: "J", log: true, window: 60, color: indexColor,
136+ series: Array.from({ length: P.N }, (_, n) => ({
137+ label: `E${n + 1}`, value: () => (Ek[n] > 1e-12 * E0 ? Ek[n] : NaN),
138+ })),
139+ },
126140 { label: "Energy error", series: [{ label: "energy balance error", value: relErr }] },
127- ],
128- 10,
129-);
141+ ];
142+ traces = new TracePanel(togglesEl, chartsEl, g.map((x) => ({ ...x, shown: shown.includes(x.label) })), 10);
143+}
144+
145+// Mode bars (chip ahead of the trace charts): the current energy of each
146+// mode relative to the strike.
147+const modesCanvas = document.getElementById("modes") as HTMLCanvasElement;
148+const modeStats = document.getElementById("mode-stats")!;
149+const barsToggle = document.getElementById("bars-toggle") as HTMLInputElement;
150+const barsFig = document.getElementById("bars")!;
151+barsToggle.addEventListener("change", () => (barsFig.hidden = !barsToggle.checked));
152+function drawModes() {
153+ if (E0 > 0) modes.energies(s, Ek);
154+ const shared = drawModeBars(modesCanvas, E0 > 0 ? Ek : null, E0, P.N);
155+ const hz = (w: number) => (w / (2 * Math.PI)).toPrecision(3);
156+ modeStats.textContent =
157+ (shared > 0 ? `modes sharing the energy ${shared.toFixed(1)} · ` : "") +
158+ `modes ${hz(modes.omega[0])} … ${hz(modes.omega[P.N - 1])} Hz`;
159+}
160+// Mode history (chip after Mode bars): each mode's share of the energy over
161+// the last 300 s, as a heat map.
162+const liveModes = new LiveModeHistory(300);
163+document.getElementById("live-modes")!.appendChild(liveModes.canvas);
164+const liveModesFig = document.getElementById("live-modes-fig")!;
165+const liveModesToggle = document.getElementById("live-modes-toggle") as HTMLInputElement;
166+liveModesToggle.addEventListener("change", () => (liveModesFig.hidden = !liveModesToggle.checked));
130167
131168 // Parameters: numbers in the form, stretching form in a select; Apply
132169 // restarts at rest. N and the ends are set above the form.
@@ -241,7 +278,15 @@ const soundTraces = new TracePanel(
241278 10, 960, soundCursor,
242279 );
243280 let spec: NoteSpectrogram | null = null;
244-let note: { x: Float32Array; energy: Float32Array; lambda: Float32Array; rate: number } | null = null;
281+let note: {
282+ x: Float32Array; energy: Float32Array; lambda: Float32Array; modeEnergy: Float32Array; N: number; rate: number;
283+} | null = null;
284+// Mode-energy history of the note (chip after Spectrogram).
285+const modeHistory = new ModeHistory(960, soundCursor);
286+document.getElementById("mode-history")!.appendChild(modeHistory.canvas);
287+const modesFig = document.getElementById("modes-fig")!;
288+const modesToggle = document.getElementById("modes-toggle") as HTMLInputElement;
289+modesToggle.addEventListener("change", () => (modesFig.hidden = !modesToggle.checked));
245290 let fed = 0; // samples of the note given to the displays
246291 function feedDisplays(upTo: number) {
247292 if (!note || !spec) return;
@@ -252,6 +297,8 @@ function feedDisplays(upTo: number) {
252297 noteEnergy = note.energy[fed / DIAG_EVERY];
253298 noteLambda = note.lambda[fed / DIAG_EVERY];
254299 soundTraces.sample(fed / note.rate);
300+ const k = fed / DIAG_EVERY;
301+ modeHistory.push((fed + DIAG_EVERY) / note.rate, note.modeEnergy.subarray(k * note.N, (k + 1) * note.N));
255302 }
256303 }
257304 }
@@ -295,7 +342,7 @@ worker.onmessage = (e: MessageEvent<RenderResult>) => {
295342 const rate = player.sampleRate;
296343 const x = e.data.samples;
297344 Player.normalize(x, rate);
298- note = { x, energy: e.data.energy, lambda: e.data.lambda, rate };
345+ note = { x, energy: e.data.energy, lambda: e.data.lambda, modeEnergy: e.data.modeEnergy, N: P.N, rate };
299346 fed = 0;
300347 const span = x.length / rate;
301348 // Spectrogram window: 2048 samples down to a lowest-mode pitch of 30 Hz;
@@ -306,6 +353,7 @@ worker.onmessage = (e: MessageEvent<RenderResult>) => {
306353 soundCursor,
307354 );
308355 spec.start(span);
356+ modeHistory.start(P.N, span);
309357 document.getElementById("spectrogram")!.replaceChildren(spec.canvas);
310358 soundTraces.clear();
311359 soundTraces.setFixed({ t0: 0, span });
@@ -319,6 +367,7 @@ replayButton.addEventListener("click", renderNote);
319367
320368 // Set new parameters: everything back to rest.
321369 function setParams(next: Params) {
370+ const shown = traces ? traces.shownLabels() : ["Lyapunov"];
322371 P = next;
323372 modes = new Modes(P);
324373 H = stepFor(P, modes, 0);
@@ -328,7 +377,9 @@ function setParams(next: Params) {
328377 t = 0;
329378 ampl = 0;
330379 lyap.stop();
331- traces.clear();
380+ Ek = new Float64Array(P.N);
381+ buildTraces(shown);
382+ liveModes.clear(P.N);
332383 nInput.value = String(P.N);
333384 indexInput.max = String(P.N);
334385 indexInput.value = String(strikeIndex());
@@ -477,7 +528,9 @@ function frame(now: number) {
477528 sinceSample += H;
478529 if (sinceSample >= SAMPLE_DT) {
479530 sinceSample -= SAMPLE_DT;
531+ modes.energies(s, Ek);
480532 traces.sample(t);
533+ liveModes.sample(t, Ek);
481534 }
482535 }
483536 }
@@ -485,7 +538,9 @@ function frame(now: number) {
485538 for (const u of s.u) umax = Math.max(umax, Math.abs(u));
486539 ampl = Math.max(umax, 0.998 * ampl);
487540 drawBeam();
541+ if (!barsFig.hidden) drawModes();
488542 traces.draw();
543+ if (!liveModesFig.hidden) liveModes.draw();
489544 if (note && soundPanel.open) {
490545 // Feed the displays up to the audio clock; playhead unless pinned.
491546 const at = player.position();
@@ -494,6 +549,7 @@ function frame(now: number) {
494549 if (!soundCursor.pinned && (at !== null || playing)) soundCursor.t = at;
495550 playing = at !== null;
496551 if (!specFig.hidden) spec?.draw();
552+ if (!modesFig.hidden) modeHistory.draw();
497553 soundTraces.draw();
498554 }
499555 requestAnimationFrame(frame);
src/beam/render-worker.tsmodified+13−3View file
@@ -1,5 +1,6 @@
11 // Renders a note: the beam from a given state, sped up, sampled as audio
2-// (the loop, energy and Lyapunov exponent: ../common/note-render.ts).
2+// (the loop, energy and Lyapunov exponent: ../common/note-render.ts), with
3+// the mode energies, N values per diagnostic sample.
34
45 import { Modes, Verlet, copyState, energy, stepFor, type Params, type State } from "./beam";
56 import { renderNote, type Note } from "../common/note-render";
@@ -20,6 +21,7 @@ export interface RenderRequest {
2021
2122 export interface RenderResult extends Note {
2223 id: number;
24+ modeEnergy: Float32Array; // harmonic energy of each mode (J), N values per diagnostic sample
2325 }
2426
2527 self.onmessage = (e: MessageEvent<RenderRequest>) => {
@@ -29,6 +31,8 @@ self.onmessage = (e: MessageEvent<RenderRequest>) => {
2931 const modes = new Modes(P);
3032 const verlet = new Verlet(P, s);
3133 const signal = signalByKey(r.signal);
34+ const Ek = new Float64Array(P.N);
35+ const modeE: number[] = [];
3236 const note = renderNote(
3337 {
3438 energy: () => energy(P, s),
@@ -36,9 +40,15 @@ self.onmessage = (e: MessageEvent<RenderRequest>) => {
3640 step: (h) => verlet.step(s, h),
3741 signal: () => signal.value(P, s, verlet.force, r.j),
3842 shadow: () => shadowOf(P, modes, s),
43+ diag: () => {
44+ modes.energies(s, Ek);
45+ for (const x of Ek) modeE.push(x);
46+ },
3947 },
4048 { speedup: r.speedup, sampleRate: r.sampleRate, damped: P.tau > 0, maxLength: r.maxLength, lyapunov: r.lyapunov },
4149 );
42- const result: RenderResult = { id: r.id, ...note };
43- (self as unknown as Worker).postMessage(result, [result.samples.buffer, result.energy.buffer, result.lambda.buffer]);
50+ const result: RenderResult = { id: r.id, ...note, modeEnergy: Float32Array.from(modeE.slice(0, note.energy.length * P.N)) };
51+ (self as unknown as Worker).postMessage(result, [
52+ result.samples.buffer, result.energy.buffer, result.lambda.buffer, result.modeEnergy.buffer,
53+ ]);
4454 };
src/beam/style.cssmodified+4−0View file
@@ -7,6 +7,10 @@ canvas { display: block; width: 100%; }
77 #beam { aspect-ratio: 1.4; }
88 .card-head { font-size: 12px; margin-bottom: 12px; display: flex; align-items: center; }
99 #traces canvas, #sound-traces canvas { height: auto; margin-top: 12px; }
10+#modes { aspect-ratio: 2.2; }
11+#mode-stats { margin-top: 6px; }
12+#toggles { display: contents; }
13+#mode-history canvas, #live-modes canvas { width: 100%; height: auto; border-radius: 4px; }
1014 #sound-chips { margin-left: auto; }
1115 input[type="number"] { width: 4.5em; font-family: var(--mono); }
1216 #energy-value { min-width: 4.5em; text-align: right; }
src/common/canvas.tsmodified+6−0View file
@@ -11,3 +11,9 @@ export function fit(canvas: HTMLCanvasElement): CanvasRenderingContext2D {
1111 ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
1212 return ctx;
1313 }
14+
15+// Colors by index k of n (masses, springs, modes): four fixed colors for a
16+// few, a blue-to-red sweep for more.
17+const PALETTE = ["#2f5d8a", "#c8742c", "#4a8c5c", "#a8476e"];
18+export const indexColor = (k: number, n: number) =>
19+ n <= PALETTE.length ? PALETTE[k] : `hsl(${215 - (215 * k) / (n - 1)}, 55%, 45%)`;
src/common/modebars.tsadded+57−0View file
@@ -0,0 +1,57 @@
1+// Mode bars: the harmonic energy of each normal mode relative to a reference
2+// energy (the strike's), on a log scale over DECADES decades, one bar per
3+// mode in the mode's index color.
4+
5+import { fit, indexColor } from "./canvas";
6+
7+const DECADES = 12;
8+const MUTED = "#7a7d82", LINE = "#e3e2dc";
9+
10+// Draw the bars for mode energies E (J) against Eref, or only the axes when E
11+// is null. Returns the number of modes sharing the energy (inverse
12+// participation, 1 / sum (E_n / sum E)^2, over the modes drawn), or NaN.
13+export function drawModeBars(canvas: HTMLCanvasElement, E: Float64Array | null, Eref: number, N: number): number {
14+ const ctx = fit(canvas);
15+ const W = canvas.clientWidth, Ht = canvas.clientHeight;
16+ ctx.clearRect(0, 0, W, Ht);
17+ const left = 40, right = W - 6, top = 8, bottom = Ht - 22;
18+ const yOf = (lg: number) => top + (-lg / DECADES) * (bottom - top); // lg = log10(E_n / Eref), 0 at top
19+
20+ ctx.font = "11px ui-monospace, SFMono-Regular, Menlo, monospace";
21+ ctx.lineWidth = 1;
22+ ctx.textAlign = "right";
23+ ctx.textBaseline = "middle";
24+ for (let d = 0; d <= DECADES; d += 3) {
25+ const y = yOf(-d);
26+ ctx.strokeStyle = LINE;
27+ ctx.beginPath();
28+ ctx.moveTo(left, y);
29+ ctx.lineTo(right, y);
30+ ctx.stroke();
31+ ctx.fillStyle = MUTED;
32+ ctx.fillText(d === 0 ? "1" : `1e-${d}`, left - 6, y);
33+ }
34+
35+ const bw = (right - left) / N;
36+ ctx.textAlign = "center";
37+ ctx.textBaseline = "top";
38+ const every = N <= 16 ? 1 : N <= 32 ? 4 : 8;
39+ for (let n = 1; n <= N; n++) {
40+ if (n === 1 || n % every === 0) ctx.fillText(String(n), left + (n - 0.5) * bw, bottom + 6);
41+ }
42+ ctx.textBaseline = "alphabetic";
43+ ctx.textAlign = "left";
44+
45+ if (!E || !(Eref > 0)) return NaN;
46+ let sum = 0, pr = 0;
47+ for (let n = 0; n < N; n++) sum += E[n];
48+ for (let n = 0; n < N; n++) {
49+ const lg = Math.log10(E[n] / Eref);
50+ if (!(lg > -DECADES)) continue;
51+ const y = yOf(Math.min(0, lg));
52+ ctx.fillStyle = indexColor(n, N);
53+ ctx.fillRect(left + n * bw + 0.15 * bw, y, 0.7 * bw, bottom - y);
54+ pr += (E[n] / sum) ** 2;
55+ }
56+ return pr > 0 ? 1 / pr : NaN;
57+}
src/fput-chain/modehistory.ts →src/common/modehistory.tsrenamed+3−3View file
@@ -5,8 +5,8 @@
55 // decades, so the picture does not fade as the note decays. Columns arrive
66 // as the audio clock reaches them. An optional shared time cursor is drawn.
77
8-import { attachCursor, type Cursor } from "../common/cursor";
9-import { colormap } from "../common/spectrogram";
8+import { attachCursor, type Cursor } from "./cursor";
9+import { colormap } from "./spectrogram";
1010
1111 const HEIGHT = 160;
1212 const DECADES = 6;
@@ -100,7 +100,7 @@ export class ModeHistory {
100100 }
101101 }
102102
103-// The same picture for the animated chain, scrolling: the last `window`
103+// The same picture for the animated system, scrolling: the last `window`
104104 // seconds, newest at the right (each mode's share of the harmonic energy;
105105 // samples closer than window / LIVE_CAP / 2 to the previous kept one are
106106 // skipped, so the ring always spans the window).
src/fput-chain/README.mdmodified+2−2View file
@@ -2,9 +2,9 @@
22
33 Struck FPUT-beta chain, step 2 of "Listening for chaos" (after double-pendulum-chaos). Work in progress.
44
5-Current state: N masses (2 to 64, default 2) between two fixed walls, joined by springs with tension k d + k3 d^3. The chain sits at rest until Strike, which gives it energy E (log slider, 10 µJ to 100 J, default 2.51 J) as velocity, either on one mass j alone (default mass 1, a hammer blow at one end) or in the shape of one normal mode n. The left card animates the chain (top: to scale, rest spacing a; below: the same displacements drawn sideways as a profile, scaled to fit, with the scale given) with the time and the relative energy error. Speed: 0.1x to 20x real time (default 1x). The time and current energy show at the top left. The Ghost chip (as in the pendulum app) adds a second chain started from the same state with every mass moved by the same amount, 10^k / sqrt(N) m (total offset 10^k m, k = -12 to -1, default -10; moving only the struck mass would put the offset along the motion itself, which does not grow), run in lockstep without renormalization and drawn in translucent orange underneath; restarted on Strike, on "Restart ghost" (from the chain's current state), when switched on or when the offset changes; a readout gives the separation (root sum of squared displacement differences, m) and the time since the ghost started, and a "Separation" chart (log, last 60 s; offered only with the ghost on) plots it. A "Lyapunov" chart (last 60 s; the first 5 s after a strike left out of its y range) shows the largest Lyapunov exponent over the last 10 s and since the strike (`../common/lyapunov.ts`, two-trajectory Benettin method shared with the pendulum app, with the chain's shadow in `lyapunov.ts`: a hidden shadow chain 1e-8 away, displacements in units of d0 and momenta in units of sqrt(m k) d0, renormalized every step). Checked (N = 4, mass-1 strike, 300 s): without damping 0.1 J ~0.05 to 0.1 /s (weak chaos; N = 4 onset is near 3 k d0^2 = 75 mJ), 0.5 J ~0.5 /s, 2.51 J ~0.9 /s, 25 J ~1.7 /s; with tau 540 s, 0.1 J falls to ~0.01 /s and 2.51 J falls from ~1.0 to ~0.3 /s by 300 s. The slider is labelled "Strike energy". Parameters (m, k, k3, a, tau) fold out underneath with derived values (mode frequencies, d0, nonlinear energy scale, integrator step); Apply or changing N returns the chain to rest. The "Real time" card on the right has toggle chips for its charts. "Mode history" (off by default) is a scrolling heat map of each mode's share of the harmonic energy, log10(E_n / sum E) over 6 decades (inferno colors, mode 1 at the bottom), over the last 300 s (`LiveModeHistory` in `modehistory.ts`); the cascade of energy up the modes shows here (e.g. N = 32, mode-1 strike at 10 mJ: the top mode's share goes from ~1e-28 to ~1e-12 in 10 periods of mode 1 and ~3e-5 in 50 without damping; with tau 540 s the damping wins and the spread stalls near mode 17). "Mode bars" shows the current harmonic energy of each normal mode relative to E on a log scale (12 decades), with the number of modes sharing the energy (inverse participation, 1 / sum (E_n / sum E)^2). The other chips are charts over time (from `../common/traces.ts` and `../common/cursor.ts`, with per-group colors and a legend capped at 8 series): displacements, velocities, spring stretches, mode energies (log, last 60 s; values below 1e-12 of E left out), energies (E, T, V, W dissipated) and the energy balance error ((E + W - E0) / E0); others last 10 s; sampled every 10 ms; hover for values, click to pin. Mode bars, displacements and mode energies are on by default. Masses, springs and modes share one color per index (four fixed colors for up to 4, a blue-to-red sweep beyond).
5+Current state: N masses (2 to 64, default 2) between two fixed walls, joined by springs with tension k d + k3 d^3. The chain sits at rest until Strike, which gives it energy E (log slider, 10 µJ to 100 J, default 2.51 J) as velocity, either on one mass j alone (default mass 1, a hammer blow at one end) or in the shape of one normal mode n. The left card animates the chain (top: to scale, rest spacing a; below: the same displacements drawn sideways as a profile, scaled to fit, with the scale given) with the time and the relative energy error. Speed: 0.1x to 20x real time (default 1x). The time and current energy show at the top left. The Ghost chip (as in the pendulum app) adds a second chain started from the same state with every mass moved by the same amount, 10^k / sqrt(N) m (total offset 10^k m, k = -12 to -1, default -10; moving only the struck mass would put the offset along the motion itself, which does not grow), run in lockstep without renormalization and drawn in translucent orange underneath; restarted on Strike, on "Restart ghost" (from the chain's current state), when switched on or when the offset changes; a readout gives the separation (root sum of squared displacement differences, m) and the time since the ghost started, and a "Separation" chart (log, last 60 s; offered only with the ghost on) plots it. A "Lyapunov" chart (last 60 s; the first 5 s after a strike left out of its y range) shows the largest Lyapunov exponent over the last 10 s and since the strike (`../common/lyapunov.ts`, two-trajectory Benettin method shared with the pendulum app, with the chain's shadow in `lyapunov.ts`: a hidden shadow chain 1e-8 away, displacements in units of d0 and momenta in units of sqrt(m k) d0, renormalized every step). Checked (N = 4, mass-1 strike, 300 s): without damping 0.1 J ~0.05 to 0.1 /s (weak chaos; N = 4 onset is near 3 k d0^2 = 75 mJ), 0.5 J ~0.5 /s, 2.51 J ~0.9 /s, 25 J ~1.7 /s; with tau 540 s, 0.1 J falls to ~0.01 /s and 2.51 J falls from ~1.0 to ~0.3 /s by 300 s. The slider is labelled "Strike energy". Parameters (m, k, k3, a, tau) fold out underneath with derived values (mode frequencies, d0, nonlinear energy scale, integrator step); Apply or changing N returns the chain to rest. The "Real time" card on the right has toggle chips for its charts. "Mode history" (off by default) is a scrolling heat map of each mode's share of the harmonic energy, log10(E_n / sum E) over 6 decades (inferno colors, mode 1 at the bottom), over the last 300 s (`LiveModeHistory` in `../common/modehistory.ts`); the cascade of energy up the modes shows here (e.g. N = 32, mode-1 strike at 10 mJ: the top mode's share goes from ~1e-28 to ~1e-12 in 10 periods of mode 1 and ~3e-5 in 50 without damping; with tau 540 s the damping wins and the spread stalls near mode 17). "Mode bars" (`../common/modebars.ts`) shows the current harmonic energy of each normal mode relative to E on a log scale (12 decades), with the number of modes sharing the energy (inverse participation, 1 / sum (E_n / sum E)^2). The other chips are charts over time (from `../common/traces.ts` and `../common/cursor.ts`, with per-group colors and a legend capped at 8 series): displacements, velocities, spring stretches, mode energies (log, last 60 s; values below 1e-12 of E left out), energies (E, T, V, W dissipated) and the energy balance error ((E + W - E0) / E0); others last 10 s; sampled every 10 ms; hover for values, click to pin. Mode bars, displacements and mode energies are on by default. Masses, springs and modes share one color per index (four fixed colors for up to 4, a blue-to-red sweep beyond).
66
7-"Sped up · listen" (open by default, below the cards; otherwise as in the pendulum app): the header says how much faster it runs ("the whole decay, 321× faster: 62 min of motion in 12 s"; without damping "321× faster than the chain above"). The page starts muted (the mute button is tinted red and reads "Muted"; muted notes are still computed and shown); the audio context is created at the first Strike; closing the panel stops the note. While it is open each Strike plays a note, the same strike rendered in a Web Worker (`render-worker.ts`, on the loop shared with the beam app in `../common/note-render.ts`) sped up so the lowest linear mode sounds at the Pitch (5 to 1000 Hz, default 100; below ~20 Hz the lowest modes are below hearing but show in the spectrogram; the readout gives the lowest and highest mode pitches). A damped note is the whole decay, ending when its energy has fallen to 1e-6 of the strike's (-60 dB; predicted length (tau/2) ln 1e6 of physical time, 11.6 s of sound by default, measured 11.3 s; capped at twice that); undamped notes last 10 s. "Strike to hear the whole decay." shows until the first note; the status line gives the signal and note length ("computing…" while rendering). Replay plays the last strike again with the current settings (to compare signals). Signal (`signals.ts`): velocity (default), displacement or acceleration of mass j (default 1, the end mass, which is never at a node), force on the left wall (the first spring's tension), or sum of accelerations (the net wall force, in which even modes cancel). In one mass's motion mode n is weighted by sqrt(E_n) / omega_n, sqrt(E_n) or sqrt(E_n) omega_n. Each note is made zero-mean, scaled to a 0.9 peak (all signals equally loud; Volume sets the level) and faded out over its last 20 ms (`../common/sound.ts`). Save WAV saves the last note as heard (16-bit mono PCM, peak at 0.9; `../common/wav.ts`; named e.g. fput-N4-mass1-2.51J-v1-100Hz.wav). Chips (as in the pendulum app, plus Modes): Spectrogram (on; `NoteSpectrogram` in `../common/spectrogram.ts`: 2048-sample Hann, zero-pad 4096, hop 512, for pitches down to 30 Hz; below, the window lengthens in proportion (up to 16384 samples at 5 Hz, zero-pad 2x, hop a quarter window) so neighbouring low modes stay resolved; dashed lines at the linear mode pitches, drawn only while at least 6 px apart, since crowded together their dashes merged into a solid on-off bar at the bottom), Modes (off by default; the note's mode-energy history, each mode's share of the energy over the whole note, from the render worker, one column per 256 samples; `ModeHistory` in `modehistory.ts`; a cascade that takes tens of mode-1 periods occupies only the first few percent of a whole-decay note, so Mode history in the Real time panel shows it better), Lyapunov (the note's largest Lyapunov exponent over the last 10 s of physical time, from a shadow run in the worker alongside the note; the first 5 s of physical time left out of the y range), Energy (log scale, so the decay is a straight line) and λ vs E (`../common/scatter.ts`: one point per 256 samples, accumulated over notes, log energy axis, colored by time into the note on a log scale, earlier notes faded, hover for values, Clear button). The first three span the whole note (strike at left, end at right) and fill in as the audio clock reaches each sample; one shared cursor (playhead while playing; hover for values, click to pin). Pause (or space) pauses the animation and the sound (audio context suspended). The note's Lyapunov shadow runs only while the Lyapunov chart or λ vs E is shown (it doubles the computation). Render time in the browser pane (with the Lyapunov shadow): ~0.6 s for N = 4, ~2 s for N = 32 (default strike). First look (N = 4, 2.51 J): λ ~1.3 /s at the strike, falling to ~0 by ~4 s of sound as the spectrogram resolves into lines; on λ vs E the note's points sit near 0 below ~0.1 J and rise to ~1.4 /s at the top.
7+"Sped up · listen" (open by default, below the cards; otherwise as in the pendulum app): the header says how much faster it runs ("the whole decay, 321× faster: 62 min of motion in 12 s"; without damping "321× faster than the chain above"). The page starts muted (the mute button is tinted red and reads "Muted"; muted notes are still computed and shown); the audio context is created at the first Strike; closing the panel stops the note. While it is open each Strike plays a note, the same strike rendered in a Web Worker (`render-worker.ts`, on the loop shared with the beam app in `../common/note-render.ts`) sped up so the lowest linear mode sounds at the Pitch (5 to 1000 Hz, default 100; below ~20 Hz the lowest modes are below hearing but show in the spectrogram; the readout gives the lowest and highest mode pitches). A damped note is the whole decay, ending when its energy has fallen to 1e-6 of the strike's (-60 dB; predicted length (tau/2) ln 1e6 of physical time, 11.6 s of sound by default, measured 11.3 s; capped at twice that); undamped notes last 10 s. "Strike to hear the whole decay." shows until the first note; the status line gives the signal and note length ("computing…" while rendering). Replay plays the last strike again with the current settings (to compare signals). Signal (`signals.ts`): velocity (default), displacement or acceleration of mass j (default 1, the end mass, which is never at a node), force on the left wall (the first spring's tension), or sum of accelerations (the net wall force, in which even modes cancel). In one mass's motion mode n is weighted by sqrt(E_n) / omega_n, sqrt(E_n) or sqrt(E_n) omega_n. Each note is made zero-mean, scaled to a 0.9 peak (all signals equally loud; Volume sets the level) and faded out over its last 20 ms (`../common/sound.ts`). Save WAV saves the last note as heard (16-bit mono PCM, peak at 0.9; `../common/wav.ts`; named e.g. fput-N4-mass1-2.51J-v1-100Hz.wav). Chips (as in the pendulum app, plus Modes): Spectrogram (on; `NoteSpectrogram` in `../common/spectrogram.ts`: 2048-sample Hann, zero-pad 4096, hop 512, for pitches down to 30 Hz; below, the window lengthens in proportion (up to 16384 samples at 5 Hz, zero-pad 2x, hop a quarter window) so neighbouring low modes stay resolved; dashed lines at the linear mode pitches, drawn only while at least 6 px apart, since crowded together their dashes merged into a solid on-off bar at the bottom), Modes (off by default; the note's mode-energy history, each mode's share of the energy over the whole note, from the render worker, one column per 256 samples; `ModeHistory` in `../common/modehistory.ts`; a cascade that takes tens of mode-1 periods occupies only the first few percent of a whole-decay note, so Mode history in the Real time panel shows it better), Lyapunov (the note's largest Lyapunov exponent over the last 10 s of physical time, from a shadow run in the worker alongside the note; the first 5 s of physical time left out of the y range), Energy (log scale, so the decay is a straight line) and λ vs E (`../common/scatter.ts`: one point per 256 samples, accumulated over notes, log energy axis, colored by time into the note on a log scale, earlier notes faded, hover for values, Clear button). The first three span the whole note (strike at left, end at right) and fill in as the audio clock reaches each sample; one shared cursor (playhead while playing; hover for values, click to pin). Pause (or space) pauses the animation and the sound (audio context suspended). The note's Lyapunov shadow runs only while the Lyapunov chart or λ vs E is shown (it doubles the computation). Render time in the browser pane (with the Lyapunov shadow): ~0.6 s for N = 4, ~2 s for N = 32 (default strike). First look (N = 4, 2.51 J): λ ~1.3 /s at the strike, falling to ~0 by ~4 s of sound as the spectrogram resolves into lines; on λ vs E the note's points sit near 0 below ~0.1 J and rise to ~1.4 /s at the top.
88
99 Poincaré section (shown only for N = 2 and N = 3, below the sped-up panel, open; adapted from the pendulum app): its own energy slider (log, 10 µJ to 100 J, default 2.51 J), same parameters, no damping. N = 2: each time mass 1 passes its rest position moving right, mass 2's (u2, p2) is plotted. N = 3: only the symmetric family (u1 = u3, p1 = p3; only modes 1 and 3 move, since the cubic force couples odd modes only to odd modes), which is two-dimensional: each time mass 2 passes its rest position moving right, mass 1's (u1, p1) is plotted. On either section the springs are stretched by 0 or +-x, so V = vFactor (k x^2 / 2 + k3 x^4 / 4) (vFactor 2 or 4), the plotted momentum counts once (N = 2) or twice (N = 3) in the kinetic energy, the outline is where the crossing mass's momentum vanishes, and that momentum follows from E. 42 orbits seeded on a grid, 300 crossings each, in a worker (`poincare-core.ts`, the chain's section, on `../common/section.ts` and `../common/section-worker.ts`; `poincare.ts`, the panel's configuration for `../common/section-panel.ts`; integrator step stepFor(E), energy error < 5e-5; ~1 s per section offline, a few s in the pane), drawn as they arrive; per-orbit colors or Color by λ (each orbit's Lyapunov exponent over its run, log scale); hover to pick out an orbit with its λ; click inside the outline to add an orbit there, and with Click to strike (on) also strike the chain from that exact state (and play it, if the sound panel is open). Follow (as in the pendulum app): "real time" makes the section's energy track the chain's as it decays (recomputed after a 3% change, at most every 2 s, and at each strike); "sped up" (which opens the sped-up panel) shows the playing note's crossings (found in the render worker, for N = 3 only while exactly symmetric, and drawn as the audio clock reaches them) as a fading trail of the last 150, with the axes fitted to the note's current energy (refit every 2%) and each dot fitted from its own energy; nothing is computed live. "Precompute sections" (shown only with Follow "sped up" until complete) builds an atlas (`../common/atlas.ts`, configured in `atlas.ts`): sections at 32 energies log-spaced from 1 mJ to 100 J (a factor ~1.45 apart), 42 orbits x 150 crossings, highest first, in its own worker (~22 s in the pane for N = 3), stored in IndexedDB per N, m, k, k3 and deleted after 7 days; the sound view shows the atlas section nearest the current energy, fitted to its allowed region (exact in the linear regime, below ~25 mJ, where sections are scaled copies; an approximation across the gaps above). Without an atlas only the outline is drawn behind the trail. Setting the section's energy by hand pauses everything and clears the rings and the trail; Follow takes over again on Resume. The chain's own crossings show as dark rings when within 5% of the section's energy and, for N = 3, only while the chain is exactly symmetric (else the legend says "chain not symmetric, not shown"; strikes on mass 2 or on mode 1 or 3 are symmetric, mode shapes are made exactly mirror-symmetric for this). Findings: the two-mass chain appears regular at every energy tried (10 mJ to 100 J): nested closed curves and island chains, no chaotic sea; the grid orbits' λ falls as the run lengthens (at 10 J, median 0.045 /s over 300 crossings, 0.007 /s over 3000), as for regular orbits. A likely reason: in mode coordinates (u = S Q) the potential is (k/2) rho^2 + (k3/8) rho^4 with rho^2 = Q1^2 + 3 Q2^2, a function of one combination of the two modes. The N = 3 symmetric family is chaotic: grid orbits with λ > 0.1 /s: 0 of 42 at 25 mJ, 10 at 0.25 J (islands in a chaotic sea), 37 at 2.51 J. It is unstable to breaking the symmetry: an exactly symmetric start stays symmetric (the arithmetic is exactly mirror-symmetric), but an asymmetry of 1e-12 grows to full size within ~100 s at 0.25 to 25 J. The ghost and the Lyapunov shadow offset all masses equally, so after a symmetric strike they too stay symmetric and measure the exponent within the family.
1010
src/fput-chain/main.tsmodified+9−55View file
@@ -7,7 +7,8 @@ import { newCursor } from "../common/cursor";
77 import { setupHelp } from "../common/help";
88 import { Lyapunov } from "../common/lyapunov";
99 import { shadowOf } from "./lyapunov";
10-import { LiveModeHistory, ModeHistory } from "./modehistory";
10+import { LiveModeHistory, ModeHistory } from "../common/modehistory";
11+import { drawModeBars } from "../common/modebars";
1112 import { newPoincarePanel, type PoincarePanel } from "./poincare";
1213 import { sectionDef } from "./poincare-core";
1314 import { END_RATIO, DIAG_EVERY, UNDAMPED_LENGTH } from "../common/note-render";
@@ -17,7 +18,7 @@ import { SIGNALS, signalByKey } from "./signals";
1718 import { Player } from "../common/sound";
1819 import { setupMute } from "../common/mute";
1920 import { fmtDuration, fmtEnergy, fmtLength } from "../common/format";
20-import { fit } from "../common/canvas";
21+import { fit, indexColor } from "../common/canvas";
2122 import { NoteSpectrogram } from "../common/spectrogram";
2223 import { TracePanel, type Group } from "../common/traces";
2324 import { saveFile, wavBlob } from "../common/wav";
@@ -56,11 +57,7 @@ let Ek = new Float64Array(0); // mode energies at the last sample or draw
5657 let ampl = 0; // recent largest |u|, for scaling the profile
5758 let lastStrike: State | null = null; // state right after the last strike (for the sound)
5859
59-// Colors by index k of n (masses, springs, modes): the trace palette for a
60-// few, a blue-to-red sweep for more.
61-const PALETTE = ["#2f5d8a", "#c8742c", "#4a8c5c", "#a8476e"];
62-const indexColor = (k: number, n: number) =>
63- n <= PALETTE.length ? PALETTE[k] : `hsl(${215 - (215 * k) / (n - 1)}, 55%, 45%)`;
60+// Colors by index (masses, springs, modes): indexColor from ../common/canvas.ts.
6461
6562 const strikeEnergy = () => 10 ** Number(energyInput.value);
6663 const showEnergy = () => (energyValue.textContent = fmtEnergy(strikeEnergy()));
@@ -642,58 +639,15 @@ function drawChain() {
642639 ctx.textAlign = "left";
643640 }
644641
645-// Harmonic energy of each mode relative to the strike energy, log scale.
646-const DECADES = 12;
642+// Mode bars, with the number of modes sharing the energy and the range of
643+// mode frequencies underneath.
647644 function drawModes() {
648- const ctx = fit(modesCanvas);
649- const W = modesCanvas.clientWidth, Ht = modesCanvas.clientHeight;
650- ctx.clearRect(0, 0, W, Ht);
651- const { N } = P;
652- const left = 40, right = W - 6, top = 8, bottom = Ht - 22;
653- const yOf = (lg: number) => top + (-lg / DECADES) * (bottom - top); // lg = log10(E_n / E), 0 at top
654-
655- ctx.font = "11px ui-monospace, SFMono-Regular, Menlo, monospace";
656- ctx.lineWidth = 1;
657- ctx.textAlign = "right";
658- ctx.textBaseline = "middle";
659- for (let d = 0; d <= DECADES; d += 3) {
660- const y = yOf(-d);
661- ctx.strokeStyle = LINE;
662- ctx.beginPath();
663- ctx.moveTo(left, y);
664- ctx.lineTo(right, y);
665- ctx.stroke();
666- ctx.fillStyle = MUTED;
667- ctx.fillText(d === 0 ? "1" : `1e-${d}`, left - 6, y);
668- }
669-
670- const bw = (right - left) / N;
671- ctx.textAlign = "center";
672- ctx.textBaseline = "top";
673- const every = N <= 16 ? 1 : N <= 32 ? 4 : 8;
674- for (let n = 1; n <= N; n++) {
675- if (n === 1 || n % every === 0) ctx.fillText(String(n), left + (n - 0.5) * bw, bottom + 6);
676- }
677- ctx.textBaseline = "alphabetic";
678-
679- let pr = 0;
680- if (E0 > 0) {
681- modes.energies(s, Ek);
682- let sum = 0;
683- for (let n = 0; n < N; n++) sum += Ek[n];
684- for (let n = 0; n < N; n++) {
685- const lg = Math.log10(Ek[n] / E0);
686- if (!(lg > -DECADES)) continue;
687- const y = yOf(Math.min(0, lg));
688- ctx.fillStyle = indexColor(n, N);
689- ctx.fillRect(left + n * bw + 0.15 * bw, y, 0.7 * bw, bottom - y);
690- pr += (Ek[n] / sum) ** 2;
691- }
692- }
645+ if (E0 > 0) modes.energies(s, Ek);
646+ const shared = drawModeBars(modesCanvas, E0 > 0 ? Ek : null, E0, P.N);
693647 const w = modes.omega;
694648 const hz = (x: number) => (x / (2 * Math.PI)).toFixed(3);
695649 modeStats.textContent =
696- (pr > 0 ? `modes sharing the energy ${(1 / pr).toFixed(1)} · ` : "") + `modes ${hz(w[0])} … ${hz(w[N - 1])} Hz`;
650+ (shared > 0 ? `modes sharing the energy ${shared.toFixed(1)} · ` : "") + `modes ${hz(w[0])} … ${hz(w[P.N - 1])} Hz`;
697651 }
698652
699653 // Animation: the simulation advances `speed` seconds per second of real time.