use of org.orekit.propagation.Propagator in project Orekit by CS-SI.
the class CloseEventsAbstractTest method testRootFindingToleranceReverse.
/**
* 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 testRootFindingToleranceReverse() 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.0));
// 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());
}
use of org.orekit.propagation.Propagator in project Orekit by CS-SI.
the class CloseEventsAbstractTest method testRootPlusToleranceHasWrongSign.
/**
* check when g(t < root) < 0, g(root + convergence) < 0.
*/
@Test
public void testRootPlusToleranceHasWrongSign() 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(1e-6);
TimeDetector detectorB = new TimeDetector(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));
// verify
// we only care that the rules are satisfied, there are other 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());
// chronological
for (int i = 1; i < events.size(); i++) {
Assert.assertTrue(events.get(i).getState().getDate().compareTo(events.get(i - 1).getState().getDate()) >= 0);
}
}
use of org.orekit.propagation.Propagator in project Orekit by CS-SI.
the class CloseEventsAbstractTest method testMultipleBackups.
/**
* Test where an event detector has to back up multiple times.
*/
@Test
public void testMultipleBackups() throws OrekitException {
// setup
double maxCheck = 10;
double tolerance = 1e-6;
double t1 = 1.0, t2 = 2, t3 = 3, t4 = 4, t5 = 5, t6 = 6.5, t7 = 7;
// shared event list so we know the order in which they occurred
List<Event<EventDetector>> events = new ArrayList<>();
ContinuousDetector detectorA = new ContinuousDetector(t6).withHandler(new RecordAndContinue<>(events)).withMaxCheck(maxCheck).withThreshold(tolerance);
FlatDetector detectorB = new FlatDetector(t1, t3, t4, t7).withHandler(new RecordAndContinue<>(events)).withMaxCheck(maxCheck).withThreshold(tolerance);
ContinuousDetector detectorC = new ContinuousDetector(t2, t5).withHandler(new RecordAndContinue<>(events)).withMaxCheck(maxCheck).withThreshold(tolerance);
Propagator propagator = getPropagator(10);
propagator.addEventDetector(detectorA);
propagator.addEventDetector(detectorB);
propagator.addEventDetector(detectorC);
// action
propagator.propagate(epoch.shiftedBy(30));
// verify
// need at least 5 events to check that multiple backups occurred
Assert.assertEquals(5, events.size());
Assert.assertEquals(t1, events.get(0).getState().getDate().durationFrom(epoch), tolerance);
Assert.assertEquals(true, events.get(0).isIncreasing());
Assert.assertEquals(detectorB, events.get(0).getDetector());
Assert.assertEquals(t2, events.get(1).getState().getDate().durationFrom(epoch), tolerance);
Assert.assertEquals(true, events.get(1).isIncreasing());
Assert.assertEquals(detectorC, events.get(1).getDetector());
// reporting t3 and t4 is optional, seeing them is not.
// we know a root was found at t3 because events are reported at t2 and t5.
/*
Assert.assertEquals(t3, events.get(2).getT(), tolerance);
Assert.assertEquals(false, events.get(2).isIncreasing());
Assert.assertEquals(detectorB, events.get(2).getHandler());
Assert.assertEquals(t4, events.get(3).getT(), tolerance);
Assert.assertEquals(true, events.get(3).isIncreasing());
Assert.assertEquals(detectorB, events.get(3).getHandler());
*/
Assert.assertEquals(t5, events.get(2).getState().getDate().durationFrom(epoch), tolerance);
Assert.assertEquals(false, events.get(2).isIncreasing());
Assert.assertEquals(detectorC, events.get(2).getDetector());
Assert.assertEquals(t6, events.get(3).getState().getDate().durationFrom(epoch), tolerance);
Assert.assertEquals(true, events.get(3).isIncreasing());
Assert.assertEquals(detectorA, events.get(3).getDetector());
Assert.assertEquals(t7, events.get(4).getState().getDate().durationFrom(epoch), tolerance);
Assert.assertEquals(false, events.get(4).isIncreasing());
Assert.assertEquals(detectorB, events.get(4).getDetector());
}
use of org.orekit.propagation.Propagator 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());
}
use of org.orekit.propagation.Propagator 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());
}
Aggregations