Search in sources :

Example 21 with Event

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

the class CloseEventsAbstractTest method testRootPlusToleranceHasWrongSignAndLessThanTb.

/**
 * check when g(t < root) < 0,  g(root + convergence) < 0.
 */
@Test
public void testRootPlusToleranceHasWrongSignAndLessThanTb() throws OrekitException {
    // setup
    // test is fragile w.r.t. implementation and these parameters
    double maxCheck = 10;
    double tolerance = 0.5;
    double t1 = 11, t2 = 11.4, t3 = 12.0;
    // shared event list so we know the order in which they occurred
    List<Event<EventDetector>> events = new ArrayList<>();
    FlatDetector detectorB = new FlatDetector(t1, t2, t3).withHandler(new RecordAndContinue<>(events)).withMaxCheck(maxCheck).withThreshold(tolerance);
    Propagator propagator = getPropagator(10);
    propagator.addEventDetector(detectorB);
    // action
    propagator.propagate(epoch.shiftedBy(30));
    // verify
    // allowed to find t1 or t3.
    Assert.assertEquals(1, events.size());
    Assert.assertEquals(t1, events.get(0).getState().getDate().durationFrom(epoch), tolerance);
    Assert.assertEquals(true, events.get(0).isIncreasing());
    Assert.assertSame(detectorB, events.get(0).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 22 with Event

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

the class CloseEventsAbstractTest method testRootPlusToleranceHasWrongSignReverse.

/**
 * check when g(t < root) < 0,  g(root + convergence) < 0.
 */
@Test
public void testRootPlusToleranceHasWrongSignReverse() 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(tolerance);
    TimeDetector detectorB = new TimeDetector(-50, 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.0));
    // verify
    // we only care that the rules are satisfied. There are multiple 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());
    // ascending order
    Assert.assertTrue(events.get(0).getState().getDate().compareTo(events.get(1).getState().getDate()) >= 0);
    Assert.assertTrue(events.get(1).getState().getDate().compareTo(events.get(2).getState().getDate()) >= 0);
}
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 23 with Event

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

the class CloseEventsAbstractTest method testEventChangesGFunctionDefinitionReverse.

/**
 * test when one event detector changes the definition of another's g function before
 * the end of the step as a result of a continue action. Not sure if this should be
 * officially supported, but it is used in Orekit's DateDetector, it's useful, and not
 * too hard to implement.
 */
@Test
public void testEventChangesGFunctionDefinitionReverse() throws OrekitException {
    // setup
    double maxCheck = 5;
    double tolerance = 1e-6;
    double t1 = -11, t2 = -19;
    // shared event list so we know the order in which they occurred
    List<Event<EventDetector>> events = new ArrayList<>();
    // mutable boolean
    boolean[] swap = new boolean[1];
    ContinuousDetector detectorA = new ContinuousDetector(t1).withMaxCheck(maxCheck).withThreshold(tolerance).withHandler(new RecordAndContinue<EventDetector>(events) {

        @Override
        public Action eventOccurred(SpacecraftState s, EventDetector detector, boolean increasing) {
            swap[0] = true;
            return super.eventOccurred(s, detector, increasing);
        }
    });
    ContinuousDetector detectorB = new ContinuousDetector(t2);
    EventDetector detectorC = new AbstractDetector<EventDetector>(maxCheck, tolerance, 100, new RecordAndContinue<>(events)) {

        private static final long serialVersionUID = 1L;

        @Override
        public double g(SpacecraftState state) throws OrekitException {
            if (swap[0]) {
                return detectorB.g(state);
            } else {
                return 1;
            }
        }

        @Override
        protected EventDetector create(double newMaxCheck, double newThreshold, int newMaxIter, EventHandler<? super EventDetector> newHandler) {
            return null;
        }
    };
    Propagator propagator = getPropagator(10);
    propagator.addEventDetector(detectorA);
    propagator.addEventDetector(detectorC);
    // 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(true, events.get(1).isIncreasing());
    Assert.assertSame(detectorC, events.get(1).getDetector());
}
Also used : Action(org.orekit.propagation.events.handlers.EventHandler.Action) ArrayList(java.util.ArrayList) EventHandler(org.orekit.propagation.events.handlers.EventHandler) 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) Test(org.junit.Test)

Example 24 with Event

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

the class RecordAndContinueTest method testGetEvents.

/**
 * check add and clear behavior.
 *
 * @throws OrekitException on error.
 */
@Test
public void testGetEvents() throws OrekitException {
    // setup
    RecordAndContinue<DateDetector> handler = new RecordAndContinue<DateDetector>();
    AbsoluteDate date = AbsoluteDate.J2000_EPOCH;
    DateDetector detector = new DateDetector(date);
    Frame eci = FramesFactory.getGCRF();
    Orbit orbit = new KeplerianOrbit(6378137 + 500e3, 0, 0, 0, 0, 0, PositionAngle.TRUE, eci, date, Constants.EIGEN5C_EARTH_MU);
    SpacecraftState s1 = new SpacecraftState(orbit);
    SpacecraftState s2 = s1.shiftedBy(-10);
    SpacecraftState s3 = s2.shiftedBy(1);
    SpacecraftState s4 = s3.shiftedBy(1);
    // actions
    Assert.assertEquals(Action.CONTINUE, handler.eventOccurred(s1, detector, true));
    Assert.assertEquals(Action.CONTINUE, handler.eventOccurred(s2, detector, true));
    Assert.assertEquals(Action.CONTINUE, handler.eventOccurred(s3, detector, false));
    // verify
    List<Event<DateDetector>> events = handler.getEvents();
    Assert.assertEquals(3, events.size());
    Assert.assertEquals(s1, events.get(0).getState());
    Assert.assertEquals(s2, events.get(1).getState());
    Assert.assertEquals(s3, events.get(2).getState());
    Assert.assertEquals(true, events.get(0).isIncreasing());
    Assert.assertEquals(true, events.get(1).isIncreasing());
    Assert.assertEquals(false, events.get(2).isIncreasing());
    for (Event<DateDetector> event : events) {
        Assert.assertEquals(detector, event.getDetector());
    }
    // action: clear
    handler.clear();
    // verify is empty
    Assert.assertEquals(0, handler.getEvents().size());
    // action add more
    Assert.assertEquals(Action.CONTINUE, handler.eventOccurred(s4, detector, false));
    // verify new events
    events = handler.getEvents();
    Assert.assertEquals(1, events.size());
    Assert.assertEquals(s4, events.get(0).getState());
    Assert.assertEquals(false, events.get(0).isIncreasing());
    Assert.assertEquals(detector, events.get(0).getDetector());
}
Also used : DateDetector(org.orekit.propagation.events.DateDetector) SpacecraftState(org.orekit.propagation.SpacecraftState) Frame(org.orekit.frames.Frame) KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) Orbit(org.orekit.orbits.Orbit) Event(org.orekit.propagation.events.handlers.RecordAndContinue.Event) KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) AbsoluteDate(org.orekit.time.AbsoluteDate) Test(org.junit.Test)

Example 25 with Event

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

the class CloseEventsAbstractTest method testDoubleRootReverse.

/**
 * Check when g(t) has a multiple root. e.g. g(t < root) < 0, g(root) = 0, g(t > root)
 * < 0.
 */
@Test
public void testDoubleRootReverse() 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.0));
    // 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);
}
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