1use anise::analysis::AnalysisError;
20use anise::errors::{AlmanacError, PhysicsError};
21pub use anise::prelude::*;
22
23pub use crate::cosmic::{DragData, GuidanceMode, Mass, SRPData, Spacecraft};
24use crate::dynamics::DynamicsError;
25pub use crate::errors::NyxError;
26use crate::errors::StateError;
27use crate::linalg::allocator::Allocator;
28use crate::linalg::{DefaultAllocator, DimName, OMatrix, OVector};
29use crate::md::StateParameter;
30use snafu::Snafu;
31use std::fmt;
32
33pub trait TimeTagged {
35 fn epoch(&self) -> Epoch;
37 fn set_epoch(&mut self, epoch: Epoch);
39}
40
41pub trait State: Default + Copy + PartialEq + fmt::Display + fmt::LowerExp + Send + Sync
44where
45 Self: Sized,
46 DefaultAllocator:
47 Allocator<Self::Size> + Allocator<Self::Size, Self::Size> + Allocator<Self::VecLength>,
48{
49 type Size: DimName;
51 type VecLength: DimName;
52
53 fn zeros() -> Self {
56 unimplemented!()
57 }
58
59 fn to_vector(&self) -> OVector<f64, Self::VecLength>;
61
62 fn to_state_vector(&self) -> OVector<f64, Self::Size> {
64 OVector::<f64, Self::Size>::from_iterator(
65 self.to_vector().iter().copied().take(Self::Size::DIM),
66 )
67 }
68
69 fn stm(&self) -> Result<OMatrix<f64, Self::Size, Self::Size>, DynamicsError> {
72 Err(DynamicsError::StateTransitionMatrixUnset)
73 }
74
75 fn with_stm(self) -> Self;
77
78 fn reset_stm(&mut self) {
80 unimplemented!()
81 }
82
83 fn unset_stm(&mut self);
85
86 fn set(&mut self, epoch: Epoch, vector: &OVector<f64, Self::VecLength>);
88
89 fn set_with_delta_seconds(
92 mut self,
93 delta_t_s: f64,
94 vector: &OVector<f64, Self::VecLength>,
95 ) -> Self
96 where
97 DefaultAllocator: Allocator<Self::VecLength>,
98 {
99 self.set(self.epoch() + delta_t_s, vector);
100 self
101 }
102
103 fn epoch(&self) -> Epoch;
105
106 fn set_epoch(&mut self, epoch: Epoch);
108
109 fn add(self, _other: OVector<f64, Self::Size>) -> Self {
111 unimplemented!()
112 }
113
114 fn value(&self, param: StateParameter) -> Result<f64, StateError> {
116 Err(StateError::Unavailable { param })
117 }
118
119 fn set_value(&mut self, param: StateParameter, _val: f64) -> Result<(), StateError> {
122 Err(StateError::Unavailable { param })
123 }
124
125 fn orbit(&self) -> Orbit;
127
128 fn set_orbit(&mut self, _orbit: Orbit) {}
130}
131
132pub fn assert_orbit_eq_or_abs(left: &Orbit, right: &Orbit, epsilon: f64, msg: &str) {
133 if !left.eq_within(right, epsilon, epsilon) {
134 panic!(
135 r#"assertion failed: {msg}
136 left: `{left:?}`,
137 right: `{right:?}`"#
138 )
139 }
140}
141
142#[derive(Debug, PartialEq, Snafu)]
143#[snafu(visibility(pub(crate)))]
144pub enum AstroError {
145 #[snafu(display("B Plane jacobian invariant must be either VX, VY or VZ"))]
146 BPlaneInvariant,
147 #[snafu(display("operation requires a local frame"))]
148 NotLocalFrame,
149 #[snafu(display("partial derivatives not defined for this parameter"))]
150 PartialsUndefined,
151 #[snafu(display("Orbit is not hyperbolic so there is no hyperbolic anomaly."))]
152 NotHyperbolic,
153 #[snafu(display("physics error occured during astro computation: {source}"))]
154 AstroPhysics { source: PhysicsError },
155 #[snafu(display("analysis error occured during astro computation: {source}"))]
156 AstroAnalysis { source: AnalysisError },
157 #[snafu(display("ANISE Almanac error occured during astro computation: {source}"))]
158 AstroAlmanac {
159 #[snafu(source(from(AlmanacError, Box::new)))]
160 source: Box<AlmanacError>,
161 },
162}
163
164mod bplane;
166pub use self::bplane::*;
167
168mod spacecraft;
170pub use self::spacecraft::*;
171
172pub mod eclipse;
174
175pub const SPEED_OF_LIGHT_M_S: f64 = SPEED_OF_LIGHT_KM_S * 1e3;
177pub use anise::constants::SPEED_OF_LIGHT_KM_S;
178
179pub const AU: f64 = 149_597_870.700;
181
182pub const STD_GRAVITY: f64 = 9.80665;