Hipparchus-Math / hipparchus

An efficient, general-purpose mathematics components library in the Java programming language
Apache License 2.0
142 stars 41 forks source link

EventState.check throws MathRuntimeException for some simultaneous events at end of integration step #211

Closed mvarnim closed 1 year ago

mvarnim commented 2 years ago

Hi, I was just using Hipparchus through Orekit in one of my projects and encountered this problem. The stack trace suggested that I file a bug report. The underlying issue seems to be with Hipparchus so I'm putting this here rather than at Orekit.

Environment

I'm using Orekit 11.2.1 and Hipparchus 2.1, both managed by Maven, and JDK 17.0.2 as the runtime environment.

Stacktrace

Exception in thread "main" org.orekit.errors.OrekitException: internal error, please fill a bug report at https://github.com/Hipparchus-Math/hipparchus/issues
    at org.orekit.errors.OrekitException.unwrap(OrekitException.java:154)
    at org.orekit.propagation.integration.AbstractIntegratedPropagator.integrateDynamics(AbstractIntegratedPropagator.java:511)
    at org.orekit.propagation.integration.AbstractIntegratedPropagator.propagate(AbstractIntegratedPropagator.java:425)
    at org.orekit.propagation.integration.AbstractIntegratedPropagator.propagate(AbstractIntegratedPropagator.java:385)
    at myenvironment.Propagator.propagate(Propagator.java:142)
    at myenvironment.Scenario.main(Scenario.java:404)
Caused by: org.hipparchus.exception.MathRuntimeException: internal error, please fill a bug report at https://github.com/Hipparchus-Math/hipparchus/issues
    at org.hipparchus.exception.MathRuntimeException.createInternalError(MathRuntimeException.java:69)
    at org.hipparchus.ode.events.EventState.check(EventState.java:575)
    at org.hipparchus.ode.events.EventState.tryAdvance(EventState.java:445)
    at org.hipparchus.ode.AbstractIntegrator.acceptStep(AbstractIntegrator.java:425)
    at org.hipparchus.ode.nonstiff.EmbeddedRungeKuttaIntegrator.integrate(EmbeddedRungeKuttaIntegrator.java:285)
    at org.orekit.propagation.integration.AbstractIntegratedPropagator.integrateDynamics(AbstractIntegratedPropagator.java:477)
    ... 4 more

Steps to reproduce and initial troubleshooting

The issue can be reproduced reliably for a given scenario using multiple independent events. When I change the parameters of the events (i. e. when they are expected to occur), the exception happens at another time.

I've set a conditional breakpoint at (EventState.java:445) and I can see that pendingEvent=true, t=0.09999999999999998 and pendingEventTime=0.09999999999999488.

I've set the propagator to (attempt to) propagate 100ms in every step. There seems to be an event (actually multiple events) happening in close proximity to when the entire propagation step is supposed to conclude. However, I know that other events have triggered at such times without issues previously during this simulation run.

There was another (independent) event shortly before at t=0.09995. Analytically, I can calculate that both events should happen exactly at t=0.1. In the global (Orekit) timescale, one event happens first at 10.001 seconds and repeats every 0.431 seconds, the other event happens first at 9.999 seconds and repeats every 0.143 seconds. I have encountered situations where multiple events happen at the same time previously during the simulation run, without any issues.

My EventState is set up with maxCheckInterval=600, convergence=0.0005 and maxIterationCount=100.

Modifying the convergence value has no effect on when the exception occurs (625.9 seconds from the start of the simulation) but it does slightly shift the two events' timestamps. For example, choosing convergence=0.0001 I get the same results t=0.09999999999999998 and pendingEventTime=0.09999999999999488 for the event that triggers the exception but the previous event now happens at t=0.099999999999913.

The propagator being used is the DormandPrince853Integrator with minStep=0.001 and maxStep=1000.0 and vecAbsoluteTolerance=[40.0, 4.299141733674762E-6, 2.866094489116508E-6, 7.16523622279127E-7, 7.165236222791271E-7, 1.4330472445582535E-6, 1.0E-6], vecRelativeTolerance=[1.433047244558254E-6, 1.433047244558254E-6, 1.433047244558254E-6, 1.433047244558254E-6, 1.433047244558254E-6, 1.433047244558254E-6, 1.433047244558254E-6].

maisonobe commented 1 year ago

This should have been fixed as part of fixing issue #270, the fix is in the master branch and will be released with Hipparchus 3.0 (which will be a dependency for Orekit 12.0).