GithubHelp home page GithubHelp logo

tomtuamnuq / ode-solvers Goto Github PK

View Code? Open in Web Editor NEW

This project forked from srenevey/ode-solvers

0.0 0.0 0.0 4.28 MB

Numerical methods to solve ordinary differential equations in Rust.

License: BSD 3-Clause "New" or "Revised" License

Rust 100.00%

ode-solvers's Introduction

ODE-solvers

Crates.io Docs Crates.io

Homepage Documentation

Numerical methods to solve ordinary differential equations (ODEs) in Rust.

Installation

To start using the crate in a project, the following dependency must be added in the project's Cargo.toml file:

[dependencies]
ode_solvers = "0.4.0"

Then, in the main file, add

use ode_solvers::*;

Type alias definition

The numerical integration methods implemented in the crate support multi-dimensional systems. In order to define the dimension of the system, declare a type alias for the state vector. For instance

type State = Vector3<f64>;

The state representation of the system is based on the SVector<T,D> structure defined in the nalgebra crate. For convenience, ode-solvers re-exports six types to work with systems of dimension 1 to 6: Vector1<T>,..., Vector6<T>. For higher dimensions, the user should import the nalgebra crate and define a SVector<T,D> where the second type parameter of SVector is a dimension. For instance, for a 9-dimensional system, one would have:

type State = SVector<f64, 9>;

Alternativly, one can also use the DVector<T> structure from the nalgebra crate as the state representation. When using a DVector<T>, the number of rows in the DVector<T> defines the dimension of the system.

type State = DVector<f64>;

System definition

The system of first order ODEs must be defined in the system method of the System<T, V> trait. Typically, this trait is defined for a structure containing some parameters of the model. The signature of the System<T, V> trait is:

pub trait System<T, V> {
    fn system(&self, x: T, y: &V, dy: &mut V);
    fn solout(&self, _x: T, _y: &V, _dy: &V) -> bool {
        false
    }
}

where system must contain the ODEs: the second argument is the independent variable (usually time), the third one is a vector containing the dependent variable(s), and the fourth one contains the derivative(s) of y with respect to x. The method solout is called after each successful integration step and stops the integration whenever it is evaluated as true. The implementation of that method is optional. See the examples for implementation details.

Method selection

The following explicit Runge-Kutta methods are implemented in the current version of the crate:

Method Name Order Error estimate order Dense output order
Runge-Kutta 4 Rk4 4 N/A N/A
Dormand-Prince Dopri5 5 4 4
Dormand-Prince Dop853 8 (5, 3) 7

These methods are defined in the modules rk4, dopri5, and dop853. The first step is to bring the desired module into scope:

use ode_solvers::dopri5::*;

Then, a structure is created using the new or the from_param method of the corresponding struct. Refer to the API documentation for a description of the input arguments.

let mut stepper = Dopri5::new(system, x0, x_end, dx, y0, rtol, atol);

The system is integrated using

let res = stepper.integrate();

and the results are retrieved with

let x_out = stepper.x_out();
let y_out = stepper.y_out();

See the homepage for more details.

ode-solvers's People

Contributors

srenevey avatar burrbull avatar n3vu0r avatar darthb avatar dstaatz avatar joshparallel avatar stefanmathis avatar lopsided98 avatar zusez4 avatar mhovd avatar pvdberg1998 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.