Skip to main content

sidereon_core/astro/propagator/
api.rs

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