Skip to content

Rust API

use soliton_core::{Complex64, Kdv, Nls, PeriodicGrid, Simulation};
use soliton_core::exact::{kdv_soliton, nls_bright_soliton};
TypeRole
PeriodicGrid::new(points, length)uniform grid on [−L/2,L/2)[-L/2, L/2); positions(), wavenumbers(), spacing()
SpectralSpacegrid plus FFT plans; to_spectral, to_physical, differentiate, integrate
SemiLineartrait for u_t = L u + N(u): linear_symbol(k), nonlinear(...), invariants(...)
Kdv, Nlsequations implementing SemiLinear
Etdrk4the time stepper; implements Stepper
Simulation<E, S>drives an equation with a stepper on a grid
let mut sim = Simulation::new(PeriodicGrid::new(512, 60.0), Kdv, 1e-3);
sim.set_profile(|x| Complex64::new(kdv_soliton(x, 0.0, 4.0, -10.0), 0.0));
sim.add_profile(|x| Complex64::new(kdv_soliton(x, 0.0, 1.0, 5.0), 0.0));
sim.advance(5000);
let field = sim.state(); // Vec<Complex64> in physical space
let spectrum = sim.spectrum(); // &[Complex64], unnormalised FFT order
let invariants = sim.invariants();

Implement SemiLinear in one file under equations/. The stepper and simulation are generic, so nothing else changes.

impl SemiLinear for MyEquation {
fn linear_symbol(&self, k: f64) -> Complex64 { /* L(k) */ }
fn nonlinear(&self, space: &mut SpectralSpace, spectrum: &[Complex64], out: &mut [Complex64]) { /* N(u) */ }
fn invariants(&self, space: &mut SpectralSpace, spectrum: &[Complex64]) -> Vec<Invariant> { /* ... */ }
}