1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
use crate::frametransform;
use crate::mathtypes::*;
use crate::Frame;
use crate::Instant;
/// A constant thrust acceleration over a time window
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct ContinuousThrust {
/// Acceleration vector in the specified frame [m/s^2]
pub accel: Vector3,
/// Coordinate frame for the acceleration vector
pub frame: Frame,
/// Start time of the thrust arc
pub start: Instant,
/// End time of the thrust arc
pub end: Instant,
}
impl ContinuousThrust {
/// Create a constant thrust acceleration over a time window.
///
/// The frame is validated here — mirroring the up-front maneuver-frame
/// validation in `SatState::propagate` — so an unsupported (Earth-fixed /
/// inertial-chain) frame surfaces as a clean error at construction rather
/// than a panic deep inside the force evaluation during propagation.
pub fn new(
accel: Vector3,
frame: Frame,
start: Instant,
end: Instant,
) -> Result<Self, crate::orbitprop::Error> {
match frame {
Frame::GCRF | Frame::RTN | Frame::NTW | Frame::LVLH => Ok(Self {
accel,
frame,
start,
end,
}),
Frame::ITRF
| Frame::TIRS
| Frame::CIRS
| Frame::TEME
| Frame::EME2000
| Frame::ICRF => Err(crate::orbitprop::Error::UnsupportedThrustFrame { frame }),
}
}
/// Check if thrust is active at the given time
pub fn is_active(&self, time: &Instant) -> bool {
*time >= self.start && *time <= self.end
}
/// Compute thrust acceleration in GCRF at the given time and state.
///
/// Supported frames: [`Frame::GCRF`], [`Frame::RTN`], [`Frame::NTW`],
/// [`Frame::LVLH`]. Use NTW for thrust-along-velocity scenarios (most
/// electric-propulsion mission profiles); use RTN for position-tied
/// burn components; use LVLH if you're porting GN&C code written in
/// the crewed-spaceflight / body-pointing convention.
///
/// Returns `None` if thrust is not active at this time.
pub fn accel_gcrf(
&self,
time: &Instant,
pos_gcrf: &Vector3,
vel_gcrf: &Vector3,
) -> Option<Vector3> {
if !self.is_active(time) {
return None;
}
Some(match self.frame {
Frame::GCRF => self.accel,
Frame::RTN => {
let dcm = frametransform::rtn_to_gcrf(pos_gcrf, vel_gcrf);
dcm * self.accel
}
Frame::NTW => {
let dcm = frametransform::ntw_to_gcrf(pos_gcrf, vel_gcrf);
dcm * self.accel
}
Frame::LVLH => {
let dcm = frametransform::lvlh_to_gcrf(pos_gcrf, vel_gcrf);
dcm * self.accel
}
Frame::ITRF
| Frame::TIRS
| Frame::CIRS
| Frame::TEME
| Frame::EME2000
| Frame::ICRF => panic!(
"Unsupported frame for thrust: {}. Must be GCRF, RTN, NTW, or LVLH",
self.frame
),
})
}
}
/// A collection of thrust arcs
///
/// This is the primary thrust type used by the propagator.
/// It holds a list of `ContinuousThrust` entries and evaluates
/// the total thrust acceleration at any given time.
#[derive(Debug, Clone, Default)]
pub struct ThrustProfile {
pub thrusts: Vec<ContinuousThrust>,
}
impl ThrustProfile {
pub fn new(thrusts: Vec<ContinuousThrust>) -> Self {
Self { thrusts }
}
/// Compute total thrust acceleration in GCRF at the given time and state
///
/// Returns None if no thrust arcs are active at this time
pub fn accel_gcrf(
&self,
time: &Instant,
pos_gcrf: &Vector3,
vel_gcrf: &Vector3,
) -> Option<Vector3> {
let mut total = Vector3::zeros();
let mut active = false;
for t in &self.thrusts {
if let Some(a) = t.accel_gcrf(time, pos_gcrf, vel_gcrf) {
total += a;
active = true;
}
}
active.then_some(total)
}
pub fn is_empty(&self) -> bool {
self.thrusts.is_empty()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn new_rejects_unsupported_frames() {
let t0 = Instant::from_date(2024, 1, 1).unwrap();
let t1 = Instant::from_date(2024, 1, 2).unwrap();
let a = crate::mathtypes::Vector3::from_slice(&[1.0e-4, 0.0, 0.0]);
for f in [Frame::GCRF, Frame::RTN, Frame::NTW, Frame::LVLH] {
assert!(ContinuousThrust::new(a, f, t0, t1).is_ok());
}
for f in [
Frame::ITRF,
Frame::TIRS,
Frame::CIRS,
Frame::TEME,
Frame::EME2000,
Frame::ICRF,
] {
assert!(matches!(
ContinuousThrust::new(a, f, t0, t1),
Err(crate::orbitprop::Error::UnsupportedThrustFrame { .. })
));
}
}
}