differential_equations/lib.rs
1//! # differential-equations
2//!
3//! A Rust library for solving various types of differential equations.
4//!
5//! [](https://github.com/Ryan-D-Gast/differential-equations)
6//! [](https://docs.rs/differential-equations)
7//!
8//! ## Overview
9//!
10//! This library provides numerical solvers for different classes of differential equations:
11//!
12//! - **[Ordinary Differential Equations (ODE)](crate::ode)**
13//! - Initial value problems (ODEProblem)
14//! - Fixed and adaptive step methods
15//! - Event detection
16//! - Customizable output control
17//!
18//! - **[Delay Differential Equations (DDE)](crate::dde)**
19//! - Constant delays
20//! - State-dependent delays
21//! - Same features as ODEs
22//!
23//! - **[Stochastic Differential Equations (SDE)](crate::sde)**
24//! - Drift-diffusion equations
25//! - User controlled random number generation
26//! - Same features as ODEs
27//!
28//! ## Feature Flags
29//!
30//! - `polars`: Enable converting Solution to Polars DataFrame using `Solution.to_polars()`
31//!
32//! ## Example (ODE)
33//!
34//!```rust
35//! use differential_equations::prelude::*;
36//! use nalgebra::{SVector, vector};
37//!
38//! pub struct LinearEquation {
39//! pub a: f64,
40//! pub b: f64,
41//! }
42//!
43//! impl ODE<f64, SVector<f64, 1>> for LinearEquation {
44//! fn diff(&self, _t: f64, y: &SVector<f64, 1>, dydt: &mut SVector<f64, 1>) {
45//! dydt[0] = self.a + self.b * y[0];
46//! }
47//! }
48//!
49//! fn main() {
50//! let system = LinearEquation { a: 1.0, b: 2.0 };
51//! let t0 = 0.0;
52//! let tf = 1.0;
53//! let y0 = vector![1.0];
54//! let problem = ODEProblem::new(system, t0, tf, y0);
55//! let mut solver = ExplicitRungeKutta::dop853().rtol(1e-8).atol(1e-6);
56//! let solution = match problem.solve(&mut solver) {
57//! Ok(sol) => sol,
58//! Err(e) => panic!("Error: {:?}", e),
59//! };
60//!
61//! for (t, y) in solution.iter() {
62//! println!("t: {:.4}, y: {:.4}", t, y[0]);
63//! }
64//! }
65//!```
66//!
67//! # License
68//!
69//! ```text
70//! Copyright 2025 Ryan D. Gast
71//!
72//! Licensed under the Apache License, Version 2.0 (the "License");
73//! you may not use this file except in compliance with the License.
74//! You may obtain a copy of the License at
75//!
76//! http://www.apache.org/licenses/LICENSE-2.0
77//!
78//! Unless required by applicable law or agreed to in writing, software
79//! distributed under the License is distributed on an "AS IS" BASIS,
80//! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
81//! See the License for the specific language governing permissions and
82//! limitations under the License.
83//! ```
84
85// -- Prelude Module & Recommended Imports for Users --
86
87pub mod prelude;
88
89// -- Butcher Tableaus --
90
91mod tableau;
92
93// -- Numerical Methods for Differential Equations --
94pub mod methods;
95
96// -- Types of Differential Equations --
97
98// Ordinary Differential Equations (ODE) Module
99pub mod ode;
100
101// Delay Differential Equations (DDE) Module
102pub mod dde;
103
104// Stochastic Differential Equations (SDE) Module
105pub mod sde;
106
107// -- Solution Output Control --
108
109// Numerous implementations of the Solout trait are contained in this module
110pub mod solout;
111pub use solout::{
112 // Solout Trait for controlling output of the solver
113 Solout,
114};
115
116// -- Shared items not specific to a Differential Equation Type --
117
118// Error for Differential Equations NumericalMethods
119mod error;
120pub use error::Error;
121
122// Status of Differential Equations NumericalMethods
123mod status;
124pub use status::Status;
125
126// Solution of a solved differential equation
127mod solution;
128pub use solution::Solution;
129
130// Control Flow
131mod control;
132pub use control::ControlFlag;
133
134// Traits for Floating Point Types
135pub mod traits;
136
137// Interpolation Functions
138pub mod interpolate;
139
140// Shared Utility Functions
141pub mod utils;
142
143// Linear Algebra Functions
144pub mod linalg;
145
146// Alias for primative types for readability
147pub mod alias;
148
149// Derive Macros for Differential Equations
150pub mod derive {
151 pub use differential_equations_derive::State;
152}