Skip to main content

nyx_space/propagators/
mod.rs

1/*
2    Nyx, blazing fast astrodynamics
3    Copyright (C) 2018-onwards Christopher Rabotin <christopher.rabotin@gmail.com>
4
5    This program is free software: you can redistribute it and/or modify
6    it under the terms of the GNU Affero General Public License as published
7    by the Free Software Foundation, either version 3 of the License, or
8    (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU Affero General Public License for more details.
14
15    You should have received a copy of the GNU Affero General Public License
16    along with this program.  If not, see <https://www.gnu.org/licenses/>.
17*/
18
19use anise::{
20    analysis::AnalysisError,
21    errors::{AlmanacError, MathError},
22};
23use snafu::prelude::*;
24use std::fmt;
25
26/// Provides different methods for controlling the error computation of the integrator.
27pub mod error_ctrl;
28pub use self::error_ctrl::*;
29
30mod event;
31
32// Re-Export
33mod instance;
34pub use instance::*;
35mod propagator;
36pub use propagator::*;
37mod rk_methods;
38pub use rk_methods::*;
39mod options;
40use crate::{dynamics::DynamicsError, io::ConfigError, md::trajectory::TrajError, time::Duration};
41pub use options::*;
42use serde::{Deserialize, Serialize};
43
44#[cfg(feature = "python")]
45mod python;
46
47/// Stores the details of the previous integration step of a given propagator. Access as `my_prop.clone().latest_details()`.
48#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
49pub struct IntegrationDetails {
50    /// step size used
51    pub step: Duration,
52    /// error in the previous integration step
53    pub error: f64,
54    /// number of attempts needed by an adaptive step size to be within the tolerance
55    pub attempts: u8,
56}
57
58impl fmt::Display for IntegrationDetails {
59    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
60        write!(
61            f,
62            "IntegrationDetails {{step: {}, error: {:.3e}, attempts: {}}}",
63            self.step, self.error, self.attempts
64        )
65    }
66}
67
68#[derive(Debug, PartialEq, Snafu)]
69pub enum PropagationError {
70    #[snafu(display("encountered a dynamics error {source}"))]
71    Dynamics { source: DynamicsError },
72    #[snafu(display("when propagating until an event: {source}"))]
73    TrajectoryEventError { source: TrajError },
74    #[snafu(display("requested propagation until event #{nth} but only {found} found"))]
75    NthEventError { nth: usize, found: usize },
76    #[snafu(display("propagation failed because {source}"))]
77    PropConfigError { source: ConfigError },
78    #[snafu(display("propagation encountered a math error {source}"))]
79    PropMathError { source: MathError },
80    #[snafu(display("propagation encountered an analysis error {source}"))]
81    PropAnalysisError {
82        #[snafu(source(from(AnalysisError, Box::new)))]
83        source: Box<AnalysisError>,
84    },
85    PropAlmanacError {
86        #[snafu(source(from(AlmanacError, Box::new)))]
87        source: Box<AlmanacError>,
88    },
89}