Search in sources :

Example 11 with DateDetector

use of org.orekit.propagation.events.DateDetector in project Orekit by CS-SI.

the class JacobianPropagatorConverter method getModel.

/**
 * {@inheritDoc}
 */
protected MultivariateJacobianFunction getModel() {
    return new MultivariateJacobianFunction() {

        /**
         * {@inheritDoc}
         */
        public Pair<RealVector, RealMatrix> value(final RealVector point) throws IllegalArgumentException, OrekitExceptionWrapper {
            try {
                final RealVector value = new ArrayRealVector(getTargetSize());
                final RealMatrix jacobian = MatrixUtils.createRealMatrix(getTargetSize(), point.getDimension());
                final NumericalPropagator prop = builder.buildPropagator(point.toArray());
                final int stateSize = isOnlyPosition() ? 3 : 6;
                final ParameterDriversList orbitalParameters = builder.getOrbitalParametersDrivers();
                final PartialDerivativesEquations pde = new PartialDerivativesEquations("pde", prop);
                final ParameterDriversList propagationParameters = pde.getSelectedParameters();
                prop.setInitialState(pde.setInitialJacobians(prop.getInitialState()));
                final JacobiansMapper mapper = pde.getMapper();
                final List<SpacecraftState> sample = getSample();
                for (int i = 0; i < sample.size(); ++i) {
                    final int row = i * stateSize;
                    if (prop.getInitialState().getDate().equals(sample.get(i).getDate())) {
                        // use initial state and Jacobians
                        fillRows(value, jacobian, row, prop.getInitialState(), stateSize, orbitalParameters, propagationParameters, mapper);
                    } else {
                        // use a date detector to pick up state and Jacobians
                        prop.addEventDetector(new DateDetector(sample.get(i).getDate()).withHandler(new EventHandler<DateDetector>() {

                            /**
                             * {@inheritDoc}
                             */
                            @Override
                            public Action eventOccurred(final SpacecraftState state, final DateDetector detector, final boolean increasing) throws OrekitException {
                                fillRows(value, jacobian, row, state, stateSize, orbitalParameters, propagationParameters, mapper);
                                return row + stateSize >= getTargetSize() ? Action.STOP : Action.CONTINUE;
                            }
                        }));
                    }
                }
                prop.propagate(sample.get(sample.size() - 1).getDate().shiftedBy(10.0));
                return new Pair<RealVector, RealMatrix>(value, jacobian);
            } catch (OrekitException ex) {
                throw new OrekitExceptionWrapper(ex);
            }
        }
    };
}
Also used : DateDetector(org.orekit.propagation.events.DateDetector) OrekitExceptionWrapper(org.orekit.errors.OrekitExceptionWrapper) ArrayRealVector(org.hipparchus.linear.ArrayRealVector) EventHandler(org.orekit.propagation.events.handlers.EventHandler) MultivariateJacobianFunction(org.hipparchus.optim.nonlinear.vector.leastsquares.MultivariateJacobianFunction) SpacecraftState(org.orekit.propagation.SpacecraftState) RealMatrix(org.hipparchus.linear.RealMatrix) NumericalPropagator(org.orekit.propagation.numerical.NumericalPropagator) ParameterDriversList(org.orekit.utils.ParameterDriversList) PartialDerivativesEquations(org.orekit.propagation.numerical.PartialDerivativesEquations) ArrayRealVector(org.hipparchus.linear.ArrayRealVector) RealVector(org.hipparchus.linear.RealVector) OrekitException(org.orekit.errors.OrekitException) JacobiansMapper(org.orekit.propagation.numerical.JacobiansMapper) Pair(org.hipparchus.util.Pair)

Example 12 with DateDetector

use of org.orekit.propagation.events.DateDetector in project Orekit by CS-SI.

the class ImpulseManeuverTest method testBackward.

@Test
public void testBackward() throws OrekitException {
    final AbsoluteDate iniDate = new AbsoluteDate(2003, 5, 1, 17, 30, 0.0, TimeScalesFactory.getUTC());
    final Orbit initialOrbit = new KeplerianOrbit(7e6, 1.0e-4, FastMath.toRadians(98.5), FastMath.toRadians(87.0), FastMath.toRadians(216.1807), FastMath.toRadians(319.779), PositionAngle.MEAN, FramesFactory.getEME2000(), iniDate, Constants.EIGEN5C_EARTH_MU);
    KeplerianPropagator propagator = new KeplerianPropagator(initialOrbit, new LofOffset(initialOrbit.getFrame(), LOFType.VNC));
    DateDetector dateDetector = new DateDetector(iniDate.shiftedBy(-300));
    Vector3D deltaV = new Vector3D(12.0, 1.0, -4.0);
    final double isp = 300;
    ImpulseManeuver<DateDetector> maneuver = new ImpulseManeuver<DateDetector>(dateDetector, deltaV, isp).withMaxCheck(3600.0).withThreshold(1.0e-6);
    propagator.addEventDetector(maneuver);
    SpacecraftState finalState = propagator.propagate(initialOrbit.getDate().shiftedBy(-900));
    Assert.assertTrue(finalState.getMass() > propagator.getInitialState().getMass());
    Assert.assertTrue(finalState.getDate().compareTo(propagator.getInitialState().getDate()) < 0);
}
Also used : KeplerianPropagator(org.orekit.propagation.analytical.KeplerianPropagator) DateDetector(org.orekit.propagation.events.DateDetector) SpacecraftState(org.orekit.propagation.SpacecraftState) Orbit(org.orekit.orbits.Orbit) CartesianOrbit(org.orekit.orbits.CartesianOrbit) KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) LofOffset(org.orekit.attitudes.LofOffset) AbsoluteDate(org.orekit.time.AbsoluteDate) Test(org.junit.Test)

Example 13 with DateDetector

use of org.orekit.propagation.events.DateDetector in project Orekit by CS-SI.

the class PropagatorsParallelizerTest method testStopOnLateEvent.

@Test
public void testStopOnLateEvent() throws OrekitException {
    final AbsoluteDate startDate = orbit.getDate();
    final AbsoluteDate endDate = startDate.shiftedBy(3600.0);
    final AbsoluteDate stopDate = startDate.shiftedBy(900.0);
    List<Propagator> propagators = Arrays.asList(buildEcksteinHechler(), buildNumerical());
    propagators.get(0).addEventDetector(new DateDetector(stopDate).withHandler(new StopOnEvent<>()));
    List<SpacecraftState> results = new PropagatorsParallelizer(propagators, (interpolators, isLast) -> {
    }).propagate(startDate, endDate);
    Assert.assertEquals(2, results.size());
    Assert.assertEquals(0.0, results.get(0).getDate().durationFrom(stopDate), 1.0e-15);
    Assert.assertEquals(0.0, results.get(1).getDate().durationFrom(stopDate), 1.0e-15);
}
Also used : DateDetector(org.orekit.propagation.events.DateDetector) DormandPrince853Integrator(org.hipparchus.ode.nonstiff.DormandPrince853Integrator) Arrays(java.util.Arrays) ForceModel(org.orekit.forces.ForceModel) AttitudeProvider(org.orekit.attitudes.AttitudeProvider) IERSConventions(org.orekit.utils.IERSConventions) Orbit(org.orekit.orbits.Orbit) NormalizedSphericalHarmonicsProvider(org.orekit.forces.gravity.potential.NormalizedSphericalHarmonicsProvider) BodyCenterPointing(org.orekit.attitudes.BodyCenterPointing) ODEIntegrator(org.hipparchus.ode.ODEIntegrator) After(org.junit.After) StopOnEvent(org.orekit.propagation.events.handlers.StopOnEvent) OrbitType(org.orekit.orbits.OrbitType) PositionAngle(org.orekit.orbits.PositionAngle) DateDetector(org.orekit.propagation.events.DateDetector) FastMath(org.hipparchus.util.FastMath) EcksteinHechlerPropagator(org.orekit.propagation.analytical.EcksteinHechlerPropagator) Utils(org.orekit.Utils) Before(org.junit.Before) Constants(org.orekit.utils.Constants) DateComponents(org.orekit.time.DateComponents) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) FramesFactory(org.orekit.frames.FramesFactory) KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) Test(org.junit.Test) GravityFieldFactory(org.orekit.forces.gravity.potential.GravityFieldFactory) OrekitMessages(org.orekit.errors.OrekitMessages) List(java.util.List) OneAxisEllipsoid(org.orekit.bodies.OneAxisEllipsoid) OrekitException(org.orekit.errors.OrekitException) NumericalPropagator(org.orekit.propagation.numerical.NumericalPropagator) TimeScalesFactory(org.orekit.time.TimeScalesFactory) LocalizedCoreFormats(org.hipparchus.exception.LocalizedCoreFormats) TimeComponents(org.orekit.time.TimeComponents) Assert(org.junit.Assert) HolmesFeatherstoneAttractionModel(org.orekit.forces.gravity.HolmesFeatherstoneAttractionModel) UnnormalizedSphericalHarmonicsProvider(org.orekit.forces.gravity.potential.UnnormalizedSphericalHarmonicsProvider) AbsoluteDate(org.orekit.time.AbsoluteDate) EcksteinHechlerPropagator(org.orekit.propagation.analytical.EcksteinHechlerPropagator) NumericalPropagator(org.orekit.propagation.numerical.NumericalPropagator) StopOnEvent(org.orekit.propagation.events.handlers.StopOnEvent) AbsoluteDate(org.orekit.time.AbsoluteDate) Test(org.junit.Test)

Example 14 with DateDetector

use of org.orekit.propagation.events.DateDetector in project Orekit by CS-SI.

the class PropagatorsParallelizerTest method testEarlyStop.

@Test
public void testEarlyStop() throws OrekitException {
    final AbsoluteDate startDate = orbit.getDate();
    final AbsoluteDate endDate = startDate.shiftedBy(3600.0);
    List<Propagator> propagators = Arrays.asList(buildEcksteinHechler(), buildNumerical());
    propagators.get(0).addEventDetector(new DateDetector(startDate.shiftedBy(900.0)).withHandler((state, detector, increasing) -> {
        throw new RuntimeException("boo!");
    }));
    try {
        new PropagatorsParallelizer(propagators, (interpolators, isLast) -> {
        }).propagate(startDate, endDate);
        Assert.fail("an exception should have been thrown");
    } catch (OrekitException oe) {
        Assert.assertNotNull(oe.getCause());
        Assert.assertTrue(oe.getCause() instanceof RuntimeException);
        Assert.assertEquals(LocalizedCoreFormats.SIMPLE_MESSAGE, oe.getSpecifier());
        Assert.assertTrue(((String) oe.getParts()[0]).endsWith("boo!"));
    }
}
Also used : DateDetector(org.orekit.propagation.events.DateDetector) DormandPrince853Integrator(org.hipparchus.ode.nonstiff.DormandPrince853Integrator) Arrays(java.util.Arrays) ForceModel(org.orekit.forces.ForceModel) AttitudeProvider(org.orekit.attitudes.AttitudeProvider) IERSConventions(org.orekit.utils.IERSConventions) Orbit(org.orekit.orbits.Orbit) NormalizedSphericalHarmonicsProvider(org.orekit.forces.gravity.potential.NormalizedSphericalHarmonicsProvider) BodyCenterPointing(org.orekit.attitudes.BodyCenterPointing) ODEIntegrator(org.hipparchus.ode.ODEIntegrator) After(org.junit.After) StopOnEvent(org.orekit.propagation.events.handlers.StopOnEvent) OrbitType(org.orekit.orbits.OrbitType) PositionAngle(org.orekit.orbits.PositionAngle) DateDetector(org.orekit.propagation.events.DateDetector) FastMath(org.hipparchus.util.FastMath) EcksteinHechlerPropagator(org.orekit.propagation.analytical.EcksteinHechlerPropagator) Utils(org.orekit.Utils) Before(org.junit.Before) Constants(org.orekit.utils.Constants) DateComponents(org.orekit.time.DateComponents) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) FramesFactory(org.orekit.frames.FramesFactory) KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) Test(org.junit.Test) GravityFieldFactory(org.orekit.forces.gravity.potential.GravityFieldFactory) OrekitMessages(org.orekit.errors.OrekitMessages) List(java.util.List) OneAxisEllipsoid(org.orekit.bodies.OneAxisEllipsoid) OrekitException(org.orekit.errors.OrekitException) NumericalPropagator(org.orekit.propagation.numerical.NumericalPropagator) TimeScalesFactory(org.orekit.time.TimeScalesFactory) LocalizedCoreFormats(org.hipparchus.exception.LocalizedCoreFormats) TimeComponents(org.orekit.time.TimeComponents) Assert(org.junit.Assert) HolmesFeatherstoneAttractionModel(org.orekit.forces.gravity.HolmesFeatherstoneAttractionModel) UnnormalizedSphericalHarmonicsProvider(org.orekit.forces.gravity.potential.UnnormalizedSphericalHarmonicsProvider) AbsoluteDate(org.orekit.time.AbsoluteDate) EcksteinHechlerPropagator(org.orekit.propagation.analytical.EcksteinHechlerPropagator) NumericalPropagator(org.orekit.propagation.numerical.NumericalPropagator) OrekitException(org.orekit.errors.OrekitException) AbsoluteDate(org.orekit.time.AbsoluteDate) Test(org.junit.Test)

Example 15 with DateDetector

use of org.orekit.propagation.events.DateDetector in project Orekit by CS-SI.

the class KeplerianPropagatorTest method date.

@Test
public void date() 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);
    final AbsoluteDate stopDate = AbsoluteDate.J2000_EPOCH.shiftedBy(500.0);
    propagator.addEventDetector(new DateDetector(stopDate));
    AbsoluteDate farTarget = AbsoluteDate.J2000_EPOCH.shiftedBy(10000.0);
    SpacecraftState propagated = propagator.propagate(farTarget);
    Assert.assertEquals(0, stopDate.durationFrom(propagated.getDate()), 1.0e-10);
}
Also used : DateDetector(org.orekit.propagation.events.DateDetector) SpacecraftState(org.orekit.propagation.SpacecraftState) KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) FieldAbsoluteDate(org.orekit.time.FieldAbsoluteDate) AbsoluteDate(org.orekit.time.AbsoluteDate) Test(org.junit.Test)

Aggregations

DateDetector (org.orekit.propagation.events.DateDetector)31 Test (org.junit.Test)27 AbsoluteDate (org.orekit.time.AbsoluteDate)27 SpacecraftState (org.orekit.propagation.SpacecraftState)25 KeplerianOrbit (org.orekit.orbits.KeplerianOrbit)15 Vector3D (org.hipparchus.geometry.euclidean.threed.Vector3D)13 Orbit (org.orekit.orbits.Orbit)12 FieldSpacecraftState (org.orekit.propagation.FieldSpacecraftState)9 NumericalPropagator (org.orekit.propagation.numerical.NumericalPropagator)9 LofOffset (org.orekit.attitudes.LofOffset)8 AttitudeProvider (org.orekit.attitudes.AttitudeProvider)7 OrekitException (org.orekit.errors.OrekitException)7 CartesianOrbit (org.orekit.orbits.CartesianOrbit)6 FieldAbsoluteDate (org.orekit.time.FieldAbsoluteDate)6 Rotation (org.hipparchus.geometry.euclidean.threed.Rotation)5 DormandPrince853Integrator (org.hipparchus.ode.nonstiff.DormandPrince853Integrator)5 Frame (org.orekit.frames.Frame)5 Arrays (java.util.Arrays)4 List (java.util.List)4 LocalizedCoreFormats (org.hipparchus.exception.LocalizedCoreFormats)4