use of org.orekit.propagation.events.DateDetector in project Orekit by CS-SI.
the class ImpulseManeuverTest method testAdditionalStateKeplerian.
@Test
public void testAdditionalStateKeplerian() throws OrekitException {
final double mu = CelestialBodyFactory.getEarth().getGM();
final double initialX = 7100e3;
final double initialY = 0.0;
final double initialZ = 1300e3;
final double initialVx = 0;
final double initialVy = 8000;
final double initialVz = 1000;
final Vector3D position = new Vector3D(initialX, initialY, initialZ);
final Vector3D velocity = new Vector3D(initialVx, initialVy, initialVz);
final AbsoluteDate epoch = new AbsoluteDate(2010, 1, 1, 0, 0, 0, TimeScalesFactory.getUTC());
final TimeStampedPVCoordinates pv = new TimeStampedPVCoordinates(epoch, position, velocity, Vector3D.ZERO);
final Orbit initialOrbit = new CartesianOrbit(pv, FramesFactory.getEME2000(), mu);
final double totalPropagationTime = 10;
final double deltaX = 0.01;
final double deltaY = 0.02;
final double deltaZ = 0.03;
final double isp = 300;
final Vector3D deltaV = new Vector3D(deltaX, deltaY, deltaZ);
final AttitudeProvider attitudeProvider = new LofOffset(initialOrbit.getFrame(), LOFType.VNC);
final Attitude initialAttitude = attitudeProvider.getAttitude(initialOrbit, initialOrbit.getDate(), initialOrbit.getFrame());
final SpacecraftState initialState = new SpacecraftState(initialOrbit, initialAttitude);
KeplerianPropagator propagator = new KeplerianPropagator(initialOrbit);
propagator.resetInitialState(initialState.addAdditionalState("testOnly", -1.0));
DateDetector dateDetector = new DateDetector(epoch.shiftedBy(0.5 * totalPropagationTime));
InertialProvider attitudeOverride = new InertialProvider(new Rotation(RotationOrder.XYX, RotationConvention.VECTOR_OPERATOR, 0, 0, 0));
ImpulseManeuver<DateDetector> burnAtEpoch = new ImpulseManeuver<DateDetector>(dateDetector, attitudeOverride, deltaV, isp).withThreshold(1.0e-3);
propagator.addEventDetector(burnAtEpoch);
SpacecraftState finalState = propagator.propagate(epoch.shiftedBy(totalPropagationTime));
Assert.assertEquals(1, finalState.getAdditionalStates().size());
Assert.assertEquals(-1.0, finalState.getAdditionalState("testOnly")[0], 1.0e-15);
}
use of org.orekit.propagation.events.DateDetector in project Orekit by CS-SI.
the class NumericalPropagatorTest method testContinueEvent.
@Test
public void testContinueEvent() throws OrekitException {
final AbsoluteDate resetDate = initDate.shiftedBy(1000);
CheckingHandler<DateDetector> checking = new CheckingHandler<DateDetector>(Action.CONTINUE);
propagator.addEventDetector(new DateDetector(resetDate).withHandler(checking));
final double dt = 3200;
checking.assertEvent(false);
Assert.assertEquals(0.0, propagator.getInitialState().getDate().durationFrom(initDate), 1.0e-10);
propagator.setResetAtEnd(false);
final SpacecraftState finalState = propagator.propagate(initDate.shiftedBy(dt));
Assert.assertEquals(0.0, propagator.getInitialState().getDate().durationFrom(initDate), 1.0e-10);
checking.assertEvent(true);
final double n = FastMath.sqrt(initialState.getMu() / initialState.getA()) / initialState.getA();
Assert.assertEquals(initialState.getA(), finalState.getA(), 1.0e-10);
Assert.assertEquals(initialState.getEquinoctialEx(), finalState.getEquinoctialEx(), 1.0e-10);
Assert.assertEquals(initialState.getEquinoctialEy(), finalState.getEquinoctialEy(), 1.0e-10);
Assert.assertEquals(initialState.getHx(), finalState.getHx(), 1.0e-10);
Assert.assertEquals(initialState.getHy(), finalState.getHy(), 1.0e-10);
Assert.assertEquals(initialState.getLM() + n * dt, finalState.getLM(), 6.0e-10);
}
use of org.orekit.propagation.events.DateDetector in project Orekit by CS-SI.
the class NumericalPropagatorTest method testCloseEventDates.
/**
* check propagation succeeds when two events are within the tolerance of
* each other.
*/
@Test
public void testCloseEventDates() throws OrekitException {
// setup
DateDetector d1 = new DateDetector(10, 1, initDate.shiftedBy(15)).withHandler(new ContinueOnEvent<DateDetector>());
DateDetector d2 = new DateDetector(10, 1, initDate.shiftedBy(15.5)).withHandler(new ContinueOnEvent<DateDetector>());
propagator.addEventDetector(d1);
propagator.addEventDetector(d2);
// action
AbsoluteDate end = initDate.shiftedBy(30);
SpacecraftState actual = propagator.propagate(end);
// verify
Assert.assertEquals(actual.getDate().durationFrom(end), 0.0, 0.0);
}
use of org.orekit.propagation.events.DateDetector in project Orekit by CS-SI.
the class NumericalPropagatorTest method testResetDerivativesEvent.
@Test
public void testResetDerivativesEvent() throws OrekitException {
final AbsoluteDate resetDate = initDate.shiftedBy(1000);
CheckingHandler<DateDetector> checking = new CheckingHandler<DateDetector>(Action.RESET_DERIVATIVES);
propagator.addEventDetector(new DateDetector(resetDate).withHandler(checking));
final double dt = 3200;
checking.assertEvent(false);
Assert.assertEquals(0.0, propagator.getInitialState().getDate().durationFrom(initDate), 1.0e-10);
propagator.setResetAtEnd(true);
final SpacecraftState finalState = propagator.propagate(initDate.shiftedBy(dt));
Assert.assertEquals(dt, propagator.getInitialState().getDate().durationFrom(initDate), 1.0e-10);
checking.assertEvent(true);
final double n = FastMath.sqrt(initialState.getMu() / initialState.getA()) / initialState.getA();
Assert.assertEquals(initialState.getA(), finalState.getA(), 1.0e-10);
Assert.assertEquals(initialState.getEquinoctialEx(), finalState.getEquinoctialEx(), 1.0e-10);
Assert.assertEquals(initialState.getEquinoctialEy(), finalState.getEquinoctialEy(), 1.0e-10);
Assert.assertEquals(initialState.getHx(), finalState.getHx(), 1.0e-10);
Assert.assertEquals(initialState.getHy(), finalState.getHy(), 1.0e-10);
Assert.assertEquals(initialState.getLM() + n * dt, finalState.getLM(), 6.0e-10);
}
use of org.orekit.propagation.events.DateDetector 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());
}
Aggregations