use of org.orekit.propagation.events.handlers.RecordAndContinue.Event in project Orekit by CS-SI.
the class CloseEventsAbstractTest method testCloseEvents.
@Test
public void testCloseEvents() throws OrekitException {
// setup
double tolerance = 1;
Propagator propagator = getPropagator(10);
RecordAndContinue<EventDetector> handler = new RecordAndContinue<>();
TimeDetector detector1 = new TimeDetector(5).withHandler(handler).withMaxCheck(10).withThreshold(tolerance);
propagator.addEventDetector(detector1);
TimeDetector detector2 = new TimeDetector(5.5).withHandler(handler).withMaxCheck(10).withThreshold(tolerance);
propagator.addEventDetector(detector2);
// action
propagator.propagate(epoch.shiftedBy(20));
// verify
List<Event<EventDetector>> events = handler.getEvents();
Assert.assertEquals(2, events.size());
Assert.assertEquals(5, events.get(0).getState().getDate().durationFrom(epoch), tolerance);
Assert.assertEquals(detector1, events.get(0).getDetector());
Assert.assertEquals(5.5, events.get(1).getState().getDate().durationFrom(epoch), tolerance);
Assert.assertEquals(detector2, events.get(1).getDetector());
}
use of org.orekit.propagation.events.handlers.RecordAndContinue.Event in project Orekit by CS-SI.
the class CloseEventsAbstractTest method testToleranceStopReverse.
/**
* check when root finding tolerance > event finding tolerance.
*/
@Test
public void testToleranceStopReverse() throws OrekitException {
// setup
double maxCheck = 10;
// less than 1 ulp
double tolerance = 1e-18;
double t1 = -15.1;
// shared event list so we know the order in which they occurred
List<Event<EventDetector>> events = new ArrayList<>();
FlatDetector detectorA = new FlatDetector(t1).withHandler(new Handler<>(events, Action.STOP)).withMaxCheck(maxCheck).withThreshold(tolerance);
Propagator propagator = getPropagator(10);
propagator.addEventDetector(detectorA);
// action
SpacecraftState finalState = propagator.propagate(epoch.shiftedBy(-30.0));
// verify
Assert.assertEquals(1, events.size());
// use root finder tolerance instead of event finder tolerance.
Assert.assertEquals(t1, events.get(0).getState().getDate().durationFrom(epoch), tolerance);
Assert.assertEquals(true, events.get(0).isIncreasing());
Assert.assertSame(detectorA, events.get(0).getDetector());
Assert.assertEquals(t1, finalState.getDate().durationFrom(epoch), tolerance);
// try to resume propagation
finalState = propagator.propagate(epoch.shiftedBy(-30.0));
// verify it got to the end
Assert.assertEquals(-30.0, finalState.getDate().durationFrom(epoch), 0.0);
}
use of org.orekit.propagation.events.handlers.RecordAndContinue.Event in project Orekit by CS-SI.
the class CloseEventsAbstractTest method testRootFindingToleranceReverse.
/**
* Test case for two event detectors. DetectorA has event at t2, DetectorB at t3, but
* due to the root finding tolerance DetectorB's event occurs at t1. With t1 < t2 <
* t3.
*/
@Test
public void testRootFindingToleranceReverse() throws OrekitException {
// setup
double maxCheck = 10;
double t2 = -11, t3 = t2 - 1e-5;
List<Event<EventDetector>> events = new ArrayList<>();
TimeDetector detectorA = new TimeDetector(t2).withHandler(new RecordAndContinue<>(events)).withMaxCheck(maxCheck).withThreshold(1e-6);
FlatDetector detectorB = new FlatDetector(t3).withHandler(new RecordAndContinue<>(events)).withMaxCheck(maxCheck).withThreshold(0.5);
Propagator propagator = getPropagator(10);
propagator.addEventDetector(detectorA);
propagator.addEventDetector(detectorB);
// action
propagator.propagate(epoch.shiftedBy(-30.0));
// verify
// if these fail the event finding did its job,
// but this test isn't testing what it is supposed to be
Assert.assertSame(detectorB, events.get(0).getDetector());
Assert.assertSame(detectorA, events.get(1).getDetector());
Assert.assertTrue(events.get(0).getState().getDate().compareTo(events.get(1).getState().getDate()) > 0);
// check event detection worked
Assert.assertEquals(2, events.size());
Assert.assertEquals(t3, events.get(0).getState().getDate().durationFrom(epoch), 0.5);
Assert.assertEquals(true, events.get(0).isIncreasing());
Assert.assertEquals(t2, events.get(1).getState().getDate().durationFrom(epoch), 1e-6);
Assert.assertEquals(true, events.get(1).isIncreasing());
}
use of org.orekit.propagation.events.handlers.RecordAndContinue.Event in project Orekit by CS-SI.
the class CloseEventsAbstractTest method testRootPlusToleranceHasWrongSign.
/**
* check when g(t < root) < 0, g(root + convergence) < 0.
*/
@Test
public void testRootPlusToleranceHasWrongSign() throws OrekitException {
// setup
double maxCheck = 10;
double tolerance = 1e-6;
final double toleranceB = 0.3;
double t1 = 11, t2 = 11.1, t3 = 11.2;
// shared event list so we know the order in which they occurred
List<Event<EventDetector>> events = new ArrayList<>();
TimeDetector detectorA = new TimeDetector(t2).withHandler(new RecordAndContinue<>(events)).withMaxCheck(maxCheck).withThreshold(1e-6);
TimeDetector detectorB = new TimeDetector(t1, t3).withHandler(new RecordAndContinue<>(events)).withMaxCheck(maxCheck).withThreshold(toleranceB);
Propagator propagator = getPropagator(10);
propagator.addEventDetector(detectorA);
propagator.addEventDetector(detectorB);
// action
propagator.propagate(epoch.shiftedBy(30));
// verify
// we only care that the rules are satisfied, there are other solutions
Assert.assertEquals(3, events.size());
Assert.assertEquals(t1, events.get(0).getState().getDate().durationFrom(epoch), toleranceB);
Assert.assertEquals(true, events.get(0).isIncreasing());
Assert.assertSame(detectorB, events.get(0).getDetector());
Assert.assertEquals(t3, events.get(1).getState().getDate().durationFrom(epoch), toleranceB);
Assert.assertEquals(false, events.get(1).isIncreasing());
Assert.assertSame(detectorB, events.get(1).getDetector());
Assert.assertEquals(t2, events.get(2).getState().getDate().durationFrom(epoch), tolerance);
Assert.assertEquals(true, events.get(2).isIncreasing());
Assert.assertSame(detectorA, events.get(2).getDetector());
// chronological
for (int i = 1; i < events.size(); i++) {
Assert.assertTrue(events.get(i).getState().getDate().compareTo(events.get(i - 1).getState().getDate()) >= 0);
}
}
use of org.orekit.propagation.events.handlers.RecordAndContinue.Event in project Orekit by CS-SI.
the class CloseEventsAbstractTest method testMultipleBackups.
/**
* Test where an event detector has to back up multiple times.
*/
@Test
public void testMultipleBackups() throws OrekitException {
// setup
double maxCheck = 10;
double tolerance = 1e-6;
double t1 = 1.0, t2 = 2, t3 = 3, t4 = 4, t5 = 5, t6 = 6.5, t7 = 7;
// shared event list so we know the order in which they occurred
List<Event<EventDetector>> events = new ArrayList<>();
ContinuousDetector detectorA = new ContinuousDetector(t6).withHandler(new RecordAndContinue<>(events)).withMaxCheck(maxCheck).withThreshold(tolerance);
FlatDetector detectorB = new FlatDetector(t1, t3, t4, t7).withHandler(new RecordAndContinue<>(events)).withMaxCheck(maxCheck).withThreshold(tolerance);
ContinuousDetector detectorC = new ContinuousDetector(t2, t5).withHandler(new RecordAndContinue<>(events)).withMaxCheck(maxCheck).withThreshold(tolerance);
Propagator propagator = getPropagator(10);
propagator.addEventDetector(detectorA);
propagator.addEventDetector(detectorB);
propagator.addEventDetector(detectorC);
// action
propagator.propagate(epoch.shiftedBy(30));
// verify
// need at least 5 events to check that multiple backups occurred
Assert.assertEquals(5, events.size());
Assert.assertEquals(t1, events.get(0).getState().getDate().durationFrom(epoch), tolerance);
Assert.assertEquals(true, events.get(0).isIncreasing());
Assert.assertEquals(detectorB, events.get(0).getDetector());
Assert.assertEquals(t2, events.get(1).getState().getDate().durationFrom(epoch), tolerance);
Assert.assertEquals(true, events.get(1).isIncreasing());
Assert.assertEquals(detectorC, events.get(1).getDetector());
// reporting t3 and t4 is optional, seeing them is not.
// we know a root was found at t3 because events are reported at t2 and t5.
/*
Assert.assertEquals(t3, events.get(2).getT(), tolerance);
Assert.assertEquals(false, events.get(2).isIncreasing());
Assert.assertEquals(detectorB, events.get(2).getHandler());
Assert.assertEquals(t4, events.get(3).getT(), tolerance);
Assert.assertEquals(true, events.get(3).isIncreasing());
Assert.assertEquals(detectorB, events.get(3).getHandler());
*/
Assert.assertEquals(t5, events.get(2).getState().getDate().durationFrom(epoch), tolerance);
Assert.assertEquals(false, events.get(2).isIncreasing());
Assert.assertEquals(detectorC, events.get(2).getDetector());
Assert.assertEquals(t6, events.get(3).getState().getDate().durationFrom(epoch), tolerance);
Assert.assertEquals(true, events.get(3).isIncreasing());
Assert.assertEquals(detectorA, events.get(3).getDetector());
Assert.assertEquals(t7, events.get(4).getState().getDate().durationFrom(epoch), tolerance);
Assert.assertEquals(false, events.get(4).isIncreasing());
Assert.assertEquals(detectorB, events.get(4).getDetector());
}
Aggregations