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
use super::hyperdual::Hyperdual;
use super::ForceModel;
use crate::celestia::{Cosm, Frame, Spacecraft};
use crate::dimensions::{Matrix3, Vector3, U7};
use crate::errors::NyxError;
use std::sync::Arc;
#[derive(Clone, Copy, Debug)]
pub enum AtmDensity {
Constant(f64),
Exponential { rho0: f64, r0: f64, ref_alt_m: f64 },
StdAtm { max_alt_m: f64 },
}
#[derive(Clone)]
pub struct ConstantDrag {
pub rho: f64,
pub drag_frame: Frame,
pub cosm: Arc<Cosm>,
}
impl ForceModel for ConstantDrag {
fn eom(&self, ctx: &Spacecraft) -> Result<Vector3<f64>, NyxError> {
let osc = self.cosm.frame_chg(&ctx.orbit, self.drag_frame);
let velocity = osc.velocity();
Ok(-0.5 * self.rho * ctx.cd * ctx.drag_area_m2 * velocity.norm() * velocity)
}
fn dual_eom(
&self,
_radius: &Vector3<Hyperdual<f64, U7>>,
_osc_ctx: &Spacecraft,
) -> Result<(Vector3<f64>, Matrix3<f64>), NyxError> {
Err(NyxError::PartialsUndefined)
}
}
#[derive(Clone)]
pub struct Drag {
pub density: AtmDensity,
pub drag_frame: Frame,
pub cosm: Arc<Cosm>,
}
impl Drag {
pub fn earth_exp(cosm: Arc<Cosm>) -> Arc<Self> {
Arc::new(Self {
density: AtmDensity::Exponential {
rho0: 3.614e-13,
r0: 700_000.0,
ref_alt_m: 88_667.0,
},
drag_frame: cosm.frame("IAU Earth"),
cosm,
})
}
pub fn std_atm1976(cosm: Arc<Cosm>) -> Arc<Self> {
Arc::new(Self {
density: AtmDensity::StdAtm {
max_alt_m: 1_000_000.0,
},
drag_frame: cosm.frame("IAU Earth"),
cosm,
})
}
}
impl ForceModel for Drag {
fn eom(&self, ctx: &Spacecraft) -> Result<Vector3<f64>, NyxError> {
let integration_frame = ctx.orbit.frame;
let osc = self.cosm.frame_chg(&ctx.orbit, self.drag_frame);
match self.density {
AtmDensity::Constant(rho) => {
let velocity = osc.velocity();
Ok(-0.5 * rho * ctx.cd * ctx.drag_area_m2 * velocity.norm() * velocity)
}
AtmDensity::Exponential {
rho0,
r0,
ref_alt_m,
} => {
let rho = rho0
* (-(osc.rmag() - (r0 + self.drag_frame.equatorial_radius())) / ref_alt_m)
.exp();
let velocity_integr_frame = self.cosm.frame_chg(&osc, integration_frame).velocity();
let velocity = velocity_integr_frame - osc.velocity();
Ok(-0.5 * rho * ctx.cd * ctx.drag_area_m2 * velocity.norm() * velocity)
}
AtmDensity::StdAtm { max_alt_m } => {
let altitude_km = osc.rmag() - self.drag_frame.equatorial_radius();
let rho = if altitude_km > max_alt_m / 1_000.0 {
10.0_f64.powf((-7e-5) * altitude_km - 14.464)
} else {
let scale = (altitude_km - 526.8000) / 292.8563;
let logdensity =
0.34047 * scale.powi(6) - 0.5889 * scale.powi(5) - 0.5269 * scale.powi(4)
+ 1.0036 * scale.powi(3)
+ 0.60713 * scale.powi(2)
- 2.3024 * scale
- 12.575;
10.0_f64.powf(logdensity)
};
let velocity_integr_frame = self.cosm.frame_chg(&osc, integration_frame).velocity();
let velocity = velocity_integr_frame - osc.velocity();
Ok(-0.5 * rho * ctx.cd * ctx.drag_area_m2 * velocity.norm() * velocity)
}
}
}
fn dual_eom(
&self,
_radius: &Vector3<Hyperdual<f64, U7>>,
_osc_ctx: &Spacecraft,
) -> Result<(Vector3<f64>, Matrix3<f64>), NyxError> {
Err(NyxError::PartialsUndefined)
}
}