Hello everyone,
That’s a long time I posted my first suggestion but I am back after few personal/work events that prevented me to work on this subject!
Thank you for your feedbacks!
If I sum up everything, we should :
- catch MathRunTimeException only
- indicate the time and g values of both bracketing points
- possibly, indicate the last t and g value it evaluated
I changed my code catching the exception to fulfill these suggestions (I define a silly dectector so it fails fast) :
catch (MathRuntimeException e) {
throw new RuntimeException(
String.format(“%s failed to find root between %s (g=%f) and %s (g=%f) : %s\nLast iteration at %s (g=%f)”, detector, ta, ga, tb, gb, e.getMessage(), loopT,
loopG), e);
}
I have the following error in console :
java.lang.RuntimeException: java.lang.RuntimeException: some.package.SomeDetector@642a7222 failed to find root between 2030-06-18T00:10:00.000 (g=0.001000) and 2030-06-18T00:20:00.000 (g=-1.000000) : maximal count (50) exceeded
Last iteration at 2030-06-18T00:10:00.000 (g=0.001000)
at org.orekit.propagation.events.EventState.findRoot(EventState.java:380)
at org.orekit.propagation.events.EventState.evaluateStep(EventState.java:252)
at org.orekit.propagation.analytical.AbstractAnalyticalPropagator.acceptStep(AbstractAnalyticalPropagator.java:233)
at org.orekit.propagation.analytical.AbstractAnalyticalPropagator.propagate(AbstractAnalyticalPropagator.java:168)
…
Caused by: org.hipparchus.exception.MathIllegalStateException: maximal count (50) exceeded
at org.hipparchus.util.Incrementor.lambda$static$0(Incrementor.java:41)
at org.hipparchus.util.Incrementor.increment(Incrementor.java:238)
at org.hipparchus.analysis.solvers.BaseAbstractUnivariateSolver.incrementEvaluationCount(BaseAbstractUnivariateSolver.java:318)
at org.hipparchus.analysis.solvers.BaseAbstractUnivariateSolver.computeObjectiveValue(BaseAbstractUnivariateSolver.java:165)
at org.hipparchus.analysis.solvers.BracketingNthOrderBrentSolver.doSolveInterval(BracketingNthOrderBrentSolver.java:297)
at org.hipparchus.analysis.solvers.BracketingNthOrderBrentSolver.solveInterval(BracketingNthOrderBrentSolver.java:426)
at org.hipparchus.analysis.solvers.BracketedUnivariateSolver.solveInterval(BracketedUnivariateSolver.java:126)
at org.orekit.propagation.events.EventState.findRoot(EventState.java:352)
… 44 more
I have defined a unit test in EventDetectorTest :
@Test
public void testMathRuntimeException() {
try {
// initial conditions
Frame eme2000 = FramesFactory.getEME2000();
TimeScale utc = TimeScalesFactory.getUTC();
final AbsoluteDate initialDate = new AbsoluteDate(2011, 5, 11, utc);
EquinoctialOrbit initialOrbit = new EquinoctialOrbit(new PVCoordinates(new Vector3D(4008462.4706055815, -3155502.5373837613, -5044275.9880020910),
new Vector3D(-5012.9298276860990, 1920.3567095973078, -5172.7403501801580)), eme2000,
initialDate, Constants.WGS84_EARTH_MU);
KeplerianPropagator k = new KeplerianPropagator(initialOrbit);
k.addEventDetector(new AbstractDetector(100, 1e-6, 5, new ContinueOnEvent()) {
double lastValue = -1;
@Override
public double g(final SpacecraftState s) {
lastValue = lastValue * -1;
return lastValue;
}
@Override
protected AbstractDetector create(double newMaxCheck, double newThreshold, int newMaxIter, EventHandler newHandler) {
throw new UnsupportedOperationException("this class to be used locally");
}
});
k.propagate(initialDate.shiftedBy(initialOrbit.getKeplerianPeriod()));
Assert.fail("an exception should have been thrown");
}
catch (RuntimeException oe) {
Assert.assertSame(MathIllegalStateException.class, oe.getCause().getClass());
}
}
… do you think it is useful ?
@evan.ward I did not understand why I should put this code in 4 different places and I have never contribute to hipparchus.
Could you give some more information ? Or maybe, I could push my branch with my modifications so you could copy/paste where it should be done ?
Best regards,
Anne-Laure