ode::ops
Flows: one-step maps phi_h composed the way splitting and composition
methods are written (Hairer, Lubich and Wanner, Geometric Numerical
Integration, II.4-5), behind the ops feature:
a ∘ b a after b (core's ∘)
c * a the same map with step c h
a ** n n steps of a
a ⊳ y a applied to the state y (binds like *)
so Strang splitting is (0.5 * a) ∘ b ∘ (0.5 * a) and a step of
Yoshida's method (w1 * v) ∘ (w0 * v) ∘ (w1 * v).
Structs
FlowSource
pub struct FlowA one-step map y -> phi_h(y) with its step h built in.
use ode::ops::{Advance, Flow};
use core::array::Vector;
// Exact flow of y' = -y and its splitting into halves.
let decay = Flow::new(|h: f64, y: Vector<f64>| -> Vector<f64> { y .* (-h).exp() }, 0.1);
assert(((decay ** 10 ⊳ [1.0])[0] - (-1.0f64).exp()).abs() < 1e-15);
assert((((0.5 * decay) ∘ (0.5 * decay) ⊳ [1.0])[0] - (decay ⊳ [1.0])[0]).abs() < 1e-15);
The flow
y -> map(h, y).nabiuse ode::ops::{Advance, Flow}; use core::array::Vector; let euler = Flow::new(|h: f64, y: Vector<f64>| -> Vector<f64> { y .+ y .* h }, 0.5); assert((euler ⊳ [2.0])[0] == 3.0);One step of
methodfor the autonomousy' = f(y).nabiuse ode::Fixed; use ode::ops::{Advance, Flow}; use core::array::Vector; let phi = Flow::of(|y: Vector<f64>| -> Vector<f64> { y }, 0.01, Fixed::Rk4); assert(((phi ** 100 ⊳ [1.0])[0] - 1.0f64.exp()).abs() < 1e-9);The drift
q += h velocity(p)on a state[q, p]of2 dvalues: the exact flow of the kinetic part of a separable Hamiltonian.nabiuse ode::ops::{Advance, Flow}; use core::array::Vector; let d = Flow::drift(|p: Vector<f64>| -> Vector<f64> { p }, 1, 0.5); assert(d ⊳ [1.0, 2.0] == [2.0, 2.0]);The kick
p += h force(q)on a state[q, p]: the exact flow of the potential part.nabiuse ode::ops::{Advance, Flow}; use core::array::Vector; let k = Flow::kick(|q: Vector<f64>| -> Vector<f64> { -q }, 1, 0.5); assert(k ⊳ [1.0, 2.0] == [1.0, 1.5]);y0andstepsapplications of the flow, as columns ([n, steps + 1]).nabiuse ode::ops::Flow; use core::array::Vector; let grow = Flow::new(|h: f64, y: Vector<f64>| -> Vector<f64> { y .* (1.0 + h) }, 1.0); let y0: Vector<f64> = [1.0]; assert(grow.run(y0, 3)[0, 3] == 8.0);
Trait implementations 3
impl ops::Compose<Flow> for Flowimpl ops::Pow<usize> for Flowimpl Advance for Flow
Traits
AdvanceSource
pub trait Advancephi ⊳ y: the flow phi applied to the state y. Binds like *,
looser than ∘ and **, so a ∘ b ⊳ y is (a ∘ b) ⊳ y and
phi ** 10 ⊳ y takes ten steps.
use ode::ops::{Advance, Flow};
use core::array::Vector;
let shift = Flow::new(|h: f64, y: Vector<f64>| -> Vector<f64> { y .+ h }, 1.0);
assert((shift ** 3 ⊳ [0.0])[0] == 3.0 && ((2.0 * shift) ∘ shift ⊳ [0.0])[0] == 3.0);