use of org.orekit.propagation.events.handlers.RecordAndContinue.Event in project Orekit by CS-SI.
the class CloseEventsAbstractTest method testEventChangesGFunctionDefinition.
/**
* 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 testEventChangesGFunctionDefinition() 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];
final ContinuousDetector detectorA = new ContinuousDetector(t1).withThreshold(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 s) throws OrekitException {
if (swap[0]) {
return detectorB.g(s);
} 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));
// 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());
}
use of org.orekit.propagation.events.handlers.RecordAndContinue.Event in project Orekit by CS-SI.
the class CloseEventsAbstractTest method testRootPlusToleranceHasWrongSignAndLessThanTbReverse.
/**
* check when g(t < root) < 0, g(root + convergence) < 0.
*/
@Test
public void testRootPlusToleranceHasWrongSignAndLessThanTbReverse() 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.0));
// verify
// allowed to report 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());
}
use of org.orekit.propagation.events.handlers.RecordAndContinue.Event in project Orekit by CS-SI.
the class CloseEventsAbstractTest method testFastSwitchingReverse.
/**
* 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 testFastSwitchingReverse() throws OrekitException {
// setup
// step size of 10 to land in between two events we would otherwise miss
Propagator propagator = getPropagator(10);
List<Event<EventDetector>> events = new ArrayList<>();
TimeDetector detector1 = new TimeDetector(-9.9, -10.1, -12).withHandler(new RecordAndContinue<>(events)).withMaxCheck(10).withThreshold(0.2);
propagator.addEventDetector(detector1);
// action
propagator.propagate(epoch.shiftedBy(-20));
// verify
// finds one or three events. Not 2.
Assert.assertEquals(1, events.size());
Assert.assertEquals(-9.9, events.get(0).getState().getDate().durationFrom(epoch), 0.2);
Assert.assertEquals(true, events.get(0).isIncreasing());
}
use of org.orekit.propagation.events.handlers.RecordAndContinue.Event in project Orekit by CS-SI.
the class CloseEventsAbstractTest method testConvergenceTooTightReverse.
/**
* check when t + tolerance == t.
*/
@Test
public void testConvergenceTooTightReverse() throws OrekitException {
// setup
double maxCheck = 10;
double tolerance = 1e-18;
double t1 = -15;
// shared event list so we know the order in which they occurred
List<Event<EventDetector>> events = new ArrayList<>();
ContinuousDetector detectorA = new ContinuousDetector(t1).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(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());
}
use of org.orekit.propagation.events.handlers.RecordAndContinue.Event in project Orekit by CS-SI.
the class CloseEventsAbstractTest method testRootFindingTolerance.
/**
* Test case for two event detectors. DetectorA has event at t2, DetectorB at t3, but
* due to the root finding tolerance DetectorB's event occurs at t1. With t1 < t2 <
* t3.
*/
@Test
public void testRootFindingTolerance() throws OrekitException {
// setup
double maxCheck = 10;
double t2 = 11, t3 = t2 + 1e-5;
List<Event<EventDetector>> events = new ArrayList<>();
TimeDetector detectorA = new TimeDetector(t2).withHandler(new RecordAndContinue<>(events)).withMaxCheck(maxCheck).withThreshold(1e-6);
FlatDetector detectorB = new FlatDetector(t3).withHandler(new RecordAndContinue<>(events)).withMaxCheck(maxCheck).withThreshold(0.5);
Propagator propagator = getPropagator(10);
propagator.addEventDetector(detectorA);
propagator.addEventDetector(detectorB);
// action
propagator.propagate(epoch.shiftedBy(30));
// verify
// if these fail the event finding did its job,
// but this test isn't testing what it is supposed to be
Assert.assertSame(detectorB, events.get(0).getDetector());
Assert.assertSame(detectorA, events.get(1).getDetector());
Assert.assertTrue(events.get(0).getState().getDate().compareTo(events.get(1).getState().getDate()) < 0);
// check event detection worked
Assert.assertEquals(2, events.size());
Assert.assertEquals(t3, events.get(0).getState().getDate().durationFrom(epoch), 0.5);
Assert.assertEquals(true, events.get(0).isIncreasing());
Assert.assertEquals(t2, events.get(1).getState().getDate().durationFrom(epoch), 1e-6);
Assert.assertEquals(true, events.get(1).isIncreasing());
}
Aggregations