use astrodyn_dynamics::{
Abm4State as RawAbm4State, GaussJacksonConfig as RawGaussJacksonConfig,
GaussJacksonState as RawGaussJacksonState, IntegratorType as RawIntegratorType,
LsodeConfig as RawLsodeConfig, LsodeState as RawLsodeState,
};
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub enum IntegratorType {
#[default]
Rk4,
Rkf45,
GaussJackson(GaussJacksonConfig),
Abm4,
Lsode(LsodeConfig),
}
impl From<IntegratorType> for RawIntegratorType {
fn from(value: IntegratorType) -> Self {
match value {
IntegratorType::Rk4 => RawIntegratorType::Rk4,
IntegratorType::Rkf45 => RawIntegratorType::Rkf45,
IntegratorType::GaussJackson(cfg) => RawIntegratorType::GaussJackson(cfg.into()),
IntegratorType::Abm4 => RawIntegratorType::Abm4,
IntegratorType::Lsode(cfg) => RawIntegratorType::Lsode(cfg.into()),
}
}
}
impl From<RawIntegratorType> for IntegratorType {
fn from(value: RawIntegratorType) -> Self {
match value {
RawIntegratorType::Rk4 => IntegratorType::Rk4,
RawIntegratorType::Rkf45 => IntegratorType::Rkf45,
RawIntegratorType::GaussJackson(cfg) => IntegratorType::GaussJackson(cfg.into()),
RawIntegratorType::Abm4 => IntegratorType::Abm4,
RawIntegratorType::Lsode(cfg) => IntegratorType::Lsode(cfg.into()),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct GaussJacksonConfig(RawGaussJacksonConfig);
impl GaussJacksonConfig {
pub fn with_order(order: usize) -> Self {
Self(RawGaussJacksonConfig::with_order(order))
}
pub fn standard() -> Self {
Self(RawGaussJacksonConfig::standard())
}
pub fn check(&self) -> Vec<String> {
self.0.check()
}
pub fn validate(&self) {
self.0.validate()
}
pub fn with_allow_non_convergence(mut self, allow: bool) -> Self {
self.0.allow_non_convergence = allow;
self
}
}
impl From<GaussJacksonConfig> for RawGaussJacksonConfig {
#[inline]
fn from(value: GaussJacksonConfig) -> Self {
value.0
}
}
impl From<RawGaussJacksonConfig> for GaussJacksonConfig {
#[inline]
fn from(value: RawGaussJacksonConfig) -> Self {
Self(value)
}
}
#[derive(Debug, Clone)]
pub struct GaussJacksonState(RawGaussJacksonState);
impl GaussJacksonState {
pub fn new(config: GaussJacksonConfig) -> Self {
Self(RawGaussJacksonState::new(config.into()))
}
pub fn reset(&mut self) {
self.0.reset()
}
pub fn reset_for_topology_change(&mut self) {
self.0.reset_for_topology_change()
}
pub fn mark_topology_dirty(&mut self) {
self.0.mark_topology_dirty()
}
pub fn is_topology_dirty(&self) -> bool {
self.0.is_topology_dirty()
}
pub fn config(&self) -> GaussJacksonConfig {
GaussJacksonConfig(*self.0.config())
}
pub fn is_priming(&self) -> bool {
self.0.is_priming()
}
pub fn bootstrap_unconverged_iterations(&self) -> u32 {
self.0.bootstrap_unconverged_iterations()
}
#[inline]
pub fn inner_mut(&mut self) -> &mut RawGaussJacksonState {
&mut self.0
}
#[inline]
pub fn inner(&self) -> &RawGaussJacksonState {
&self.0
}
}
impl From<RawGaussJacksonState> for GaussJacksonState {
#[inline]
fn from(value: RawGaussJacksonState) -> Self {
Self(value)
}
}
impl From<GaussJacksonState> for RawGaussJacksonState {
#[inline]
fn from(value: GaussJacksonState) -> Self {
value.0
}
}
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct LsodeConfig(RawLsodeConfig);
impl LsodeConfig {
pub fn non_stiff_adams() -> Self {
Self(RawLsodeConfig::default())
}
pub fn bdf_stiff() -> Self {
Self(RawLsodeConfig {
method: astrodyn_dynamics::IntegrationMethod::ImplicitBackDiffStiff,
corrector: astrodyn_dynamics::CorrectorMethod::NewtonIterInternalJac,
max_order: 5,
..RawLsodeConfig::default()
})
}
pub fn with_tolerances(mut self, rel_tolerance: f64, abs_tolerance: f64) -> Self {
self.0.rel_tolerance = rel_tolerance;
self.0.abs_tolerance = abs_tolerance;
self
}
pub fn with_max_order(mut self, max_order: usize) -> Self {
self.0.max_order = max_order;
self
}
pub fn with_max_num_steps(mut self, max_num_steps: usize) -> Self {
self.0.max_num_steps = max_num_steps;
self
}
pub fn validate(&self) {
self.0.check()
}
}
impl From<LsodeConfig> for RawLsodeConfig {
fn from(value: LsodeConfig) -> Self {
value.0
}
}
impl From<RawLsodeConfig> for LsodeConfig {
fn from(value: RawLsodeConfig) -> Self {
Self(value)
}
}
#[derive(Debug, Clone)]
pub struct LsodeState(RawLsodeState);
impl LsodeState {
pub fn new(config: LsodeConfig) -> Self {
Self(RawLsodeState::new(config.into()))
}
pub fn config(&self) -> LsodeConfig {
LsodeConfig(*self.0.config())
}
pub fn mark_topology_dirty(&mut self) {
self.0.mark_topology_dirty()
}
pub fn is_topology_dirty(&self) -> bool {
self.0.is_topology_dirty()
}
pub fn reset_for_topology_change(&mut self) {
self.0.reset_for_topology_change()
}
#[inline]
pub fn inner_mut(&mut self) -> &mut RawLsodeState {
&mut self.0
}
#[inline]
pub fn inner(&self) -> &RawLsodeState {
&self.0
}
}
impl From<RawLsodeState> for LsodeState {
#[inline]
fn from(value: RawLsodeState) -> Self {
Self(value)
}
}
impl From<LsodeState> for RawLsodeState {
#[inline]
fn from(value: LsodeState) -> Self {
value.0
}
}
#[derive(Debug, Clone, Default)]
pub struct Abm4State(RawAbm4State);
impl Abm4State {
pub fn new() -> Self {
Self(RawAbm4State::new())
}
pub fn reset(&mut self) {
self.0.reset()
}
pub fn reset_for_topology_change(&mut self) {
self.0.reset_for_topology_change()
}
pub fn mark_topology_dirty(&mut self) {
self.0.mark_topology_dirty()
}
pub fn is_topology_dirty(&self) -> bool {
self.0.is_topology_dirty()
}
pub fn is_priming(&self) -> bool {
self.0.is_priming()
}
#[inline]
pub fn inner_mut(&mut self) -> &mut RawAbm4State {
&mut self.0
}
#[inline]
pub fn inner(&self) -> &RawAbm4State {
&self.0
}
}
impl From<RawAbm4State> for Abm4State {
#[inline]
fn from(value: RawAbm4State) -> Self {
Self(value)
}
}
impl From<Abm4State> for RawAbm4State {
#[inline]
fn from(value: Abm4State) -> Self {
value.0
}
}