Search in sources :

Example 71 with OrekitException

use of org.orekit.errors.OrekitException in project Orekit by CS-SI.

the class TransformGenerator method generate.

/**
 * {@inheritDoc}
 */
public List<Transform> generate(final AbsoluteDate existingDate, final AbsoluteDate date) {
    try {
        final List<Transform> generated = new ArrayList<>();
        if (existingDate == null) {
            // no prior existing transforms, just generate a first one
            for (int i = 0; i < neighborsSize; ++i) {
                generated.add(provider.getTransform(date.shiftedBy(i * step)));
            }
        } else {
            // some transforms have already been generated
            // add the missing ones up to specified date
            AbsoluteDate t = existingDate;
            if (date.compareTo(t) > 0) {
                // forward generation
                do {
                    t = t.shiftedBy(step);
                    generated.add(generated.size(), provider.getTransform(t));
                } while (t.compareTo(date) <= 0);
            } else {
                // backward generation
                do {
                    t = t.shiftedBy(-step);
                    generated.add(0, provider.getTransform(t));
                } while (t.compareTo(date) >= 0);
            }
        }
        // return the generated transforms
        return generated;
    } catch (OrekitException oe) {
        throw new OrekitExceptionWrapper(oe);
    }
}
Also used : OrekitExceptionWrapper(org.orekit.errors.OrekitExceptionWrapper) ArrayList(java.util.ArrayList) OrekitException(org.orekit.errors.OrekitException) AbsoluteDate(org.orekit.time.AbsoluteDate)

Example 72 with OrekitException

use of org.orekit.errors.OrekitException in project Orekit by CS-SI.

the class NumericalPropagator method tolerances.

/**
 * Estimate tolerance vectors for integrators.
 * <p>
 * The errors are estimated from partial derivatives properties of orbits,
 * starting from a scalar position error specified by the user.
 * Considering the energy conservation equation V = sqrt(mu (2/r - 1/a)),
 * we get at constant energy (i.e. on a Keplerian trajectory):
 * <pre>
 * V² r |dV| = mu |dr|
 * </pre>
 * <p> So we deduce a scalar velocity error consistent with the position error.
 * From here, we apply orbits Jacobians matrices to get consistent errors
 * on orbital parameters.
 *
 * <p>
 * The tolerances are only <em>orders of magnitude</em>, and integrator tolerances
 * are only local estimates, not global ones. So some care must be taken when using
 * these tolerances. Setting 1mm as a position error does NOT mean the tolerances
 * will guarantee a 1mm error position after several orbits integration.
 * </p>
 * @param dP user specified position error
 * @param orbit reference orbit
 * @param type propagation type for the meaning of the tolerance vectors elements
 * (it may be different from {@code orbit.getType()})
 * @return a two rows array, row 0 being the absolute tolerance error and row 1
 * being the relative tolerance error
 * @exception OrekitException if Jacobian is singular
 */
public static double[][] tolerances(final double dP, final Orbit orbit, final OrbitType type) throws OrekitException {
    // estimate the scalar velocity error
    final PVCoordinates pv = orbit.getPVCoordinates();
    final double r2 = pv.getPosition().getNormSq();
    final double v = pv.getVelocity().getNorm();
    final double dV = orbit.getMu() * dP / (v * r2);
    final double[] absTol = new double[7];
    final double[] relTol = new double[7];
    // we set the mass tolerance arbitrarily to 1.0e-6 kg, as mass evolves linearly
    // with trust, this often has no influence at all on propagation
    absTol[6] = 1.0e-6;
    if (type == OrbitType.CARTESIAN) {
        absTol[0] = dP;
        absTol[1] = dP;
        absTol[2] = dP;
        absTol[3] = dV;
        absTol[4] = dV;
        absTol[5] = dV;
    } else {
        // convert the orbit to the desired type
        final double[][] jacobian = new double[6][6];
        final Orbit converted = type.convertType(orbit);
        converted.getJacobianWrtCartesian(PositionAngle.TRUE, jacobian);
        for (int i = 0; i < 6; ++i) {
            final double[] row = jacobian[i];
            absTol[i] = FastMath.abs(row[0]) * dP + FastMath.abs(row[1]) * dP + FastMath.abs(row[2]) * dP + FastMath.abs(row[3]) * dV + FastMath.abs(row[4]) * dV + FastMath.abs(row[5]) * dV;
            if (Double.isNaN(absTol[i])) {
                throw new OrekitException(OrekitMessages.SINGULAR_JACOBIAN_FOR_ORBIT_TYPE, type);
            }
        }
    }
    Arrays.fill(relTol, dP / FastMath.sqrt(r2));
    return new double[][] { absTol, relTol };
}
Also used : Orbit(org.orekit.orbits.Orbit) TimeStampedPVCoordinates(org.orekit.utils.TimeStampedPVCoordinates) PVCoordinates(org.orekit.utils.PVCoordinates) OrekitException(org.orekit.errors.OrekitException)

Example 73 with OrekitException

use of org.orekit.errors.OrekitException in project Orekit by CS-SI.

the class TLEPropagator method computePVCoordinates.

/**
 * Retrieves the position and velocity.
 * @return the computed PVCoordinates.
 * @exception OrekitException if current orbit is out of supported range
 * (too large eccentricity, too low perigee ...)
 */
private PVCoordinates computePVCoordinates() throws OrekitException {
    // Long period periodics
    final double axn = e * FastMath.cos(omega);
    double temp = 1.0 / (a * (1.0 - e * e));
    final double xlcof = 0.125 * TLEConstants.A3OVK2 * sini0 * (3.0 + 5.0 * cosi0) / (1.0 + cosi0);
    final double aycof = 0.25 * TLEConstants.A3OVK2 * sini0;
    final double xll = temp * xlcof * axn;
    final double aynl = temp * aycof;
    final double xlt = xl + xll;
    final double ayn = e * FastMath.sin(omega) + aynl;
    final double elsq = axn * axn + ayn * ayn;
    final double capu = MathUtils.normalizeAngle(xlt - xnode, FastMath.PI);
    double epw = capu;
    double ecosE = 0;
    double esinE = 0;
    double sinEPW = 0;
    double cosEPW = 0;
    // Dundee changes:  items dependent on cosio get recomputed:
    final double cosi0Sq = cosi0 * cosi0;
    final double x3thm1 = 3.0 * cosi0Sq - 1.0;
    final double x1mth2 = 1.0 - cosi0Sq;
    final double x7thm1 = 7.0 * cosi0Sq - 1.0;
    if (e > (1 - 1e-6)) {
        throw new OrekitException(OrekitMessages.TOO_LARGE_ECCENTRICITY_FOR_PROPAGATION_MODEL, e);
    }
    // Solve Kepler's' Equation.
    final double newtonRaphsonEpsilon = 1e-12;
    for (int j = 0; j < 10; j++) {
        boolean doSecondOrderNewtonRaphson = true;
        sinEPW = FastMath.sin(epw);
        cosEPW = FastMath.cos(epw);
        ecosE = axn * cosEPW + ayn * sinEPW;
        esinE = axn * sinEPW - ayn * cosEPW;
        final double f = capu - epw + esinE;
        if (FastMath.abs(f) < newtonRaphsonEpsilon) {
            break;
        }
        final double fdot = 1.0 - ecosE;
        double delta_epw = f / fdot;
        if (j == 0) {
            final double maxNewtonRaphson = 1.25 * FastMath.abs(e);
            doSecondOrderNewtonRaphson = false;
            if (delta_epw > maxNewtonRaphson) {
                delta_epw = maxNewtonRaphson;
            } else if (delta_epw < -maxNewtonRaphson) {
                delta_epw = -maxNewtonRaphson;
            } else {
                doSecondOrderNewtonRaphson = true;
            }
        }
        if (doSecondOrderNewtonRaphson) {
            delta_epw = f / (fdot + 0.5 * esinE * delta_epw);
        }
        epw += delta_epw;
    }
    // Short period preliminary quantities
    temp = 1.0 - elsq;
    final double pl = a * temp;
    final double r = a * (1.0 - ecosE);
    double temp2 = a / r;
    final double betal = FastMath.sqrt(temp);
    temp = esinE / (1.0 + betal);
    final double cosu = temp2 * (cosEPW - axn + ayn * temp);
    final double sinu = temp2 * (sinEPW - ayn - axn * temp);
    final double u = FastMath.atan2(sinu, cosu);
    final double sin2u = 2.0 * sinu * cosu;
    final double cos2u = 2.0 * cosu * cosu - 1.0;
    final double temp1 = TLEConstants.CK2 / pl;
    temp2 = temp1 / pl;
    // Update for short periodics
    final double rk = r * (1.0 - 1.5 * temp2 * betal * x3thm1) + 0.5 * temp1 * x1mth2 * cos2u;
    final double uk = u - 0.25 * temp2 * x7thm1 * sin2u;
    final double xnodek = xnode + 1.5 * temp2 * cosi0 * sin2u;
    final double xinck = i + 1.5 * temp2 * cosi0 * sini0 * cos2u;
    // Orientation vectors
    final double sinuk = FastMath.sin(uk);
    final double cosuk = FastMath.cos(uk);
    final double sinik = FastMath.sin(xinck);
    final double cosik = FastMath.cos(xinck);
    final double sinnok = FastMath.sin(xnodek);
    final double cosnok = FastMath.cos(xnodek);
    final double xmx = -sinnok * cosik;
    final double xmy = cosnok * cosik;
    final double ux = xmx * sinuk + cosnok * cosuk;
    final double uy = xmy * sinuk + sinnok * cosuk;
    final double uz = sinik * sinuk;
    // Position and velocity
    final double cr = 1000 * rk * TLEConstants.EARTH_RADIUS;
    final Vector3D pos = new Vector3D(cr * ux, cr * uy, cr * uz);
    final double rdot = TLEConstants.XKE * FastMath.sqrt(a) * esinE / r;
    final double rfdot = TLEConstants.XKE * FastMath.sqrt(pl) / r;
    final double xn = TLEConstants.XKE / (a * FastMath.sqrt(a));
    final double rdotk = rdot - xn * temp1 * x1mth2 * sin2u;
    final double rfdotk = rfdot + xn * temp1 * (x1mth2 * cos2u + 1.5 * x3thm1);
    final double vx = xmx * cosuk - cosnok * sinuk;
    final double vy = xmy * cosuk - sinnok * sinuk;
    final double vz = sinik * cosuk;
    final double cv = 1000.0 * TLEConstants.EARTH_RADIUS / 60.0;
    final Vector3D vel = new Vector3D(cv * (rdotk * ux + rfdotk * vx), cv * (rdotk * uy + rfdotk * vy), cv * (rdotk * uz + rfdotk * vz));
    return new PVCoordinates(pos, vel);
}
Also used : Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) PVCoordinates(org.orekit.utils.PVCoordinates) OrekitException(org.orekit.errors.OrekitException)

Example 74 with OrekitException

use of org.orekit.errors.OrekitException in project Orekit by CS-SI.

the class JacobianPropagatorConverter method getObjectiveFunction.

/**
 * {@inheritDoc}
 */
protected MultivariateVectorFunction getObjectiveFunction() {
    return new MultivariateVectorFunction() {

        /**
         * {@inheritDoc}
         */
        public double[] value(final double[] arg) throws IllegalArgumentException, OrekitExceptionWrapper {
            try {
                final double[] value = new double[getTargetSize()];
                final NumericalPropagator prop = builder.buildPropagator(arg);
                final int stateSize = isOnlyPosition() ? 3 : 6;
                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
                        fillRows(value, row, prop.getInitialState());
                    } else {
                        // use a date detector to pick up states
                        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, row, state);
                                return row + stateSize >= getTargetSize() ? Action.STOP : Action.CONTINUE;
                            }
                        }));
                    }
                }
                prop.propagate(sample.get(sample.size() - 1).getDate().shiftedBy(10.0));
                return value;
            } catch (OrekitException ex) {
                throw new OrekitExceptionWrapper(ex);
            }
        }
    };
}
Also used : DateDetector(org.orekit.propagation.events.DateDetector) SpacecraftState(org.orekit.propagation.SpacecraftState) OrekitExceptionWrapper(org.orekit.errors.OrekitExceptionWrapper) NumericalPropagator(org.orekit.propagation.numerical.NumericalPropagator) EventHandler(org.orekit.propagation.events.handlers.EventHandler) OrekitException(org.orekit.errors.OrekitException) MultivariateVectorFunction(org.hipparchus.analysis.MultivariateVectorFunction)

Example 75 with OrekitException

use of org.orekit.errors.OrekitException 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)

Aggregations

OrekitException (org.orekit.errors.OrekitException)332 AbsoluteDate (org.orekit.time.AbsoluteDate)150 Test (org.junit.Test)135 Vector3D (org.hipparchus.geometry.euclidean.threed.Vector3D)91 SpacecraftState (org.orekit.propagation.SpacecraftState)75 Frame (org.orekit.frames.Frame)62 FieldAbsoluteDate (org.orekit.time.FieldAbsoluteDate)59 ArrayList (java.util.ArrayList)48 Before (org.junit.Before)48 FieldVector3D (org.hipparchus.geometry.euclidean.threed.FieldVector3D)42 KeplerianOrbit (org.orekit.orbits.KeplerianOrbit)42 DateComponents (org.orekit.time.DateComponents)42 GeodeticPoint (org.orekit.bodies.GeodeticPoint)41 Orbit (org.orekit.orbits.Orbit)40 PVCoordinates (org.orekit.utils.PVCoordinates)37 OneAxisEllipsoid (org.orekit.bodies.OneAxisEllipsoid)36 IOException (java.io.IOException)32 InputStream (java.io.InputStream)31 Propagator (org.orekit.propagation.Propagator)30 UnivariateFunction (org.hipparchus.analysis.UnivariateFunction)28