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/// Stores the details of the previous integration step of a given propagator. Access as `my_prop.clone().latest_details()`.
45#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
46pub struct IntegrationDetails {
47    /// step size used
48    pub step: Duration,
49    /// error in the previous integration step
50    pub error: f64,
51    /// number of attempts needed by an adaptive step size to be within the tolerance
52    pub attempts: u8,
53}
54
55impl fmt::Display for IntegrationDetails {
56    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
57        write!(
58            f,
59            "IntegrationDetails {{step: {}, error: {:.3e}, attempts: {}}}",
60            self.step, self.error, self.attempts
61        )
62    }
63}
64
65#[derive(Debug, PartialEq, Snafu)]
66pub enum PropagationError {
67    #[snafu(display("encountered a dynamics error {source}"))]
68    Dynamics { source: DynamicsError },
69    #[snafu(display("when propagating until an event: {source}"))]
70    TrajectoryEventError { source: TrajError },
71    #[snafu(display("requested propagation until event #{nth} but only {found} found"))]
72    NthEventError { nth: usize, found: usize },
73    #[snafu(display("propagation failed because {source}"))]
74    PropConfigError { source: ConfigError },
75    #[snafu(display("propagation encountered a math error {source}"))]
76    PropMathError { source: MathError },
77    #[snafu(display("propagation encountered an analysis error {source}"))]
78    PropAnalysisError {
79        #[snafu(source(from(AnalysisError, Box::new)))]
80        source: Box<AnalysisError>,
81    },
82    PropAlmanacError {
83        #[snafu(source(from(AlmanacError, Box::new)))]
84        source: Box<AlmanacError>,
85    },
86}