Search in sources :

Example 91 with SpacecraftState

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

the class Phasing method findLatitudeCrossing.

/**
 * Find the state at which the reference latitude is crossed.
 * @param latitude latitude to search for
 * @param guessDate guess date for the crossing
 * @param endDate maximal date not to overtake
 * @param shift shift value used to evaluate the latitude function bracketing around the guess date
 * @param maxShift maximum value that the shift value can take
 * @param propagator propagator used
 * @return state at latitude crossing time
 * @throws OrekitException if state cannot be propagated
 * @throws MathRuntimeException if latitude cannot be bracketed in the search interval
 */
private SpacecraftState findLatitudeCrossing(final double latitude, final AbsoluteDate guessDate, final AbsoluteDate endDate, final double shift, final double maxShift, final Propagator propagator) throws OrekitException, MathRuntimeException {
    // function evaluating to 0 at latitude crossings
    final UnivariateFunction latitudeFunction = new UnivariateFunction() {

        /**
         * {@inheritDoc}
         */
        public double value(double x) {
            try {
                final SpacecraftState state = propagator.propagate(guessDate.shiftedBy(x));
                final Vector3D position = state.getPVCoordinates(earth.getBodyFrame()).getPosition();
                final GeodeticPoint point = earth.transform(position, earth.getBodyFrame(), state.getDate());
                return point.getLatitude() - latitude;
            } catch (OrekitException oe) {
                throw new RuntimeException(oe);
            }
        }
    };
    // try to bracket the encounter
    double span;
    if (guessDate.shiftedBy(shift).compareTo(endDate) > 0) {
        // Take a 1e-3 security margin
        span = endDate.durationFrom(guessDate) - 1e-3;
    } else {
        span = shift;
    }
    while (!UnivariateSolverUtils.isBracketing(latitudeFunction, -span, span)) {
        if (2 * span > maxShift) {
            // let the Hipparchus exception be thrown
            UnivariateSolverUtils.verifyBracketing(latitudeFunction, -span, span);
        } else if (guessDate.shiftedBy(2 * span).compareTo(endDate) > 0) {
            // Out of range :
            return null;
        }
        // expand the search interval
        span *= 2;
    }
    // find the encounter in the bracketed interval
    final BaseUnivariateSolver<UnivariateFunction> solver = new BracketingNthOrderBrentSolver(0.1, 5);
    final double dt = solver.solve(1000, latitudeFunction, -span, span);
    return propagator.propagate(guessDate.shiftedBy(dt));
}
Also used : SpacecraftState(org.orekit.propagation.SpacecraftState) MathRuntimeException(org.hipparchus.exception.MathRuntimeException) UnivariateFunction(org.hipparchus.analysis.UnivariateFunction) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) OrekitException(org.orekit.errors.OrekitException) GeodeticPoint(org.orekit.bodies.GeodeticPoint) BracketingNthOrderBrentSolver(org.hipparchus.analysis.solvers.BracketingNthOrderBrentSolver)

Example 92 with SpacecraftState

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

the class SecularAndHarmonicTest method createPropagator.

private NumericalPropagator createPropagator(CircularOrbit orbit) throws OrekitException {
    OrbitType type = OrbitType.CIRCULAR;
    double[][] tolerances = NumericalPropagator.tolerances(0.1, orbit, type);
    DormandPrince853Integrator integrator = new DormandPrince853Integrator(1.0, 600, tolerances[0], tolerances[1]);
    integrator.setInitialStepSize(60.0);
    NumericalPropagator propagator = new NumericalPropagator(integrator);
    propagator.addForceModel(new HolmesFeatherstoneAttractionModel(earth.getBodyFrame(), gravityField));
    propagator.addForceModel(new ThirdBodyAttraction(CelestialBodyFactory.getSun()));
    propagator.addForceModel(new ThirdBodyAttraction(CelestialBodyFactory.getMoon()));
    propagator.setOrbitType(type);
    propagator.resetInitialState(new SpacecraftState(orbit));
    return propagator;
}
Also used : SpacecraftState(org.orekit.propagation.SpacecraftState) ThirdBodyAttraction(org.orekit.forces.gravity.ThirdBodyAttraction) NumericalPropagator(org.orekit.propagation.numerical.NumericalPropagator) OrbitType(org.orekit.orbits.OrbitType) DormandPrince853Integrator(org.hipparchus.ode.nonstiff.DormandPrince853Integrator) HolmesFeatherstoneAttractionModel(org.orekit.forces.gravity.HolmesFeatherstoneAttractionModel)

Example 93 with SpacecraftState

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

the class OrekitStepHandlerTest method testIsInterpolated.

/**
 * Check {@link OrekitStepInterpolator#isPreviousStateInterpolated()} and {@link
 * OrekitStepInterpolator#isCurrentStateInterpolated()}.
 *
 * @throws OrekitException on error.
 */
@Test
public void testIsInterpolated() throws OrekitException {
    // setup
    NumericalPropagator propagator = new NumericalPropagator(new ClassicalRungeKuttaIntegrator(60));
    AbsoluteDate date = AbsoluteDate.J2000_EPOCH;
    Frame eci = FramesFactory.getGCRF();
    SpacecraftState ic = new SpacecraftState(new KeplerianOrbit(6378137 + 500e3, 1e-3, 0, 0, 0, 0, PositionAngle.TRUE, eci, date, Constants.EIGEN5C_EARTH_MU));
    propagator.setInitialState(ic);
    propagator.setOrbitType(OrbitType.CARTESIAN);
    // detector triggers half way through second step
    DateDetector detector = new DateDetector(date.shiftedBy(90)).withHandler(new ContinueOnEvent<>());
    propagator.addEventDetector(detector);
    // action and verify
    Queue<Boolean> expected = new ArrayDeque<>(Arrays.asList(false, false, false, true, true, false));
    propagator.setMasterMode(new OrekitStepHandler() {

        @Override
        public void handleStep(OrekitStepInterpolator interpolator, boolean isLast) {
            assertEquals(expected.poll(), interpolator.isPreviousStateInterpolated());
            assertEquals(expected.poll(), interpolator.isCurrentStateInterpolated());
        }
    });
    final AbsoluteDate end = date.shiftedBy(120);
    assertEquals(end, propagator.propagate(end).getDate());
}
Also used : DateDetector(org.orekit.propagation.events.DateDetector) Frame(org.orekit.frames.Frame) FactoryManagedFrame(org.orekit.frames.FactoryManagedFrame) ClassicalRungeKuttaIntegrator(org.hipparchus.ode.nonstiff.ClassicalRungeKuttaIntegrator) AbsoluteDate(org.orekit.time.AbsoluteDate) ArrayDeque(java.util.ArrayDeque) SpacecraftState(org.orekit.propagation.SpacecraftState) NumericalPropagator(org.orekit.propagation.numerical.NumericalPropagator) KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) Test(org.junit.Test)

Example 94 with SpacecraftState

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

the class KeplerianPropagator method resetInitialState.

/**
 * {@inheritDoc}
 */
public void resetInitialState(final SpacecraftState state) throws OrekitException {
    // ensure the orbit use the specified mu and has no non-Keplerian derivatives
    final double mu = initialState == null ? state.getMu() : initialState.getMu();
    final SpacecraftState fixedState = fixState(state.getOrbit(), state.getAttitude(), state.getMass(), mu, state.getAdditionalStates());
    initialState = fixedState;
    states = new TimeSpanMap<SpacecraftState>(initialState);
    super.resetInitialState(fixedState);
}
Also used : SpacecraftState(org.orekit.propagation.SpacecraftState)

Example 95 with SpacecraftState

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

the class KeplerianPropagator method fixState.

/**
 * Fix state to use a specified mu and remove derivatives.
 * <p>
 * This ensures the propagation model (which is based on calling
 * {@link Orbit#shiftedBy(double)}) is Keplerian only and uses a specified mu.
 * </p>
 * @param orbit orbit to fix
 * @param attitude current attitude
 * @param mass current mass
 * @param mu gravity coefficient to use
 * @param additionalStates additional states
 * @return fixed orbit
 */
private SpacecraftState fixState(final Orbit orbit, final Attitude attitude, final double mass, final double mu, final Map<String, double[]> additionalStates) {
    final OrbitType type = orbit.getType();
    final double[] stateVector = new double[6];
    type.mapOrbitToArray(orbit, PositionAngle.TRUE, stateVector, null);
    final Orbit fixedOrbit = type.mapArrayToOrbit(stateVector, null, PositionAngle.TRUE, orbit.getDate(), mu, orbit.getFrame());
    SpacecraftState fixedState = new SpacecraftState(fixedOrbit, attitude, mass);
    for (final Map.Entry<String, double[]> entry : additionalStates.entrySet()) {
        fixedState = fixedState.addAdditionalState(entry.getKey(), entry.getValue());
    }
    return fixedState;
}
Also used : SpacecraftState(org.orekit.propagation.SpacecraftState) Orbit(org.orekit.orbits.Orbit) OrbitType(org.orekit.orbits.OrbitType) TimeSpanMap(org.orekit.utils.TimeSpanMap) Map(java.util.Map)

Aggregations

SpacecraftState (org.orekit.propagation.SpacecraftState)470 Test (org.junit.Test)324 AbsoluteDate (org.orekit.time.AbsoluteDate)280 KeplerianOrbit (org.orekit.orbits.KeplerianOrbit)178 Vector3D (org.hipparchus.geometry.euclidean.threed.Vector3D)153 FieldAbsoluteDate (org.orekit.time.FieldAbsoluteDate)138 Orbit (org.orekit.orbits.Orbit)131 FieldSpacecraftState (org.orekit.propagation.FieldSpacecraftState)127 PVCoordinates (org.orekit.utils.PVCoordinates)98 CartesianOrbit (org.orekit.orbits.CartesianOrbit)95 Propagator (org.orekit.propagation.Propagator)92 Frame (org.orekit.frames.Frame)79 OrekitException (org.orekit.errors.OrekitException)74 EquinoctialOrbit (org.orekit.orbits.EquinoctialOrbit)74 NumericalPropagator (org.orekit.propagation.numerical.NumericalPropagator)74 DormandPrince853Integrator (org.hipparchus.ode.nonstiff.DormandPrince853Integrator)70 TimeStampedPVCoordinates (org.orekit.utils.TimeStampedPVCoordinates)64 AbstractLegacyForceModelTest (org.orekit.forces.AbstractLegacyForceModelTest)61 CircularOrbit (org.orekit.orbits.CircularOrbit)58 FieldVector3D (org.hipparchus.geometry.euclidean.threed.FieldVector3D)57