use of org.orekit.propagation.events.handlers.RecordAndContinue.Event in project Orekit by CS-SI.
the class CloseEventsAbstractTest method testMultipleBackupsReverse.
/**
* Test where an event detector has to back up multiple times.
*/
@Test
public void testMultipleBackupsReverse() 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);
ContinuousDetector detectorB = new ContinuousDetector(-50, t1, t3, t4, t7).withHandler(new RecordAndContinue<>(events)).withMaxCheck(maxCheck).withThreshold(tolerance);
ContinuousDetector detectorC = new ContinuousDetector(-50, 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.0));
// verify
// really we only care that the Rules of Event Handling are not violated,
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());
}
use of org.orekit.propagation.events.handlers.RecordAndContinue.Event in project Orekit by CS-SI.
the class CloseEventsAbstractTest method testZeroAtBeginningAndEndOfInterval.
/**
* check root finding when zero at both ends.
*/
@Test
public void testZeroAtBeginningAndEndOfInterval() throws OrekitException {
// setup
double maxCheck = 10;
double tolerance = 1e-6;
double t1 = 10, t2 = 20;
// shared event list so we know the order in which they occurred
List<Event<EventDetector>> events = new ArrayList<>();
ContinuousDetector detectorA = new ContinuousDetector(t1, t2).withHandler(new RecordAndContinue<>(events)).withMaxCheck(maxCheck).withThreshold(tolerance);
Propagator propagator = getPropagator(10);
propagator.addEventDetector(detectorA);
// action
propagator.propagate(epoch.shiftedBy(30));
// verify
Assert.assertEquals(2, events.size());
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(t2, events.get(1).getState().getDate().durationFrom(epoch), tolerance);
Assert.assertEquals(false, events.get(1).isIncreasing());
Assert.assertSame(detectorA, events.get(1).getDetector());
}
use of org.orekit.propagation.events.handlers.RecordAndContinue.Event in project Orekit by CS-SI.
the class CloseEventsAbstractTest method testDoubleRoot.
/**
* Check when g(t) has a multiple root. e.g. g(t < root) < 0, g(root) = 0, g(t > root)
* < 0.
*/
@Test
public void testDoubleRoot() throws OrekitException {
// setup
double maxCheck = 10;
double tolerance = 1e-6;
double t1 = 11;
// shared event list so we know the order in which they occurred
List<Event<EventDetector>> events = new ArrayList<>();
TimeDetector detectorA = new TimeDetector(t1).withHandler(new RecordAndContinue<>(events)).withMaxCheck(maxCheck).withThreshold(tolerance);
TimeDetector detectorB = new TimeDetector(t1, t1).withHandler(new RecordAndContinue<>(events)).withMaxCheck(maxCheck).withThreshold(tolerance);
Propagator propagator = getPropagator(10);
propagator.addEventDetector(detectorA);
propagator.addEventDetector(detectorB);
// action
propagator.propagate(epoch.shiftedBy(30));
// verify
Assert.assertEquals(1, events.size());
Assert.assertEquals(t1, events.get(0).getState().getDate().durationFrom(epoch), 0.0);
Assert.assertEquals(true, events.get(0).isIncreasing());
Assert.assertSame(detectorA, events.get(0).getDetector());
// detector worked correctly
Assert.assertTrue(detectorB.g(state(t1)) == 0.0);
Assert.assertTrue(detectorB.g(state(t1 - 1e-6)) < 0);
Assert.assertTrue(detectorB.g(state(t1 + 1e-6)) < 0);
}
use of org.orekit.propagation.events.handlers.RecordAndContinue.Event in project Orekit by CS-SI.
the class CloseEventsAbstractTest method testEventCausedByStateResetReverse.
/**
* Test a reset event triggering another event at the same time.
*/
@Test
public void testEventCausedByStateResetReverse() throws OrekitException {
// setup
double maxCheck = 10;
double tolerance = 1e-6;
double t1 = -15.0;
SpacecraftState newState = new SpacecraftState(new KeplerianOrbit(6378137 + 500e3, 0, FastMath.PI / 2, 0, 0, FastMath.PI / 2, PositionAngle.TRUE, eci, epoch.shiftedBy(t1), mu));
// shared event list so we know the order in which they occurred
List<Event<EventDetector>> events = new ArrayList<>();
TimeDetector detectorA = new TimeDetector(t1).withHandler(new Handler<EventDetector>(events, Action.RESET_STATE) {
@Override
public SpacecraftState resetState(EventDetector detector, SpacecraftState oldState) {
return newState;
}
}).withMaxCheck(maxCheck).withThreshold(tolerance);
LatitudeCrossingDetector detectorB = new LatitudeCrossingDetector(earth, FastMath.toRadians(80)).withHandler(new RecordAndContinue<>(events)).withMaxCheck(maxCheck).withThreshold(tolerance);
Propagator propagator = getPropagator(10);
propagator.addEventDetector(detectorA);
propagator.addEventDetector(detectorB);
// action
propagator.propagate(epoch.shiftedBy(-40.0));
// verify
// really we only care that the Rules of Event Handling are not violated,
Assert.assertEquals(2, events.size());
Assert.assertEquals(t1, events.get(0).getState().getDate().durationFrom(epoch), tolerance);
Assert.assertEquals(true, events.get(0).isIncreasing());
Assert.assertEquals(detectorA, events.get(0).getDetector());
Assert.assertEquals(t1, events.get(1).getState().getDate().durationFrom(epoch), tolerance);
Assert.assertEquals(false, events.get(1).isIncreasing());
Assert.assertEquals(detectorB, events.get(1).getDetector());
}
use of org.orekit.propagation.events.handlers.RecordAndContinue.Event in project Orekit by CS-SI.
the class CloseEventsAbstractTest method testToleranceMaxIterations.
/**
* check when root finding tolerance > event finding tolerance.
*/
@Test
public void testToleranceMaxIterations() throws OrekitException {
// setup
double maxCheck = 10;
// less than 1 ulp
double tolerance = 1e-18;
AbsoluteDate t1 = epoch.shiftedBy(15).shiftedBy(FastMath.ulp(15.0) / 8);
// 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 RecordAndContinue<>(events)).withMaxCheck(maxCheck).withThreshold(tolerance);
Propagator propagator = getPropagator(10);
propagator.addEventDetector(detectorA);
// action
propagator.propagate(epoch.shiftedBy(30));
// verify
Assert.assertEquals(1, events.size());
// use root finder tolerance instead of event finder tolerance.
Assert.assertEquals(t1.durationFrom(epoch), events.get(0).getState().getDate().durationFrom(epoch), tolerance);
Assert.assertEquals(true, events.get(0).isIncreasing());
Assert.assertSame(detectorA, events.get(0).getDetector());
}
Aggregations