use crate::dynamics::{Dynamics, DynamicsError};
use crate::od::groundpnt::GroundAsset;
use anise::prelude::Almanac;
use nalgebra::allocator::Allocator;
use nalgebra::{Const, DefaultAllocator, Matrix6, OMatrix, OVector, Vector6};
#[derive(Clone)]
pub struct GroundDynamics {}
impl Dynamics for GroundDynamics {
type StateType = GroundAsset;
type HyperdualSize = Const<6>;
fn eom(
&self,
_delta_t: f64,
_state_vec: &OVector<f64, <Self::StateType as crate::State>::VecLength>,
state_ctx: &Self::StateType,
_almanac: &Almanac,
) -> Result<OVector<f64, <Self::StateType as crate::State>::VecLength>, DynamicsError>
where
DefaultAllocator: Allocator<<Self::StateType as crate::State>::VecLength>,
{
let d_x = Vector6::from_iterator([
state_ctx.latitude_rate_deg_s,
state_ctx.longitude_rate_deg_s,
state_ctx.height_rate_km_s,
0.0,
0.0,
0.0,
]);
Ok(OVector::<f64, Const<42>>::from_iterator(
d_x.iter()
.chain(OVector::<f64, Const<36>>::zeros().iter())
.cloned(),
))
}
fn dual_eom(
&self,
_delta_t: f64,
osc: &Self::StateType,
_almanac: &Almanac,
) -> Result<
(
OVector<f64, <Self::StateType as crate::State>::Size>,
OMatrix<
f64,
<Self::StateType as crate::State>::Size,
<Self::StateType as crate::State>::Size,
>,
),
DynamicsError,
>
where
DefaultAllocator: Allocator<Self::HyperdualSize>
+ Allocator<<Self::StateType as crate::State>::Size>
+ Allocator<
<Self::StateType as crate::State>::Size,
<Self::StateType as crate::State>::Size,
>,
nalgebra::Owned<f64, Self::HyperdualSize>: Copy,
{
let dx = Vector6::new(
osc.latitude_rate_deg_s,
osc.longitude_rate_deg_s,
osc.height_rate_km_s,
0.0,
0.0,
0.0,
);
let mut grad = Matrix6::zeros();
grad[(0, 3)] = 1.0;
grad[(1, 4)] = 1.0;
grad[(2, 5)] = 1.0;
Ok((dx, grad))
}
}