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//! ## Feature Flags
19//!
20//! - `polars`: Enable converting Solution to Polars DataFrame using `Solution.to_polars()`
21//!
22//! ## Example (ODE)
23//!
24//!```rust
25//! use differential_equations::ode::*;
26//! use nalgebra::{SVector, vector};
27//!
28//! pub struct LinearEquation {
29//! pub a: f64,
30//! pub b: f64,
31//! }
32//!
33//! impl ODE<f64, SVector<f64, 1>> for LinearEquation {
34//! fn diff(&self, _t: f64, y: &SVector<f64, 1>, dydt: &mut SVector<f64, 1>) {
35//! dydt[0] = self.a + self.b * y[0];
36//! }
37//! }
38//!
39//! fn main() {
40//! let system = LinearEquation { a: 1.0, b: 2.0 };
41//! let t0 = 0.0;
42//! let tf = 1.0;
43//! let y0 = vector![1.0];
44//! let problem = ODEProblem::new(system, t0, tf, y0);
45//! let mut solver = DOP853::new().rtol(1e-8).atol(1e-6);
46//! let solution = match problem.solve(&mut solver) {
47//! Ok(sol) => sol,
48//! Err(e) => panic!("Error: {:?}", e),
49//! };
50//!
51//! for (t, y) in solution.iter() {
52//! println!("t: {:.4}, y: {:.4}", t, y[0]);
53//! }
54//! }
55//!```
56//!
57//! # License
58//!
59//! ```text
60//! Copyright 2025 Ryan D. Gast
61//!
62//! Licensed under the Apache License, Version 2.0 (the "License");
63//! you may not use this file except in compliance with the License.
64//! You may obtain a copy of the License at
65//!
66//! http://www.apache.org/licenses/LICENSE-2.0
67//!
68//! Unless required by applicable law or agreed to in writing, software
69//! distributed under the License is distributed on an "AS IS" BASIS,
70//! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
71//! See the License for the specific language governing permissions and
72//! limitations under the License.
73//! ```
74
75// -- Types of Differential Equations --
76
77// Ordinary Differential Equations (ODE) Module
78pub mod ode;
79
80// Stochastic Differential Equations (SDE) Module
81pub mod sde;
82
83// -- Solution Output Control --
84
85// Numerous implementations of the Solout trait are contained in this module
86pub mod solout;
87pub use solout::{
88 // Solout Trait for controlling output of the solver
89 Solout,
90};
91
92// -- Shared items not specific to a Differential Equation Type --
93
94// Error for Differential Equations NumericalMethods
95mod error;
96pub use error::Error;
97
98// Status of Differential Equations NumericalMethods
99mod status;
100pub use status::Status;
101
102// Solution of a solved differential equation
103mod solution;
104pub use solution::Solution;
105
106// Control Flow
107mod control;
108pub use control::ControlFlag;
109
110// Traits for Floating Point Types
111pub mod traits;
112
113// Interpolation Functions
114pub mod interpolate;
115
116// Shared Utility Functions
117pub mod utils;
118
119// Derive Macros for Differential Equations
120pub mod derive {
121 pub use differential_equations_derive::State;
122}
123
124// -- Shared items for re-exporting to differential equation type modules --
125mod shared {
126 pub use crate::control::ControlFlag;
127 pub use crate::error::Error;
128 pub use crate::solout::CrossingDirection;
129 pub use crate::solution::Solution;
130 pub use crate::status::Status;
131}