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.
49 lines
1.7 KiB
Rust
49 lines
1.7 KiB
Rust
//! Burgers' equation `u_t = ν u_xx − u u_x` from a stable RK4 forward solve.
|
||
//!
|
||
//! The headline recovery: BOTH the viscous `u_xx` term (`≈ ν`) and the advective
|
||
//! nonlinearity `u·u_x` (`≈ −1`) must be found. The nonlinear cascade fills the
|
||
//! spectrum, so `u`/`u_xx` are well separated (no single-mode degeneracy).
|
||
|
||
mod common;
|
||
|
||
use common::burgers_forward;
|
||
use lawsynth_pde::{PdeConfig, discover_pde};
|
||
|
||
const NU: f64 = 0.1;
|
||
|
||
fn burgers_model() -> lawsynth_pde::PdeModel {
|
||
// 128 spatial points, 80 snapshots at dt = 0.004 with 8 RK4 substeps each.
|
||
let fixture = burgers_forward(NU, 128, 80, 0.004, 8);
|
||
discover_pde(&fixture.field, fixture.dx, fixture.dt, &PdeConfig::default()).unwrap()
|
||
}
|
||
|
||
#[test]
|
||
fn recovers_the_viscosity() {
|
||
let model = burgers_model();
|
||
let nu = model.coefficient_of(0, 2);
|
||
assert!((nu - NU).abs() < 0.02, "u_xx coefficient {nu} not ≈ ν = {NU}");
|
||
}
|
||
|
||
#[test]
|
||
fn recovers_the_advective_nonlinearity() {
|
||
let model = burgers_model();
|
||
let coefficient = model.coefficient_of(1, 1);
|
||
assert!((coefficient - (-1.0)).abs() < 0.05, "u*u_x coefficient {coefficient} not ≈ −1");
|
||
}
|
||
|
||
#[test]
|
||
fn discovers_exactly_the_two_burgers_terms() {
|
||
let model = burgers_model();
|
||
let mut active: Vec<&str> = model.active_terms().map(|term| term.label.as_str()).collect();
|
||
active.sort_unstable();
|
||
assert_eq!(active, vec!["u*u_x", "u_xx"], "law was {}", model.describe());
|
||
}
|
||
|
||
#[test]
|
||
fn spurious_terms_are_negligible() {
|
||
let model = burgers_model();
|
||
assert!(model.coefficient_of(0, 0).abs() < 1e-2, "spurious constant");
|
||
assert!(model.coefficient_of(1, 0).abs() < 1e-2, "spurious u");
|
||
assert!(model.coefficient_of(0, 1).abs() < 1e-2, "spurious u_x");
|
||
}
|