Search in sources :

Example 1 with JacobiansMapper

use of org.orekit.propagation.numerical.JacobiansMapper 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 2 with JacobiansMapper

use of org.orekit.propagation.numerical.JacobiansMapper 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 JacobiansMapper

use of org.orekit.propagation.numerical.JacobiansMapper 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)

Aggregations

OrekitException (org.orekit.errors.OrekitException)3 JacobiansMapper (org.orekit.propagation.numerical.JacobiansMapper)3 PartialDerivativesEquations (org.orekit.propagation.numerical.PartialDerivativesEquations)3 RealMatrix (org.hipparchus.linear.RealMatrix)2 SpacecraftState (org.orekit.propagation.SpacecraftState)2 OrekitStepHandler (org.orekit.propagation.sampling.OrekitStepHandler)2 OrekitStepInterpolator (org.orekit.propagation.sampling.OrekitStepInterpolator)2 Array2DRowRealMatrix (org.hipparchus.linear.Array2DRowRealMatrix)1 ArrayRealVector (org.hipparchus.linear.ArrayRealVector)1 RealVector (org.hipparchus.linear.RealVector)1 MultivariateJacobianFunction (org.hipparchus.optim.nonlinear.vector.leastsquares.MultivariateJacobianFunction)1 Pair (org.hipparchus.util.Pair)1 Test (org.junit.Test)1 OrekitExceptionWrapper (org.orekit.errors.OrekitExceptionWrapper)1 BoundedPropagator (org.orekit.propagation.BoundedPropagator)1 DateDetector (org.orekit.propagation.events.DateDetector)1 EventHandler (org.orekit.propagation.events.handlers.EventHandler)1 NumericalPropagator (org.orekit.propagation.numerical.NumericalPropagator)1 ParameterDriversList (org.orekit.utils.ParameterDriversList)1