use super::propagator::SimpleState;
use super::srp::EcomParams;
use super::thrust::ThrustProfile;
use crate::mathtypes::*;
use crate::Instant;
pub trait SatProperties {
fn cd_a_over_m(&self, tm: &Instant, state: &SimpleState) -> f64;
fn cr_a_over_m(&self, tm: &Instant, state: &SimpleState) -> f64;
fn thrust_accel(
&self,
_tm: &Instant,
_pos_gcrf: &Vector3,
_vel_gcrf: &Vector3,
) -> Option<Vector3> {
None
}
fn srp_ecom(&self, _tm: &Instant, _state: &SimpleState) -> Option<EcomParams> {
None
}
}
#[derive(Debug, Clone)]
pub struct SatPropertiesSimple {
pub cdaoverm: f64,
pub craoverm: f64,
pub thrust: ThrustProfile,
pub ecom: Option<EcomParams>,
}
impl SatPropertiesSimple {
pub fn new(cdaoverm: f64, craoverm: f64) -> Self {
Self {
cdaoverm,
craoverm,
thrust: ThrustProfile {
thrusts: Vec::new(),
},
ecom: None,
}
}
pub fn with_thrust(mut self, thrust: ThrustProfile) -> Self {
self.thrust = thrust;
self
}
pub fn with_ecom(mut self, ecom: EcomParams) -> Self {
self.ecom = Some(ecom);
self
}
}
impl Default for SatPropertiesSimple {
fn default() -> Self {
Self {
cdaoverm: 0.0,
craoverm: 0.0,
thrust: ThrustProfile::default(),
ecom: None,
}
}
}
impl std::fmt::Display for SatPropertiesSimple {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(
f,
r#"Static Sat Properties:
Cd A / M : {} m^2/kg
Cr A / M : {} m^2/kg
Thrust arcs : {}
ECOM : {}"#,
self.cdaoverm,
self.craoverm,
self.thrust.thrusts.len(),
match &self.ecom {
Some(e) => format!(
"D0 {:.3e} Y0 {:.3e} B0 {:.3e} m/s^2 ({})",
e.d0,
e.y0,
e.b0,
if e.sun_relative { "Δu" } else { "u" }
),
None => "none".to_string(),
},
)
}
}
impl SatProperties for SatPropertiesSimple {
fn cd_a_over_m(&self, _tm: &Instant, _state: &SimpleState) -> f64 {
self.cdaoverm
}
fn cr_a_over_m(&self, _tm: &Instant, _state: &SimpleState) -> f64 {
self.craoverm
}
fn thrust_accel(
&self,
tm: &Instant,
pos_gcrf: &Vector3,
vel_gcrf: &Vector3,
) -> Option<Vector3> {
if self.thrust.is_empty() {
None
} else {
self.thrust.accel_gcrf(tm, pos_gcrf, vel_gcrf)
}
}
fn srp_ecom(&self, _tm: &Instant, _state: &SimpleState) -> Option<EcomParams> {
self.ecom
}
}