Search in sources :

Example 31 with Event

use of org.orekit.propagation.events.handlers.RecordAndContinue.Event in project Orekit by CS-SI.

the class CloseEventsAbstractTest method testSimultaneousEvents.

@Test
public void testSimultaneousEvents() throws OrekitException {
    // setup
    Propagator propagator = getPropagator(10);
    RecordAndContinue<EventDetector> handler1 = new RecordAndContinue<>();
    TimeDetector detector1 = new TimeDetector(5).withHandler(handler1).withMaxCheck(10).withThreshold(1);
    propagator.addEventDetector(detector1);
    RecordAndContinue<EventDetector> handler2 = new RecordAndContinue<>();
    TimeDetector detector2 = new TimeDetector(5).withHandler(handler2).withMaxCheck(10).withThreshold(1);
    propagator.addEventDetector(detector2);
    // action
    propagator.propagate(epoch.shiftedBy(20));
    // verify
    List<Event<EventDetector>> events1 = handler1.getEvents();
    Assert.assertEquals(1, events1.size());
    Assert.assertEquals(5, events1.get(0).getState().getDate().durationFrom(epoch), 0.0);
    List<Event<EventDetector>> events2 = handler2.getEvents();
    Assert.assertEquals(1, events2.size());
    Assert.assertEquals(5, events2.get(0).getState().getDate().durationFrom(epoch), 0.0);
}
Also used : RecordAndContinue(org.orekit.propagation.events.handlers.RecordAndContinue) Propagator(org.orekit.propagation.Propagator) Event(org.orekit.propagation.events.handlers.RecordAndContinue.Event) StopOnEvent(org.orekit.propagation.events.handlers.StopOnEvent) Test(org.junit.Test)

Example 32 with Event

use of org.orekit.propagation.events.handlers.RecordAndContinue.Event in project Orekit by CS-SI.

the class CloseEventsAbstractTest method testFastSwitching.

/**
 * test the g function switching with a period shorter than the tolerance. We don't
 * need to find any of the events, but we do need to not crash. And we need to
 * preserve the alternating increasing / decreasing sequence.
 */
@Test
public void testFastSwitching() throws OrekitException {
    // setup
    // step size of 10 to land in between two events we would otherwise miss
    Propagator propagator = getPropagator(10);
    RecordAndContinue<EventDetector> handler = new RecordAndContinue<>();
    TimeDetector detector1 = new TimeDetector(9.9, 10.1, 12).withHandler(handler).withMaxCheck(10).withThreshold(0.2);
    propagator.addEventDetector(detector1);
    // action
    propagator.propagate(epoch.shiftedBy(20));
    // verify
    // finds one or three events. Not 2.
    List<Event<EventDetector>> events1 = handler.getEvents();
    Assert.assertEquals(1, events1.size());
    Assert.assertEquals(9.9, events1.get(0).getState().getDate().durationFrom(epoch), 0.1);
    Assert.assertEquals(true, events1.get(0).isIncreasing());
}
Also used : RecordAndContinue(org.orekit.propagation.events.handlers.RecordAndContinue) Propagator(org.orekit.propagation.Propagator) Event(org.orekit.propagation.events.handlers.RecordAndContinue.Event) StopOnEvent(org.orekit.propagation.events.handlers.StopOnEvent) Test(org.junit.Test)

Example 33 with Event

use of org.orekit.propagation.events.handlers.RecordAndContinue.Event in project Orekit by CS-SI.

the class CloseEventsAbstractTest method testToleranceStop.

/**
 * check when root finding tolerance > event finding tolerance.
 */
@Test
public void testToleranceStop() 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));
    // 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));
    // verify it got to the end
    Assert.assertEquals(30.0, finalState.getDate().durationFrom(epoch), 0.0);
}
Also used : SpacecraftState(org.orekit.propagation.SpacecraftState) Propagator(org.orekit.propagation.Propagator) ArrayList(java.util.ArrayList) Event(org.orekit.propagation.events.handlers.RecordAndContinue.Event) StopOnEvent(org.orekit.propagation.events.handlers.StopOnEvent) Test(org.junit.Test)

Example 34 with Event

use of org.orekit.propagation.events.handlers.RecordAndContinue.Event in project Orekit by CS-SI.

the class CloseEventsAbstractTest method testZeroAtBeginningAndEndOfIntervalReverse.

/**
 * check root finding when zero at both ends.
 */
@Test
public void testZeroAtBeginningAndEndOfIntervalReverse() 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(-50, t1, t2).withHandler(new RecordAndContinue<>(events)).withMaxCheck(maxCheck).withThreshold(tolerance);
    Propagator propagator = getPropagator(10);
    propagator.addEventDetector(detectorA);
    // action
    propagator.propagate(epoch.shiftedBy(-30.0));
    // 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());
}
Also used : Propagator(org.orekit.propagation.Propagator) ArrayList(java.util.ArrayList) Event(org.orekit.propagation.events.handlers.RecordAndContinue.Event) StopOnEvent(org.orekit.propagation.events.handlers.StopOnEvent) Test(org.junit.Test)

Example 35 with Event

use of org.orekit.propagation.events.handlers.RecordAndContinue.Event 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());
}
Also used : SpacecraftState(org.orekit.propagation.SpacecraftState) Propagator(org.orekit.propagation.Propagator) ArrayList(java.util.ArrayList) Event(org.orekit.propagation.events.handlers.RecordAndContinue.Event) StopOnEvent(org.orekit.propagation.events.handlers.StopOnEvent) EventHandler(org.orekit.propagation.events.handlers.EventHandler) AbsoluteDate(org.orekit.time.AbsoluteDate) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)39 Event (org.orekit.propagation.events.handlers.RecordAndContinue.Event)39 Propagator (org.orekit.propagation.Propagator)38 StopOnEvent (org.orekit.propagation.events.handlers.StopOnEvent)38 ArrayList (java.util.ArrayList)32 SpacecraftState (org.orekit.propagation.SpacecraftState)9 RecordAndContinue (org.orekit.propagation.events.handlers.RecordAndContinue)6 EventHandler (org.orekit.propagation.events.handlers.EventHandler)5 AbsoluteDate (org.orekit.time.AbsoluteDate)5 KeplerianOrbit (org.orekit.orbits.KeplerianOrbit)3 Action (org.orekit.propagation.events.handlers.EventHandler.Action)2 Frame (org.orekit.frames.Frame)1 Orbit (org.orekit.orbits.Orbit)1 DateDetector (org.orekit.propagation.events.DateDetector)1