Skip to content

Commit 245e327

Browse files
committed
Ver 0.36.2
- Reportable ODEError
2 parents 02b1959 + adb6ac0 commit 245e327

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "peroxide"
3-
version = "0.36.1"
3+
version = "0.36.2"
44
authors = ["axect <axect@outlook.kr>"]
55
edition = "2018"
66
description = "Rust comprehensive scientific computation library contains linear algebra, numerical analysis, statistics and machine learning tools with farmiliar syntax"

RELEASES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# Release 0.36.2 (2024-04-10)
2+
3+
- Now, you can report current states if your constraints are violated.
4+
- `ODEError::ConstraintViolation` -> `ODEError::ConstraintViolation(f64, Vec<f64>, Vec<f64>)`
5+
- for detailed information, see [docs for ODEError](https://axect.github.io/Peroxide_Doc/peroxide/numerical/ode/enum.ODEError.html)
6+
- Add docs for `ODEError`
7+
18
# Release 0.36.1 (2024-04-09)
29

310
- Fix all warnings in peroxide

src/numerical/ode.rs

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
//! - `ODEProblem`: Trait for defining an ODE problem.
88
//! - `ODEIntegrator`: Trait for ODE integrators.
99
//! - `ODESolver`: Trait for ODE solvers.
10+
//! - `ODEError`: Enum for ODE errors.
11+
//! - `ReachedMaxStepIter`: Reached maximum number of steps per step. (internal error)
12+
//! - `ConstraintViolation(f64, Vec<f64>, Vec<f64>)`: Constraint violation. (user-defined error)
1013
//!
1114
//! ## Available integrators
1215
//!
@@ -111,10 +114,39 @@ pub trait ODEIntegrator {
111114

112115

113116
/// Enum for ODE errors.
114-
#[derive(Debug, Clone, Copy, Error)]
117+
///
118+
/// # Variants
119+
///
120+
/// - `ReachedMaxStepIter`: Reached maximum number of steps per step. (internal error for integrator)
121+
/// - `ConstraintViolation`: Constraint violation. (user-defined error)
122+
///
123+
/// If you define constraints in your problem, you can use this error to report constraint violations.
124+
///
125+
/// # Example
126+
///
127+
/// ```no_run
128+
/// use peroxide::fuga::*;
129+
///
130+
/// struct ConstrainedProblem {
131+
/// y_constraint: f64
132+
/// }
133+
///
134+
/// impl ODEProblem for ConstrainedProblem {
135+
/// fn initial_conditions(&self) -> Vec<f64> { vec![0.0] } // y_0 = 0
136+
/// fn rhs(&self, t: f64, y: &[f64], dy: &mut [f64]) -> Result<(), ODEError> {
137+
/// if y[0] < self.y_constraint {
138+
/// return Err(ODEError::ConstraintViolation(t, y.to_vec(), dy.to_vec()));
139+
/// } else {
140+
/// // some function
141+
/// Ok(())
142+
/// }
143+
/// }
144+
/// }
145+
/// ```
146+
#[derive(Debug, Clone, Error)]
115147
pub enum ODEError {
116148
#[error("constraint violation")]
117-
ConstraintViolation,
149+
ConstraintViolation(f64, Vec<f64>, Vec<f64>), // t, y, dy
118150
#[error("reached maximum number of iterations per step")]
119151
ReachedMaxStepIter,
120152
}
@@ -154,7 +186,8 @@ pub trait ODESolver {
154186
/// }
155187
///
156188
/// fn rhs(&self, t: f64, y: &[f64], dy: &mut [f64]) -> Result<(), ODEError> {
157-
/// Ok(dy[0] = (5f64 * t.powi(2) - y[0]) / (t + y[0]).exp())
189+
/// dy[0] = (5f64 * t.powi(2) - y[0]) / (t + y[0]).exp();
190+
/// Ok(())
158191
/// }
159192
/// }
160193
/// ```

0 commit comments

Comments
 (0)