use of org.orekit.propagation.events.handlers.EventHandler in project Orekit by CS-SI.
the class FunctionalDetectorTest method testFunctionalDetector.
/**
* Check {@link FunctionalDetector}.
*
* @throws OrekitException on error.
*/
@Test
public void testFunctionalDetector() throws OrekitException {
// setup
GFunction g = SpacecraftState::getMass;
EventHandler<EventDetector> handler = (s, detector, increasing) -> Action.STOP;
// action
FunctionalDetector detector = new FunctionalDetector().withMaxIter(1).withThreshold(2).withMaxCheck(3).withGFunction(g).withHandler(handler);
// verify
MatcherAssert.assertThat(detector.getMaxIterationCount(), CoreMatchers.is(1));
MatcherAssert.assertThat(detector.getThreshold(), CoreMatchers.is(2.0));
MatcherAssert.assertThat(detector.getMaxCheckInterval(), CoreMatchers.is(3.0));
MatcherAssert.assertThat(detector.getHandler(), CoreMatchers.is(handler));
MatcherAssert.assertThat(detector.getGFunction(), CoreMatchers.is(g));
SpacecraftState state = new SpacecraftState(new CartesianOrbit(new PVCoordinates(new Vector3D(1, 2, 3), new Vector3D(4, 5, 6)), FramesFactory.getGCRF(), AbsoluteDate.CCSDS_EPOCH, 4), 5);
MatcherAssert.assertThat(detector.g(state), CoreMatchers.is(5.0));
MatcherAssert.assertThat(detector.eventOccurred(null, false), CoreMatchers.is(Action.STOP));
}
use of org.orekit.propagation.events.handlers.EventHandler in project Orekit by CS-SI.
the class CloseEventsAbstractTest method testShortBracketingInterval.
/**
* The root finder requires the start point to be in the interval (a, b) which is hard
* when there aren't many numbers between a and b. This test uses a second event
* detector to force a very small window for the first event detector.
*/
@Test
public void testShortBracketingInterval() throws OrekitException {
// setup
double maxCheck = 10;
double tolerance = 1e-6;
final double t1 = FastMath.nextUp(10.0), t2 = 10.5;
// shared event list so we know the order in which they occurred
List<Event<EventDetector>> events = new ArrayList<>();
// never zero so there is no easy way out
EventDetector detectorA = new AbstractDetector<EventDetector>(maxCheck, tolerance, 100, new RecordAndContinue<>(events)) {
private static final long serialVersionUID = 1L;
@Override
public double g(SpacecraftState state) {
final AbsoluteDate t = state.getDate();
if (t.compareTo(epoch.shiftedBy(t1)) < 0) {
return -1;
} else if (t.compareTo(epoch.shiftedBy(t2)) < 0) {
return 1;
} else {
return -1;
}
}
@Override
protected EventDetector create(double newMaxCheck, double newThreshold, int newMaxIter, EventHandler<? super EventDetector> newHandler) {
return null;
}
};
TimeDetector detectorB = new TimeDetector(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.0));
// verify
Assert.assertEquals(3, 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(t1, events.get(1).getState().getDate().durationFrom(epoch), tolerance);
Assert.assertEquals(true, events.get(1).isIncreasing());
Assert.assertSame(detectorB, events.get(1).getDetector());
Assert.assertEquals(t2, events.get(2).getState().getDate().durationFrom(epoch), tolerance);
Assert.assertEquals(false, events.get(2).isIncreasing());
Assert.assertSame(detectorA, events.get(2).getDetector());
}
use of org.orekit.propagation.events.handlers.EventHandler in project Orekit by CS-SI.
the class DateDetectorTest method testGenericHandler.
/**
* Check that a generic event handler can be used with an event detector.
*
* @throws OrekitException on error.
*/
@Test
public void testGenericHandler() throws OrekitException {
// setup
dateDetector = new DateDetector(maxCheck, threshold, iniDate.shiftedBy(dt));
// generic event handler that works with all detectors.
EventHandler<EventDetector> handler = new EventHandler<EventDetector>() {
@Override
public Action eventOccurred(SpacecraftState s, EventDetector detector, boolean increasing) throws OrekitException {
Assert.assertSame(dateDetector, detector);
return Action.STOP;
}
@Override
public SpacecraftState resetState(EventDetector detector, SpacecraftState oldState) throws OrekitException {
throw new RuntimeException("Should not be called");
}
};
// action
dateDetector = dateDetector.withHandler(handler);
propagator.addEventDetector(dateDetector);
SpacecraftState finalState = propagator.propagate(iniDate.shiftedBy(100 * dt));
// verify
Assert.assertEquals(dt, finalState.getDate().durationFrom(iniDate), threshold);
}
Aggregations