Skip to main content

scirs2_integrate/ode/
result.rs

1//! Result types for ODE solvers.
2
3use scirs2_core::ndarray::{Array1, Array2};
4
5/// Result of an ODE solver.
6#[derive(Debug, Clone)]
7pub struct ODEResult {
8    /// Time points for the solution.
9    pub t: Array1<f64>,
10    /// Solution values at each time point.
11    pub y: Array2<f64>,
12    /// Number of function evaluations.
13    pub nfev: usize,
14    /// Number of jacobian evaluations.
15    pub njev: usize,
16    /// Number of steps taken by the solver.
17    pub nsteps: usize,
18    /// Status of the solver (success or error).
19    pub status: ODEStatus,
20    /// Optional message about the solver's execution.
21    pub message: String,
22    /// Time points where solver failed (for diagnostics).
23    pub t_failed: Vec<f64>,
24}
25
26/// Status of the ODE solver.
27#[derive(Debug, Clone, Copy, PartialEq, Eq)]
28pub enum ODEStatus {
29    /// The solver successfully reached the end of the integration interval.
30    Success,
31    /// The solver failed at some point during integration.
32    Failed,
33}
34
35impl ODEResult {
36    /// Returns whether the solver completed successfully.
37    pub fn is_success(&self) -> bool {
38        self.status == ODEStatus::Success
39    }
40
41    /// Returns whether the solver failed.
42    pub fn is_failed(&self) -> bool {
43        self.status == ODEStatus::Failed
44    }
45}