sciforge_hub/engine/simulation/
result.rs1use super::integrator::IntegrationMethod;
2
3pub struct SimulationResult {
5 pub times: Vec<f64>,
7 pub states: Vec<Vec<f64>>,
9 pub dimension: usize,
11 pub method: IntegrationMethod,
13 pub steps_taken: usize,
15}
16
17impl SimulationResult {
18 pub fn final_state(&self) -> Option<&[f64]> {
20 self.states.last().map(|v| v.as_slice())
21 }
22
23 pub fn state_at(&self, index: usize) -> Option<&[f64]> {
25 self.states.get(index).map(|v| v.as_slice())
26 }
27
28 pub fn time_at(&self, index: usize) -> Option<f64> {
30 self.times.get(index).copied()
31 }
32
33 pub fn len(&self) -> usize {
35 self.times.len()
36 }
37
38 pub fn is_empty(&self) -> bool {
40 self.times.is_empty()
41 }
42
43 pub fn column(&self, dim_index: usize) -> Vec<f64> {
45 self.states
46 .iter()
47 .filter_map(|s| s.get(dim_index).copied())
48 .collect()
49 }
50
51 pub fn max_of(&self, dim_index: usize) -> f64 {
53 self.column(dim_index)
54 .into_iter()
55 .fold(f64::NEG_INFINITY, f64::max)
56 }
57
58 pub fn min_of(&self, dim_index: usize) -> f64 {
60 self.column(dim_index)
61 .into_iter()
62 .fold(f64::INFINITY, f64::min)
63 }
64}