Skip to content

Commit

Permalink
Safeguard against NaN state vector
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherRabotin committed Nov 18, 2024
1 parent 77658a8 commit f72e2f3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
22 changes: 11 additions & 11 deletions src/propagators/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use crate::propagators::TrajectoryEventSnafu;
use crate::time::{Duration, Epoch, Unit};
use crate::State;
use anise::almanac::Almanac;
use anise::errors::MathError;
use rayon::iter::ParallelBridge;
use rayon::prelude::ParallelIterator;
use snafu::ResultExt;
Expand Down Expand Up @@ -442,12 +443,21 @@ where
self.details.step = self.step_size;
return Ok(((self.details.step), next_state));
} else {
if next_state.iter().any(|x| x.is_nan()) {
return Err(PropagationError::PropMathError {
source: MathError::DomainError {
value: f64::NAN,
msg: "try another integration method, or decrease step size; part of state vector is",
},
});
}
// Compute the error estimate.
self.details.error =
self.prop
.opts
.error_ctrl
.estimate(&error_est, &next_state, state_vec);

if self.details.error <= self.prop.opts.tolerance
|| step_size_s <= self.prop.opts.min_step.to_seconds()
|| self.details.attempts >= self.prop.opts.attempts
Expand All @@ -473,11 +483,6 @@ where
assert!(step_size_s > 0.0);
// In all cases, let's update the step size to whatever was the adapted step size
self.step_size = step_size_s * Unit::Second;
trace!(
"+ integration error: {:e}\tnew step size: {}",
self.details.error,
step_size_s * Unit::Second
);
return Ok((self.details.step, next_state));
} else {
// Error is too high and we aren't using the smallest step, and we haven't hit the max number of attempts.
Expand All @@ -487,13 +492,8 @@ where
* step_size_s
* (self.prop.opts.tolerance / self.details.error)
.powf(1.0 / f64::from(self.prop.method.order() - 1));
step_size_s = self.prop.opts.bound_proposed_step(proposed_step_s);

trace!(
"- integration error: {:e}\tnew step size: {}",
self.details.error,
step_size_s * Unit::Second
);
step_size_s = self.prop.opts.bound_proposed_step(proposed_step_s);
// Note that we don't set self.step_size, that will be updated right before we return
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/propagators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

use anise::errors::MathError;
use snafu::prelude::*;
use std::fmt;

Expand Down Expand Up @@ -66,4 +67,6 @@ pub enum PropagationError {
NthEventError { nth: usize, found: usize },
#[snafu(display("propagation failed because {source}"))]
PropConfigError { source: ConfigError },
#[snafu(display("propagation encountered a math error {source}"))]
PropMathError { source: MathError },
}
2 changes: 1 addition & 1 deletion tests/orbit_determination/spacecraft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ fn od_val_sc_srp_estimation(
let setup = Propagator::dp78(
sc_dynamics,
IntegratorOptions::builder()
.max_step(1.minutes())
.max_step(30.seconds())
.error_ctrl(ErrorControl::RSSCartesianStep)
.build(),
);
Expand Down

0 comments on commit f72e2f3

Please sign in to comment.