aligrator 0.1.1

A lightweight numerical integration library.
Documentation
  • Coverage
  • 26.67%
    12 out of 45 items documented0 out of 30 items with examples
  • Size
  • Source code size: 126.77 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 3.43 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 19s Average build duration of successful builds.
  • all releases: 17s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • alexlovric/aligrator
    3 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • alexlovric

Aligrator

Build & Test

A lightweight, dependency-free Rust library for numerical integration of ordinary differential equations (ODEs). Supports multiple Runge-Kutta multistage integrators and is easily extensible.

Features

  • Forward Euler
  • Rk4, Rk45, Rk89
  • Adaptive time-stepping

Example: Solving a Simple Harmonic Oscillator

This example demonstrates how to use Aligrator to solve the initial value problem (IVP) for a simple harmonic oscillator (SHO):

1. Define the ODE System

struct ShoAccel;

impl IvpFunction<1> for ShoAccel {
    fn compute(&mut self, t: &f64, x: &[f64; 1], xdot: &[f64; 1]) -> [f64; 1] {
        let omega: f64 = 1.0;
        [-omega.powi(2) * x[0]]
    }
}
  • ShoAccel defines the SHO's acceleration as a function of position.
  • Implements IvpFunction<1> for a 1D system.

2. Set Initial Conditions

let x0 = [1.0];      // Initial position
let xdot0 = [0.0];   // Initial velocity
let t0 = 0.0;        // Start time
let tf = 15.0;       // End time
let dt = 1.0;        // Initial time step

3. Choose and Configure the Integrator

let mut integrator = Rk89::new(dt, None); // Adaptive disabled (second argument)
  • Here we use the high-order Runge-Kutta 8/9 method.
  • For adaptive time-stepping, pass Some(AdaptiveDt::new(Some(1e-6), None, None)) as the second argument. Here the first argument is tolerance, the second is minimum time step, and the third is maximum time step.

4. Integrate the System

let (times, positions, _) = integrate(&mut integrator, &mut ShoAccel, x0, xdot0, t0, tf);
  • Solves the IVP from t0 to tf.
  • Returns time points, positions, and velocities (not used here).
  • Here we use the integrate function to manage the looping, but you can easily just call the integrator.step(...) in your own integration loop.

The response should look like this: Response

If we check the accuracy, its consistent with what we expect from this integrator: Order

6. Run the Example

Build and run the example with:

cargo run --example sho_response

License

MIT