use of org.orekit.propagation.sampling.OrekitStepHandler in project Orekit by CS-SI.
the class MarshallSolarActivityFutureEstimationTest method testWithPropagator.
/**
* Check integration error is small when integrating the same equations over the same
* interval.
*
* @throws OrekitException on error.
*/
@Test
public void testWithPropagator() throws OrekitException {
CelestialBody sun = CelestialBodyFactory.getSun();
final Frame eci = FramesFactory.getGCRF();
final Frame ecef = FramesFactory.getITRF(IERSConventions.IERS_2010, true);
AbsoluteDate date = new AbsoluteDate(2004, 1, 1, utc);
OneAxisEllipsoid earth = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS, Constants.WGS84_EARTH_FLATTENING, ecef);
Orbit orbit = new KeplerianOrbit(6378137 + 400e3, 1e-3, FastMath.toRadians(50), 0, 0, 0, PositionAngle.TRUE, eci, date, Constants.EIGEN5C_EARTH_MU);
final SpacecraftState ic = new SpacecraftState(orbit);
final AbsoluteDate end = date.shiftedBy(5 * Constants.JULIAN_DAY);
final AbsoluteDate resetDate = date.shiftedBy(0.8 * Constants.JULIAN_DAY + 0.1);
final SpacecraftState[] lastState = new SpacecraftState[1];
final OrekitStepHandler stepSaver = (interpolator, isLast) -> {
final AbsoluteDate start = interpolator.getPreviousState().getDate();
if (start.compareTo(resetDate) < 0) {
lastState[0] = interpolator.getPreviousState();
}
};
// propagate with state rest to take slightly different path
NumericalPropagator propagator = getNumericalPropagator(sun, earth, ic);
propagator.setMasterMode(stepSaver);
propagator.propagate(resetDate);
propagator.resetInitialState(lastState[0]);
propagator.setSlaveMode();
final SpacecraftState actual = propagator.propagate(end);
// propagate straight through
propagator = getNumericalPropagator(sun, earth, ic);
propagator.resetInitialState(ic);
propagator.setSlaveMode();
final SpacecraftState expected = propagator.propagate(end);
assertThat(actual.getPVCoordinates(), pvCloseTo(expected.getPVCoordinates(), 1.0));
}
use of org.orekit.propagation.sampling.OrekitStepHandler in project Orekit by CS-SI.
the class AbstractForceModelTest method checkStateJacobian.
protected void checkStateJacobian(NumericalPropagator propagator, SpacecraftState state0, AbsoluteDate targetDate, double hFactor, double[] integratorAbsoluteTolerances, double checkTolerance) throws OrekitException {
propagator.setInitialState(state0);
double[][] reference = new double[][] { jacobianColumn(propagator, state0, targetDate, 0, hFactor * integratorAbsoluteTolerances[0]), jacobianColumn(propagator, state0, targetDate, 1, hFactor * integratorAbsoluteTolerances[1]), jacobianColumn(propagator, state0, targetDate, 2, hFactor * integratorAbsoluteTolerances[2]), jacobianColumn(propagator, state0, targetDate, 3, hFactor * integratorAbsoluteTolerances[3]), jacobianColumn(propagator, state0, targetDate, 4, hFactor * integratorAbsoluteTolerances[4]), jacobianColumn(propagator, state0, targetDate, 5, hFactor * integratorAbsoluteTolerances[5]) };
for (int j = 0; j < 6; ++j) {
for (int k = j + 1; k < 6; ++k) {
double tmp = reference[j][k];
reference[j][k] = reference[k][j];
reference[k][j] = tmp;
}
}
final String name = "pde";
PartialDerivativesEquations pde = new PartialDerivativesEquations(name, propagator);
propagator.setInitialState(pde.setInitialJacobians(state0));
final JacobiansMapper mapper = pde.getMapper();
final double[][] dYdY0 = new double[6][6];
propagator.setMasterMode(new OrekitStepHandler() {
public void handleStep(OrekitStepInterpolator interpolator, boolean isLast) throws OrekitException {
if (isLast) {
// pick up final Jacobian
mapper.getStateJacobian(interpolator.getCurrentState(), dYdY0);
}
}
});
propagator.propagate(targetDate);
for (int j = 0; j < 6; ++j) {
for (int k = 0; k < 6; ++k) {
double scale = integratorAbsoluteTolerances[j] / integratorAbsoluteTolerances[k];
Assert.assertEquals(reference[j][k], dYdY0[j][k], checkTolerance * scale);
}
}
}
use of org.orekit.propagation.sampling.OrekitStepHandler in project Orekit by CS-SI.
the class NumericalPropagatorTest method testException.
@Test(expected = OrekitException.class)
public void testException() throws OrekitException {
propagator.setMasterMode(new OrekitStepHandler() {
private int countDown = 3;
private AbsoluteDate previousCall = null;
public void init(SpacecraftState s0, AbsoluteDate t) {
}
public void handleStep(OrekitStepInterpolator interpolator, boolean isLast) throws OrekitException {
if (previousCall != null) {
Assert.assertTrue(interpolator.getCurrentState().getDate().compareTo(previousCall) < 0);
}
if (--countDown == 0) {
throw new OrekitException(LocalizedCoreFormats.SIMPLE_MESSAGE, "dummy error");
}
}
});
propagator.propagate(initDate.shiftedBy(-3600));
}
use of org.orekit.propagation.sampling.OrekitStepHandler in project Orekit by CS-SI.
the class IntegratedEphemerisTest method testPartialDerivativesIssue16.
@Test
public void testPartialDerivativesIssue16() throws OrekitException {
final String eqName = "derivatives";
numericalPropagator.setEphemerisMode();
numericalPropagator.setOrbitType(OrbitType.CARTESIAN);
final PartialDerivativesEquations derivatives = new PartialDerivativesEquations(eqName, numericalPropagator);
final SpacecraftState initialState = derivatives.setInitialJacobians(new SpacecraftState(initialOrbit));
final JacobiansMapper mapper = derivatives.getMapper();
numericalPropagator.setInitialState(initialState);
numericalPropagator.propagate(initialOrbit.getDate().shiftedBy(3600.0));
BoundedPropagator ephemeris = numericalPropagator.getGeneratedEphemeris();
ephemeris.setMasterMode(new OrekitStepHandler() {
private final Array2DRowRealMatrix dYdY0 = new Array2DRowRealMatrix(6, 6);
public void handleStep(OrekitStepInterpolator interpolator, boolean isLast) throws OrekitException {
SpacecraftState state = interpolator.getCurrentState();
Assert.assertEquals(mapper.getAdditionalStateDimension(), state.getAdditionalState(eqName).length);
mapper.getStateJacobian(state, dYdY0.getDataRef());
// no parameters, this is a no-op and should work
mapper.getParametersJacobian(state, null);
RealMatrix deltaId = dYdY0.subtract(MatrixUtils.createRealIdentityMatrix(6));
Assert.assertTrue(deltaId.getNorm() > 100);
Assert.assertTrue(deltaId.getNorm() < 3100);
}
});
ephemeris.propagate(initialOrbit.getDate().shiftedBy(1800.0));
}
use of org.orekit.propagation.sampling.OrekitStepHandler in project Orekit by CS-SI.
the class KeplerianPropagatorTest method testStepException.
@Test(expected = OrekitException.class)
public void testStepException() throws OrekitException {
final KeplerianOrbit orbit = new KeplerianOrbit(7.8e6, 0.032, 0.4, 0.1, 0.2, 0.3, PositionAngle.TRUE, FramesFactory.getEME2000(), AbsoluteDate.J2000_EPOCH, 3.986004415e14);
KeplerianPropagator propagator = new KeplerianPropagator(orbit);
OrekitStepHandlerMultiplexer multiplexer = new OrekitStepHandlerMultiplexer();
propagator.setMasterMode(multiplexer);
multiplexer.add(new OrekitStepHandler() {
public void init(SpacecraftState s0, AbsoluteDate t) {
}
public void handleStep(OrekitStepInterpolator interpolator, boolean isLast) throws OrekitException {
if (isLast) {
throw new OrekitException((Throwable) null, new DummyLocalizable("dummy error"));
}
}
});
propagator.propagate(orbit.getDate().shiftedBy(-3600));
}
Aggregations