Skip to main content

sidereon_core/astro/propagator/
api.rs

1use crate::astro::error::PropagationError;
2
3#[derive(Debug, Clone, Default)]
4pub struct PropagationContext {
5    // For future expansion: frame, atmosphere model, etc.
6}
7
8#[derive(Debug, Clone, Copy, PartialEq)]
9pub struct IntegratorOptions {
10    pub abs_tol: f64,
11    pub rel_tol: f64,
12    pub min_step: f64,
13    pub max_step: f64,
14    pub initial_step: f64,
15    pub max_steps: u32,
16    pub dense_output: bool,
17}
18
19impl Default for IntegratorOptions {
20    fn default() -> Self {
21        Self {
22            abs_tol: 1e-9,
23            rel_tol: 1e-12,
24            min_step: 1e-6,
25            max_step: 3600.0,
26            initial_step: 60.0,
27            max_steps: 1_000_000,
28            dense_output: false,
29        }
30    }
31}
32
33pub(crate) fn validate_integrator_options(
34    opts: &IntegratorOptions,
35) -> Result<(), PropagationError> {
36    validate_step_options(opts)
37}
38
39pub(crate) fn validate_adaptive_integrator_options(
40    opts: &IntegratorOptions,
41) -> Result<(), PropagationError> {
42    validate_step_options(opts)?;
43    crate::validate::finite_positive(opts.abs_tol, "abs_tol").map_err(map_field_error)?;
44    crate::validate::finite_positive(opts.rel_tol, "rel_tol").map_err(map_field_error)?;
45    Ok(())
46}
47
48pub(crate) fn validate_integrator_epoch(
49    value: f64,
50    field: &'static str,
51) -> Result<(), PropagationError> {
52    crate::validate::finite(value, field)
53        .map(|_| ())
54        .map_err(map_field_error)
55}
56
57fn validate_step_options(opts: &IntegratorOptions) -> Result<(), PropagationError> {
58    crate::validate::positive_step(opts.initial_step, "initial_step").map_err(map_field_error)?;
59    crate::validate::positive_step(opts.min_step, "min_step").map_err(map_field_error)?;
60    crate::validate::positive_step(opts.max_step, "max_step").map_err(map_field_error)?;
61    Ok(())
62}
63
64fn map_field_error(error: crate::validate::FieldError) -> PropagationError {
65    PropagationError::InvalidInput(format!("{} {}", error.field(), error.reason()))
66}