extern crate hyperdual;
use self::hyperdual::{hyperspace_from_vector, Hyperdual, Owned};
use crate::celestia::{Frame, State};
use crate::dimensions::allocator::Allocator;
use crate::dimensions::{DefaultAllocator, DimName, MatrixMN, Vector3, VectorN, U3, U7};
use crate::time::Epoch;
pub mod orbital;
pub mod momentum;
pub mod spacecraft;
pub mod propulsion;
pub mod thrustctrl;
pub mod deltavctrl;
pub mod missionarc;
pub mod solarpressure;
pub mod drag;
pub mod sph_harmonics;
pub trait Dynamics {
type StateSize: DimName;
type StateType: Copy;
fn time(&self) -> f64;
fn state_vector(&self) -> VectorN<f64, Self::StateSize>
where
DefaultAllocator: Allocator<f64, Self::StateSize>;
fn eom(&self, t: f64, state: &VectorN<f64, Self::StateSize>) -> VectorN<f64, Self::StateSize>
where
DefaultAllocator: Allocator<f64, Self::StateSize>;
fn set_state(&mut self, new_t: f64, new_state: &VectorN<f64, Self::StateSize>)
where
DefaultAllocator: Allocator<f64, Self::StateSize>;
fn state(&self) -> Self::StateType;
}
pub trait AutoDiff {
type HyperStateSize: DimName;
type STMSize: DimName;
fn eom_grad(
&self,
epoch: Epoch,
integr_frame: Frame,
state: &VectorN<f64, Self::STMSize>,
) -> (
VectorN<f64, Self::STMSize>,
MatrixMN<f64, Self::STMSize, Self::STMSize>,
)
where
DefaultAllocator: Allocator<f64, Self::STMSize>
+ Allocator<f64, Self::STMSize, Self::STMSize>
+ Allocator<f64, Self::HyperStateSize>
+ Allocator<Hyperdual<f64, Self::HyperStateSize>, Self::STMSize>,
Owned<f64, Self::HyperStateSize>: Copy,
{
let hyperstate: VectorN<Hyperdual<f64, Self::HyperStateSize>, Self::STMSize> =
hyperspace_from_vector(&state);
let (state, grad) = self.dual_eom(epoch, integr_frame, &hyperstate);
(state, grad)
}
fn dual_eom(
&self,
epoch: Epoch,
integr_frame: Frame,
state: &VectorN<Hyperdual<f64, Self::HyperStateSize>, Self::STMSize>,
) -> (
VectorN<f64, Self::STMSize>,
MatrixMN<f64, Self::STMSize, Self::STMSize>,
)
where
DefaultAllocator: Allocator<f64, Self::HyperStateSize>
+ Allocator<f64, Self::STMSize>
+ Allocator<f64, Self::STMSize, Self::STMSize>
+ Allocator<Hyperdual<f64, Self::HyperStateSize>, Self::STMSize>,
Owned<f64, Self::HyperStateSize>: Copy;
}
pub trait ForceModel: AutoDiff<STMSize = U3, HyperStateSize = U7> {
fn eom(&self, osc: &State) -> Vector3<f64>;
}
pub trait AccelModel {
fn eom(&self, osc: &State) -> Vector3<f64>;
}