use super::integrator::IntegrationMethod;
pub struct SimulationResult {
pub times: Vec<f64>,
pub states: Vec<Vec<f64>>,
pub dimension: usize,
pub method: IntegrationMethod,
pub steps_taken: usize,
}
impl SimulationResult {
pub fn final_state(&self) -> Option<&[f64]> {
self.states.last().map(|v| v.as_slice())
}
pub fn state_at(&self, index: usize) -> Option<&[f64]> {
self.states.get(index).map(|v| v.as_slice())
}
pub fn time_at(&self, index: usize) -> Option<f64> {
self.times.get(index).copied()
}
pub fn len(&self) -> usize {
self.times.len()
}
pub fn is_empty(&self) -> bool {
self.times.is_empty()
}
pub fn column(&self, dim_index: usize) -> Vec<f64> {
self.states
.iter()
.filter_map(|s| s.get(dim_index).copied())
.collect()
}
pub fn max_of(&self, dim_index: usize) -> f64 {
self.column(dim_index)
.into_iter()
.fold(f64::NEG_INFINITY, f64::max)
}
pub fn min_of(&self, dim_index: usize) -> f64 {
self.column(dim_index)
.into_iter()
.fold(f64::INFINITY, f64::min)
}
}