extern crate hyperdual;
use self::hyperdual::{hyperspace_from_vector, Hyperdual, Owned};
use crate::celestia::{Orbit, Spacecraft};
use crate::dimensions::allocator::Allocator;
use crate::dimensions::{DefaultAllocator, DimName, Matrix3, MatrixN, Vector3, VectorN, U7};
use crate::State;
pub use crate::errors::NyxError;
pub mod orbital;
pub use self::orbital::*;
pub mod spacecraft;
pub use self::spacecraft::*;
pub mod thrustctrl;
pub mod deltavctrl;
pub mod solarpressure;
pub use self::solarpressure::*;
pub mod drag;
pub use self::drag::*;
pub mod sph_harmonics;
pub use self::sph_harmonics::*;
pub trait Dynamics: Clone + Sync + Send
where
DefaultAllocator: Allocator<f64, <Self::StateType as State>::Size>,
{
type HyperdualSize: DimName;
type StateType: State;
fn eom(
&self,
delta_t: f64,
state_vec: &VectorN<f64, <Self::StateType as State>::PropVecSize>,
state_ctx: &Self::StateType,
) -> Result<VectorN<f64, <Self::StateType as State>::PropVecSize>, NyxError>
where
DefaultAllocator: Allocator<f64, <Self::StateType as State>::PropVecSize>;
fn dual_eom(
&self,
delta_t: f64,
state_vec: &VectorN<Hyperdual<f64, Self::HyperdualSize>, <Self::StateType as State>::Size>,
state_ctx: &Self::StateType,
) -> Result<
(
VectorN<f64, <Self::StateType as State>::Size>,
MatrixN<f64, <Self::StateType as State>::Size>,
),
NyxError,
>
where
DefaultAllocator: Allocator<f64, Self::HyperdualSize>
+ Allocator<f64, <Self::StateType as State>::Size>
+ Allocator<f64, <Self::StateType as State>::Size, <Self::StateType as State>::Size>
+ Allocator<Hyperdual<f64, Self::HyperdualSize>, <Self::StateType as State>::Size>,
Owned<f64, Self::HyperdualSize>: Copy;
fn eom_grad(
&self,
delta_t_s: f64,
state_vec: &VectorN<f64, <Self::StateType as State>::Size>,
state_ctx: &Self::StateType,
) -> Result<
(
VectorN<f64, <Self::StateType as State>::Size>,
MatrixN<f64, <Self::StateType as State>::Size>,
),
NyxError,
>
where
DefaultAllocator: Allocator<f64, <Self::StateType as State>::Size>
+ Allocator<f64, <Self::StateType as State>::Size, <Self::StateType as State>::Size>
+ Allocator<f64, Self::HyperdualSize>
+ Allocator<Hyperdual<f64, Self::HyperdualSize>, <Self::StateType as State>::Size>,
Owned<f64, Self::HyperdualSize>: Copy,
{
let hyperstate: VectorN<
Hyperdual<f64, Self::HyperdualSize>,
<Self::StateType as State>::Size,
> = hyperspace_from_vector(&state_vec);
let (state, grad) = self.dual_eom(delta_t_s, &hyperstate, &state_ctx)?;
Ok((state, grad))
}
fn finally(&self, next_state: Self::StateType) -> Result<Self::StateType, NyxError> {
Ok(next_state)
}
}
pub trait ForceModel: Send + Sync {
fn eom(&self, ctx: &Spacecraft) -> Result<Vector3<f64>, NyxError>;
fn dual_eom(
&self,
radius: &Vector3<Hyperdual<f64, U7>>,
osc_ctx: &Spacecraft,
) -> Result<(Vector3<f64>, Matrix3<f64>), NyxError>;
}
pub trait AccelModel: Send + Sync {
fn eom(&self, osc: &Orbit) -> Result<Vector3<f64>, NyxError>;
fn dual_eom(
&self,
radius: &Vector3<Hyperdual<f64, U7>>,
osc_ctx: &Orbit,
) -> Result<(Vector3<f64>, Matrix3<f64>), NyxError>;
}