lawsynth/crates/lawsynth-pde/tests/advection_recovery.rs
caelum0x 11bc7add70 feat: PDE discovery + invariants + model selection + Studio analysis surface
Batch 11 of expansion-v2. Extends discovery to spatiotemporal + conservation
structure, adds principled hyperparameter selection, and surfaces analysis in
the web app. Deterministic/offline/std-only (Rust) or typed/tested (TS).

crates/lawsynth-pde (new): evolution-PDE discovery (PDE-FIND). Central-difference
spatial/time derivatives on the interior + differential-term library (uᵖ·D_m) +
STLSQ on flattened u_t. Recovers heat (0.2002·u_xx), advection (−0.801·u_x), and
Burgers (−1.000·u·u_x + 0.100·u_xx) from snapshots; two-mode fixtures break the
u/u_xx collinearity; a finer-grid test confirms O(dx²). 32 tests.

crates/lawsynth-invariants (new): conserved-quantity detection. H parametrized
over a library; conserved ⇔ ∇H·f=0; the SVD nullspace of the sampled
Lie-derivative matrix yields invariants (constant excluded, canonically
normalized). Recovers x²+y² energy, two independent invariants for a decoupled
system, y²−2cos x for the pendulum (trig basis), and honestly returns EMPTY for
a damped oscillator (no false positive). 21 tests.

crates/lawsynth-modelselect (new): time-series cross-validated hyperparameter
selection. Forward-chaining/rolling folds (no shuffling), discover-on-train +
simulate-on-test predictive scoring via lawsynth-score, full auditable table,
simpler-model tie-break. Selects degree 3 for cubic Duffing, degree 1 for a
linear system, degree 2 for logistic. 27 tests.

apps/studio: analysis module surfacing all seven engine reports (stability/
control/domains/bifurcation/sensitivity/estimate/reduce) as UI view models via
the api-client parsers, wired as a navigable route. Honest cases handled
(inconclusive classification, empty fixed-point set, null validation). 16 groups.

specs/{pde-discovery,invariant-detection,model-selection}: boundary specs.
2026-08-18 17:39:38 +03:00

42 lines
1.4 KiB
Rust
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//! Advection `u_t = −c u_x` from an exact two-mode travelling wave.
//!
//! The clean linear check: the discovery must pick the single `u_x` term with
//! coefficient `≈ −c`.
mod common;
use common::advection_two_mode;
use lawsynth_pde::{PdeConfig, discover_pde};
const C: f64 = 0.8;
fn advection_model(nx: usize, nt: usize) -> lawsynth_pde::PdeModel {
let fixture = advection_two_mode(C, 1.0, 2.0, 0.5, nx, nt, 0.01);
discover_pde(&fixture.field, fixture.dx, fixture.dt, &PdeConfig::default()).unwrap()
}
#[test]
fn recovers_the_advection_speed() {
let model = advection_model(96, 40);
let coefficient = model.coefficient_of(0, 1);
assert!((coefficient - (-C)).abs() < 0.02, "u_x coefficient {coefficient} not ≈ −c = {}", -C);
}
#[test]
fn discovered_law_is_a_single_ux_term() {
let model = advection_model(96, 40);
let active: Vec<_> = model.active_terms().collect();
assert_eq!(active.len(), 1, "expected a single term, got {}", model.describe());
assert_eq!(active[0].label, "u_x");
assert_eq!(active[0].u_power, 0);
assert_eq!(active[0].derivative_order, 1);
}
#[test]
fn spurious_terms_are_negligible() {
let model = advection_model(96, 40);
assert!(model.coefficient_of(0, 2).abs() < 1e-3, "spurious u_xx");
assert!(model.coefficient_of(1, 0).abs() < 1e-3, "spurious u");
assert!(model.coefficient_of(1, 1).abs() < 1e-3, "spurious u*u_x");
}