Skip to main content

moldyn_core/simulation/
args.rs

1//! TODO document
2
3use serde::{Deserialize, Serialize};
4
5/// The struct representing the global simulation settings, which includes the
6/// time range and simulation delta time.
7#[derive(Serialize, Deserialize, Clone, Debug, Default)]
8pub struct SimulationArgs {
9    /// TODO document
10    #[serde(default)]
11    pub time_start: Option<f64>,
12
13    /// TODO document
14    #[serde(default)]
15    pub time_end: Option<f64>,
16
17    /// TODO document
18    #[serde(default)]
19    pub time_step: Option<f64>,
20}
21
22#[cfg(test)]
23impl SimulationArgs {
24    /// Creates a new [SimulationArgs] with the given time range and time step.
25    pub fn new(time: f64, time_step: f64) -> Self {
26        Self {
27            time_start: Some(0.0),
28            time_end: Some(time),
29            time_step: Some(time_step),
30        }
31    }
32
33    /// Amount of simulation ticks to run with a fixed time step of `0.01`.
34    /// Used for benchmarking tests to run for a fixed amount of time.
35    pub fn ticks(ticks: usize) -> Self {
36        const TIME_STEP: f64 = 0.01;
37
38        Self {
39            time_start: Some(0.0),
40            time_end: Some(ticks as f64 * TIME_STEP),
41            time_step: Some(TIME_STEP),
42        }
43    }
44}