Search in sources :

Example 6 with Event

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

the class CloseEventsAbstractTest method testEventCausedByStateReset.

/**
 * Test a reset event triggering another event at the same time.
 */
@Test
public void testEventCausedByStateReset() 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(true, events.get(1).isIncreasing());
    Assert.assertEquals(detectorB, events.get(1).getDetector());
}
Also used : ArrayList(java.util.ArrayList) SpacecraftState(org.orekit.propagation.SpacecraftState) Propagator(org.orekit.propagation.Propagator) Event(org.orekit.propagation.events.handlers.RecordAndContinue.Event) StopOnEvent(org.orekit.propagation.events.handlers.StopOnEvent) KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) Test(org.junit.Test)

Example 7 with Event

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

the class CloseEventsAbstractTest method testShortBracketingIntervalReverse.

/**
 * 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 testShortBracketingIntervalReverse() throws OrekitException {
    // setup
    double maxCheck = 10;
    double tolerance = 1e-6;
    final double t1 = FastMath.nextDown(-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(false, 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(true, 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)

Example 8 with Event

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

the class CloseEventsAbstractTest method testCloseEventsFirstOneIsResetReverse.

/* The following tests are copies of the above tests, except that they propagate in
     * the reverse direction and all the signs on the time values are negated.
     */
@Test
public void testCloseEventsFirstOneIsResetReverse() throws OrekitException {
    // setup
    // a fairly rare state to reproduce this bug. Two dates, d1 < d2, that
    // are very close. Event triggers on d1 will reset state to break out of
    // event handling loop in AbstractIntegrator.acceptStep(). At this point
    // detector2 has g0Positive == true but the event time is set to just
    // before the event so g(t0) is negative. Now on processing the
    // next step the root solver checks the sign of the start, midpoint,
    // and end of the interval so we need another event less than half a max
    // check interval after d2 so that the g function will be negative at
    // all three times. Then we get a non bracketing exception.
    Propagator propagator = getPropagator(10.0);
    // switched for 9 to 1 to be close to the start of the step
    double t1 = -1;
    Handler<EventDetector> handler1 = new Handler<>(Action.RESET_DERIVATIVES);
    TimeDetector detector1 = new TimeDetector(t1).withHandler(handler1).withMaxCheck(10).withThreshold(1e-9);
    propagator.addEventDetector(detector1);
    RecordAndContinue<EventDetector> handler2 = new RecordAndContinue<>();
    TimeDetector detector2 = new TimeDetector(t1 - 1e-15, t1 - 4.9).withHandler(handler2).withMaxCheck(11).withThreshold(1e-9);
    propagator.addEventDetector(detector2);
    // action
    propagator.propagate(epoch.shiftedBy(-20));
    // verify
    List<Event<EventDetector>> events1 = handler1.getEvents();
    Assert.assertEquals(1, events1.size());
    Assert.assertEquals(t1, events1.get(0).getState().getDate().durationFrom(epoch), 0.0);
    List<Event<EventDetector>> events2 = handler2.getEvents();
    Assert.assertEquals(0, events2.size());
}
Also used : RecordAndContinue(org.orekit.propagation.events.handlers.RecordAndContinue) Propagator(org.orekit.propagation.Propagator) EventHandler(org.orekit.propagation.events.handlers.EventHandler) Event(org.orekit.propagation.events.handlers.RecordAndContinue.Event) StopOnEvent(org.orekit.propagation.events.handlers.StopOnEvent) Test(org.junit.Test)

Example 9 with Event

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

the class CloseEventsAbstractTest method testZeroAtBeginningAndEndOfIntervalOppositeSignReverse.

/**
 * check root finding when zero at both ends.
 */
@Test
public void testZeroAtBeginningAndEndOfIntervalOppositeSignReverse() 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), 0.0);
    Assert.assertEquals(false, events.get(0).isIncreasing());
    Assert.assertSame(detectorA, events.get(0).getDetector());
    Assert.assertEquals(t2, events.get(1).getState().getDate().durationFrom(epoch), 0.0);
    Assert.assertEquals(true, 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 10 with Event

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

the class CloseEventsAbstractTest method testTrickyCaseLower.

/**
 * "A Tricky Problem" from bug #239.
 */
@Test
public void testTrickyCaseLower() throws OrekitException {
    // setup
    double maxCheck = 10;
    double tolerance = 1e-6;
    double t1 = 1.0, t2 = 15, t3 = 16, t4 = 17, t5 = 18;
    // shared event list so we know the order in which they occurred
    List<Event<EventDetector>> events = new ArrayList<>();
    TimeDetector detectorA = new TimeDetector(t3).withHandler(new RecordAndContinue<>(events)).withMaxCheck(maxCheck).withThreshold(tolerance);
    TimeDetector detectorB = new TimeDetector(-10, t1, t2, t5).withHandler(new RecordAndContinue<>(events)).withMaxCheck(maxCheck).withThreshold(tolerance);
    TimeDetector detectorC = new TimeDetector(t4).withHandler(new Handler<>(events, Action.RESET_DERIVATIVES)).withMaxCheck(maxCheck).withThreshold(tolerance);
    Propagator propagator = getPropagator(10);
    propagator.addEventDetector(detectorA);
    propagator.addEventDetector(detectorB);
    propagator.addEventDetector(detectorC);
    // action
    propagator.propagate(epoch.shiftedBy(30));
    // verify
    // really we only care that the Rules of Event Handling are not violated,
    // but I only know one way to do that in this case.
    Assert.assertEquals(5, events.size());
    Assert.assertEquals(t1, events.get(0).getState().getDate().durationFrom(epoch), tolerance);
    Assert.assertEquals(false, events.get(0).isIncreasing());
    Assert.assertEquals(t2, events.get(1).getState().getDate().durationFrom(epoch), tolerance);
    Assert.assertEquals(true, events.get(1).isIncreasing());
    Assert.assertEquals(t3, events.get(2).getState().getDate().durationFrom(epoch), tolerance);
    Assert.assertEquals(true, events.get(2).isIncreasing());
    Assert.assertEquals(t4, events.get(3).getState().getDate().durationFrom(epoch), tolerance);
    Assert.assertEquals(true, events.get(3).isIncreasing());
    Assert.assertEquals(t5, events.get(4).getState().getDate().durationFrom(epoch), tolerance);
    Assert.assertEquals(false, events.get(4).isIncreasing());
}
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)

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