Search in sources :

Example 1 with OrekitStepHandler

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));
}
Also used : OrekitStepHandler(org.orekit.propagation.sampling.OrekitStepHandler) DTM2000InputParameters(org.orekit.forces.drag.atmosphere.DTM2000InputParameters) Frame(org.orekit.frames.Frame) TimeScale(org.orekit.time.TimeScale) DragForce(org.orekit.forces.drag.DragForce) IERSConventions(org.orekit.utils.IERSConventions) Orbit(org.orekit.orbits.Orbit) StrengthLevel(org.orekit.forces.drag.atmosphere.data.MarshallSolarActivityFutureEstimation.StrengthLevel) CelestialBody(org.orekit.bodies.CelestialBody) ODEIntegrator(org.hipparchus.ode.ODEIntegrator) SpacecraftState(org.orekit.propagation.SpacecraftState) After(org.junit.After) OrbitType(org.orekit.orbits.OrbitType) PositionAngle(org.orekit.orbits.PositionAngle) ClassicalRungeKuttaIntegrator(org.hipparchus.ode.nonstiff.ClassicalRungeKuttaIntegrator) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) FastMath(org.hipparchus.util.FastMath) Utils(org.orekit.Utils) Before(org.junit.Before) Constants(org.orekit.utils.Constants) DTM2000(org.orekit.forces.drag.atmosphere.DTM2000) DateComponents(org.orekit.time.DateComponents) FramesFactory(org.orekit.frames.FramesFactory) Atmosphere(org.orekit.forces.drag.atmosphere.Atmosphere) KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) OrekitMatchers(org.orekit.OrekitMatchers) Test(org.junit.Test) MarshallSolarActivityFutureEstimation(org.orekit.forces.drag.atmosphere.data.MarshallSolarActivityFutureEstimation) DataProvidersManager(org.orekit.data.DataProvidersManager) Month(org.orekit.time.Month) OneAxisEllipsoid(org.orekit.bodies.OneAxisEllipsoid) OrekitException(org.orekit.errors.OrekitException) CelestialBodyFactory(org.orekit.bodies.CelestialBodyFactory) NumericalPropagator(org.orekit.propagation.numerical.NumericalPropagator) TimeScalesFactory(org.orekit.time.TimeScalesFactory) IsotropicDrag(org.orekit.forces.drag.IsotropicDrag) Assert(org.junit.Assert) AbsoluteDate(org.orekit.time.AbsoluteDate) SpacecraftState(org.orekit.propagation.SpacecraftState) Frame(org.orekit.frames.Frame) OneAxisEllipsoid(org.orekit.bodies.OneAxisEllipsoid) Orbit(org.orekit.orbits.Orbit) KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) NumericalPropagator(org.orekit.propagation.numerical.NumericalPropagator) CelestialBody(org.orekit.bodies.CelestialBody) KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) AbsoluteDate(org.orekit.time.AbsoluteDate) OrekitStepHandler(org.orekit.propagation.sampling.OrekitStepHandler) Test(org.junit.Test)

Example 2 with OrekitStepHandler

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);
        }
    }
}
Also used : PartialDerivativesEquations(org.orekit.propagation.numerical.PartialDerivativesEquations) OrekitException(org.orekit.errors.OrekitException) JacobiansMapper(org.orekit.propagation.numerical.JacobiansMapper) OrekitStepHandler(org.orekit.propagation.sampling.OrekitStepHandler) OrekitStepInterpolator(org.orekit.propagation.sampling.OrekitStepInterpolator)

Example 3 with OrekitStepHandler

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));
}
Also used : SpacecraftState(org.orekit.propagation.SpacecraftState) FieldSpacecraftState(org.orekit.propagation.FieldSpacecraftState) OrekitException(org.orekit.errors.OrekitException) AbsoluteDate(org.orekit.time.AbsoluteDate) OrekitStepHandler(org.orekit.propagation.sampling.OrekitStepHandler) OrekitStepInterpolator(org.orekit.propagation.sampling.OrekitStepInterpolator) Test(org.junit.Test)

Example 4 with OrekitStepHandler

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));
}
Also used : SpacecraftState(org.orekit.propagation.SpacecraftState) Array2DRowRealMatrix(org.hipparchus.linear.Array2DRowRealMatrix) RealMatrix(org.hipparchus.linear.RealMatrix) Array2DRowRealMatrix(org.hipparchus.linear.Array2DRowRealMatrix) PartialDerivativesEquations(org.orekit.propagation.numerical.PartialDerivativesEquations) OrekitException(org.orekit.errors.OrekitException) JacobiansMapper(org.orekit.propagation.numerical.JacobiansMapper) BoundedPropagator(org.orekit.propagation.BoundedPropagator) OrekitStepHandler(org.orekit.propagation.sampling.OrekitStepHandler) OrekitStepInterpolator(org.orekit.propagation.sampling.OrekitStepInterpolator) Test(org.junit.Test)

Example 5 with OrekitStepHandler

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));
}
Also used : OrekitStepHandlerMultiplexer(org.orekit.propagation.sampling.OrekitStepHandlerMultiplexer) DummyLocalizable(org.hipparchus.exception.DummyLocalizable) SpacecraftState(org.orekit.propagation.SpacecraftState) KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) OrekitException(org.orekit.errors.OrekitException) FieldAbsoluteDate(org.orekit.time.FieldAbsoluteDate) AbsoluteDate(org.orekit.time.AbsoluteDate) OrekitStepHandler(org.orekit.propagation.sampling.OrekitStepHandler) OrekitStepInterpolator(org.orekit.propagation.sampling.OrekitStepInterpolator) Test(org.junit.Test)

Aggregations

OrekitException (org.orekit.errors.OrekitException)6 OrekitStepHandler (org.orekit.propagation.sampling.OrekitStepHandler)6 Test (org.junit.Test)5 OrekitStepInterpolator (org.orekit.propagation.sampling.OrekitStepInterpolator)5 SpacecraftState (org.orekit.propagation.SpacecraftState)4 AbsoluteDate (org.orekit.time.AbsoluteDate)4 KeplerianOrbit (org.orekit.orbits.KeplerianOrbit)3 JacobiansMapper (org.orekit.propagation.numerical.JacobiansMapper)2 PartialDerivativesEquations (org.orekit.propagation.numerical.PartialDerivativesEquations)2 FieldAbsoluteDate (org.orekit.time.FieldAbsoluteDate)2 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1 DummyLocalizable (org.hipparchus.exception.DummyLocalizable)1 Array2DRowRealMatrix (org.hipparchus.linear.Array2DRowRealMatrix)1 RealMatrix (org.hipparchus.linear.RealMatrix)1 ODEIntegrator (org.hipparchus.ode.ODEIntegrator)1 ClassicalRungeKuttaIntegrator (org.hipparchus.ode.nonstiff.ClassicalRungeKuttaIntegrator)1 FastMath (org.hipparchus.util.FastMath)1 After (org.junit.After)1 Assert (org.junit.Assert)1 Before (org.junit.Before)1