Search in sources :

Example 6 with AdditionalStateProvider

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

the class TabulatedEphemerisTest method checkInterpolation.

private void checkInterpolation(StateFilter f, double expectedDP, double expectedDV) throws OrekitException {
    double mass = 2500;
    double a = 7187990.1979844316;
    double e = 0.5e-4;
    double i = 1.7105407051081795;
    double omega = 1.9674147913622104;
    double OMEGA = FastMath.toRadians(261);
    double lv = 0;
    final AbsoluteDate initDate = new AbsoluteDate(new DateComponents(2004, 01, 01), TimeComponents.H00, TimeScalesFactory.getUTC());
    final AbsoluteDate finalDate = new AbsoluteDate(new DateComponents(2004, 01, 02), TimeComponents.H00, TimeScalesFactory.getUTC());
    double deltaT = finalDate.durationFrom(initDate);
    Orbit transPar = new KeplerianOrbit(a, e, i, omega, OMEGA, lv, PositionAngle.TRUE, FramesFactory.getEME2000(), initDate, mu);
    int nbIntervals = 720;
    EcksteinHechlerPropagator eck = new EcksteinHechlerPropagator(transPar, mass, ae, mu, c20, c30, c40, c50, c60);
    AdditionalStateProvider provider = new AdditionalStateProvider() {

        public String getName() {
            return "dt";
        }

        public double[] getAdditionalState(SpacecraftState state) {
            return new double[] { state.getDate().durationFrom(initDate) };
        }
    };
    eck.addAdditionalStateProvider(provider);
    try {
        eck.addAdditionalStateProvider(provider);
        Assert.fail("an exception should have been thrown");
    } catch (OrekitException oe) {
        Assert.assertEquals(OrekitMessages.ADDITIONAL_STATE_NAME_ALREADY_IN_USE, oe.getSpecifier());
    }
    List<SpacecraftState> tab = new ArrayList<SpacecraftState>(nbIntervals + 1);
    for (int j = 0; j <= nbIntervals; j++) {
        AbsoluteDate current = initDate.shiftedBy((j * deltaT) / nbIntervals);
        tab.add(f.filter(eck.propagate(current)));
    }
    try {
        new Ephemeris(tab, nbIntervals + 2);
        Assert.fail("an exception should have been thrown");
    } catch (MathIllegalArgumentException miae) {
    // expected
    }
    Ephemeris te = new Ephemeris(tab, 2);
    Assert.assertEquals(0.0, te.getMaxDate().durationFrom(finalDate), 1.0e-9);
    Assert.assertEquals(0.0, te.getMinDate().durationFrom(initDate), 1.0e-9);
    double maxP = 0;
    double maxV = 0;
    for (double dt = 0; dt < 3600; dt += 1) {
        AbsoluteDate date = initDate.shiftedBy(dt);
        CartesianOrbit c1 = (CartesianOrbit) eck.propagate(date).getOrbit();
        CartesianOrbit c2 = (CartesianOrbit) te.propagate(date).getOrbit();
        maxP = FastMath.max(maxP, Vector3D.distance(c1.getPVCoordinates().getPosition(), c2.getPVCoordinates().getPosition()));
        maxV = FastMath.max(maxV, Vector3D.distance(c1.getPVCoordinates().getVelocity(), c2.getPVCoordinates().getVelocity()));
    }
    Assert.assertEquals(expectedDP, maxP, 0.1 * expectedDP);
    Assert.assertEquals(expectedDV, maxV, 0.1 * expectedDV);
}
Also used : CartesianOrbit(org.orekit.orbits.CartesianOrbit) Orbit(org.orekit.orbits.Orbit) EquinoctialOrbit(org.orekit.orbits.EquinoctialOrbit) CartesianOrbit(org.orekit.orbits.CartesianOrbit) KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) ArrayList(java.util.ArrayList) DateComponents(org.orekit.time.DateComponents) AbsoluteDate(org.orekit.time.AbsoluteDate) SpacecraftState(org.orekit.propagation.SpacecraftState) AdditionalStateProvider(org.orekit.propagation.AdditionalStateProvider) MathIllegalArgumentException(org.hipparchus.exception.MathIllegalArgumentException) KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) OrekitException(org.orekit.errors.OrekitException)

Example 7 with AdditionalStateProvider

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

the class EcksteinHechlerPropagator method writeReplace.

/**
 * Replace the instance with a data transfer object for serialization.
 * @return data transfer object that will be serialized
 * @exception NotSerializableException if an additional state provider is not serializable
 */
private Object writeReplace() throws NotSerializableException {
    try {
        // managed states providers
        final List<AdditionalStateProvider> serializableProviders = new ArrayList<AdditionalStateProvider>();
        for (final AdditionalStateProvider provider : getAdditionalStateProviders()) {
            if (provider instanceof Serializable) {
                serializableProviders.add(provider);
            } else {
                throw new NotSerializableException(provider.getClass().getName());
            }
        }
        // states transitions
        final AbsoluteDate[] transitionDates;
        final CircularOrbit[] allOrbits;
        final double[] allMasses;
        final SortedSet<TimeSpanMap.Transition<EHModel>> transitions = models.getTransitions();
        if (transitions.size() == 1 && transitions.first().getBefore() == transitions.first().getAfter()) {
            // the single entry is a dummy one, without a real transition
            // we ignore it completely
            transitionDates = null;
            allOrbits = null;
            allMasses = null;
        } else {
            transitionDates = new AbsoluteDate[transitions.size()];
            allOrbits = new CircularOrbit[transitions.size() + 1];
            allMasses = new double[transitions.size() + 1];
            int i = 0;
            for (final TimeSpanMap.Transition<EHModel> transition : transitions) {
                if (i == 0) {
                    // model before the first transition
                    allOrbits[i] = transition.getBefore().mean;
                    allMasses[i] = transition.getBefore().mass;
                }
                transitionDates[i] = transition.getDate();
                allOrbits[++i] = transition.getAfter().mean;
                allMasses[i] = transition.getAfter().mass;
            }
        }
        return new DataTransferObject(getInitialState().getOrbit(), initialModel.mass, referenceRadius, mu, ck0, getAttitudeProvider(), transitionDates, allOrbits, allMasses, serializableProviders.toArray(new AdditionalStateProvider[serializableProviders.size()]));
    } catch (OrekitException orekitException) {
        // this should never happen
        throw new OrekitInternalError(null);
    }
}
Also used : OrekitInternalError(org.orekit.errors.OrekitInternalError) Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) AbsoluteDate(org.orekit.time.AbsoluteDate) NotSerializableException(java.io.NotSerializableException) AdditionalStateProvider(org.orekit.propagation.AdditionalStateProvider) CircularOrbit(org.orekit.orbits.CircularOrbit) TimeSpanMap(org.orekit.utils.TimeSpanMap) OrekitException(org.orekit.errors.OrekitException)

Example 8 with AdditionalStateProvider

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

the class AdapterPropagatorTest method testLowEarthOrbit.

@Test
public void testLowEarthOrbit() throws OrekitException, ParseException, IOException {
    Orbit leo = new CircularOrbit(7200000.0, -1.0e-5, 2.0e-4, FastMath.toRadians(98.0), FastMath.toRadians(123.456), 0.0, PositionAngle.MEAN, FramesFactory.getEME2000(), new AbsoluteDate(new DateComponents(2004, 01, 01), new TimeComponents(23, 30, 00.000), TimeScalesFactory.getUTC()), Constants.EIGEN5C_EARTH_MU);
    double mass = 5600.0;
    AbsoluteDate t0 = leo.getDate().shiftedBy(1000.0);
    Vector3D dV = new Vector3D(-0.1, 0.2, 0.3);
    double f = 20.0;
    double isp = 315.0;
    double vExhaust = Constants.G0_STANDARD_GRAVITY * isp;
    double dt = -(mass * vExhaust / f) * FastMath.expm1(-dV.getNorm() / vExhaust);
    BoundedPropagator withoutManeuver = getEphemeris(leo, mass, 5, new LofOffset(leo.getFrame(), LOFType.LVLH), t0, Vector3D.ZERO, f, isp, false, false, null);
    BoundedPropagator withManeuver = getEphemeris(leo, mass, 5, new LofOffset(leo.getFrame(), LOFType.LVLH), t0, dV, f, isp, false, false, null);
    // we set up a model that reverts the maneuvers
    AdapterPropagator adapterPropagator = new AdapterPropagator(withManeuver);
    AdapterPropagator.DifferentialEffect effect = new SmallManeuverAnalyticalModel(adapterPropagator.propagate(t0), dV.negate(), isp);
    adapterPropagator.addEffect(effect);
    adapterPropagator.addAdditionalStateProvider(new AdditionalStateProvider() {

        public String getName() {
            return "dummy 3";
        }

        public double[] getAdditionalState(SpacecraftState state) {
            return new double[3];
        }
    });
    // the adapted propagators do not manage the additional states from the reference,
    // they simply forward them
    Assert.assertFalse(adapterPropagator.isAdditionalStateManaged("dummy 1"));
    Assert.assertFalse(adapterPropagator.isAdditionalStateManaged("dummy 2"));
    Assert.assertTrue(adapterPropagator.isAdditionalStateManaged("dummy 3"));
    for (AbsoluteDate t = t0.shiftedBy(0.5 * dt); t.compareTo(withoutManeuver.getMaxDate()) < 0; t = t.shiftedBy(60.0)) {
        PVCoordinates pvWithout = withoutManeuver.getPVCoordinates(t, leo.getFrame());
        PVCoordinates pvReverted = adapterPropagator.getPVCoordinates(t, leo.getFrame());
        double revertError = new PVCoordinates(pvWithout, pvReverted).getPosition().getNorm();
        Assert.assertEquals(0, revertError, 0.45);
        Assert.assertEquals(2, adapterPropagator.propagate(t).getAdditionalState("dummy 1").length);
        Assert.assertEquals(1, adapterPropagator.propagate(t).getAdditionalState("dummy 2").length);
        Assert.assertEquals(3, adapterPropagator.propagate(t).getAdditionalState("dummy 3").length);
    }
}
Also used : Orbit(org.orekit.orbits.Orbit) CircularOrbit(org.orekit.orbits.CircularOrbit) KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) PVCoordinates(org.orekit.utils.PVCoordinates) DateComponents(org.orekit.time.DateComponents) TimeComponents(org.orekit.time.TimeComponents) AbsoluteDate(org.orekit.time.AbsoluteDate) SpacecraftState(org.orekit.propagation.SpacecraftState) SmallManeuverAnalyticalModel(org.orekit.forces.maneuvers.SmallManeuverAnalyticalModel) CircularOrbit(org.orekit.orbits.CircularOrbit) AdditionalStateProvider(org.orekit.propagation.AdditionalStateProvider) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) BoundedPropagator(org.orekit.propagation.BoundedPropagator) LofOffset(org.orekit.attitudes.LofOffset) Test(org.junit.Test)

Example 9 with AdditionalStateProvider

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

the class AdapterPropagatorTest method testNonKeplerian.

@Test
public void testNonKeplerian() throws OrekitException, ParseException, IOException {
    Orbit leo = new CircularOrbit(7204319.233600575, 4.434564637450575E-4, 0.0011736728299091088, 1.7211611441767323, 5.5552084166959474, 24950.321259193086, PositionAngle.TRUE, FramesFactory.getEME2000(), new AbsoluteDate(new DateComponents(2003, 9, 16), new TimeComponents(23, 11, 20.264), TimeScalesFactory.getUTC()), Constants.EIGEN5C_EARTH_MU);
    double mass = 4093.0;
    AbsoluteDate t0 = new AbsoluteDate(new DateComponents(2003, 9, 16), new TimeComponents(23, 14, 40.264), TimeScalesFactory.getUTC());
    Vector3D dV = new Vector3D(0.0, 3.0, 0.0);
    double f = 40.0;
    double isp = 300.0;
    double vExhaust = Constants.G0_STANDARD_GRAVITY * isp;
    double dt = -(mass * vExhaust / f) * FastMath.expm1(-dV.getNorm() / vExhaust);
    // setup a specific coefficient file for gravity potential as it will also
    // try to read a corrupted one otherwise
    GravityFieldFactory.addPotentialCoefficientsReader(new ICGEMFormatReader("g007_eigen_05c_coef", false));
    NormalizedSphericalHarmonicsProvider gravityField = GravityFieldFactory.getNormalizedProvider(8, 8);
    BoundedPropagator withoutManeuver = getEphemeris(leo, mass, 10, new LofOffset(leo.getFrame(), LOFType.VNC), t0, Vector3D.ZERO, f, isp, true, true, gravityField);
    BoundedPropagator withManeuver = getEphemeris(leo, mass, 10, new LofOffset(leo.getFrame(), LOFType.VNC), t0, dV, f, isp, true, true, gravityField);
    // we set up a model that reverts the maneuvers
    AdapterPropagator adapterPropagator = new AdapterPropagator(withManeuver);
    SpacecraftState state0 = adapterPropagator.propagate(t0);
    AdapterPropagator.DifferentialEffect directEffect = new SmallManeuverAnalyticalModel(state0, dV.negate(), isp);
    AdapterPropagator.DifferentialEffect derivedEffect = new J2DifferentialEffect(state0, directEffect, false, GravityFieldFactory.getUnnormalizedProvider(gravityField));
    adapterPropagator.addEffect(directEffect);
    adapterPropagator.addEffect(derivedEffect);
    adapterPropagator.addAdditionalStateProvider(new AdditionalStateProvider() {

        public String getName() {
            return "dummy 3";
        }

        public double[] getAdditionalState(SpacecraftState state) {
            return new double[3];
        }
    });
    // the adapted propagators do not manage the additional states from the reference,
    // they simply forward them
    Assert.assertFalse(adapterPropagator.isAdditionalStateManaged("dummy 1"));
    Assert.assertFalse(adapterPropagator.isAdditionalStateManaged("dummy 2"));
    Assert.assertTrue(adapterPropagator.isAdditionalStateManaged("dummy 3"));
    double maxDelta = 0;
    double maxNominal = 0;
    for (AbsoluteDate t = t0.shiftedBy(0.5 * dt); t.compareTo(withoutManeuver.getMaxDate()) < 0; t = t.shiftedBy(600.0)) {
        PVCoordinates pvWithout = withoutManeuver.getPVCoordinates(t, leo.getFrame());
        PVCoordinates pvWith = withManeuver.getPVCoordinates(t, leo.getFrame());
        PVCoordinates pvReverted = adapterPropagator.getPVCoordinates(t, leo.getFrame());
        double nominal = new PVCoordinates(pvWithout, pvWith).getPosition().getNorm();
        double revertError = new PVCoordinates(pvWithout, pvReverted).getPosition().getNorm();
        maxDelta = FastMath.max(maxDelta, revertError);
        maxNominal = FastMath.max(maxNominal, nominal);
        Assert.assertEquals(2, adapterPropagator.propagate(t).getAdditionalState("dummy 1").length);
        Assert.assertEquals(1, adapterPropagator.propagate(t).getAdditionalState("dummy 2").length);
        Assert.assertEquals(3, adapterPropagator.propagate(t).getAdditionalState("dummy 3").length);
    }
    Assert.assertTrue(maxDelta < 120);
    Assert.assertTrue(maxNominal > 2800);
}
Also used : Orbit(org.orekit.orbits.Orbit) CircularOrbit(org.orekit.orbits.CircularOrbit) KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) ICGEMFormatReader(org.orekit.forces.gravity.potential.ICGEMFormatReader) PVCoordinates(org.orekit.utils.PVCoordinates) DateComponents(org.orekit.time.DateComponents) TimeComponents(org.orekit.time.TimeComponents) AbsoluteDate(org.orekit.time.AbsoluteDate) SpacecraftState(org.orekit.propagation.SpacecraftState) SmallManeuverAnalyticalModel(org.orekit.forces.maneuvers.SmallManeuverAnalyticalModel) CircularOrbit(org.orekit.orbits.CircularOrbit) AdditionalStateProvider(org.orekit.propagation.AdditionalStateProvider) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) NormalizedSphericalHarmonicsProvider(org.orekit.forces.gravity.potential.NormalizedSphericalHarmonicsProvider) BoundedPropagator(org.orekit.propagation.BoundedPropagator) LofOffset(org.orekit.attitudes.LofOffset) Test(org.junit.Test)

Example 10 with AdditionalStateProvider

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

the class AdapterPropagatorTest method getEphemeris.

private BoundedPropagator getEphemeris(final Orbit orbit, final double mass, final int nbOrbits, final AttitudeProvider law, final AbsoluteDate t0, final Vector3D dV, final double f, final double isp, final boolean sunAttraction, final boolean moonAttraction, final NormalizedSphericalHarmonicsProvider gravityField) throws OrekitException, ParseException, IOException {
    SpacecraftState initialState = new SpacecraftState(orbit, law.getAttitude(orbit, orbit.getDate(), orbit.getFrame()), mass);
    // add some dummy additional states
    initialState = initialState.addAdditionalState("dummy 1", 1.25, 2.5);
    initialState = initialState.addAdditionalState("dummy 2", 5.0);
    // set up numerical propagator
    final double dP = 1.0;
    double[][] tolerances = NumericalPropagator.tolerances(dP, orbit, orbit.getType());
    AdaptiveStepsizeIntegrator integrator = new DormandPrince853Integrator(0.001, 1000, tolerances[0], tolerances[1]);
    integrator.setInitialStepSize(orbit.getKeplerianPeriod() / 100.0);
    final NumericalPropagator propagator = new NumericalPropagator(integrator);
    propagator.addAdditionalStateProvider(new AdditionalStateProvider() {

        public String getName() {
            return "dummy 2";
        }

        public double[] getAdditionalState(SpacecraftState state) {
            return new double[] { 5.0 };
        }
    });
    propagator.setInitialState(initialState);
    propagator.setAttitudeProvider(law);
    if (dV.getNorm() > 1.0e-6) {
        // set up maneuver
        final double vExhaust = Constants.G0_STANDARD_GRAVITY * isp;
        final double dt = -(mass * vExhaust / f) * FastMath.expm1(-dV.getNorm() / vExhaust);
        final ConstantThrustManeuver maneuver = new ConstantThrustManeuver(t0.shiftedBy(-0.5 * dt), dt, f, isp, dV.normalize());
        propagator.addForceModel(maneuver);
    }
    if (sunAttraction) {
        propagator.addForceModel(new ThirdBodyAttraction(CelestialBodyFactory.getSun()));
    }
    if (moonAttraction) {
        propagator.addForceModel(new ThirdBodyAttraction(CelestialBodyFactory.getMoon()));
    }
    if (gravityField != null) {
        propagator.addForceModel(new HolmesFeatherstoneAttractionModel(FramesFactory.getGTOD(false), gravityField));
    }
    propagator.setEphemerisMode();
    propagator.propagate(t0.shiftedBy(nbOrbits * orbit.getKeplerianPeriod()));
    final BoundedPropagator ephemeris = propagator.getGeneratedEphemeris();
    // both the initial propagator and generated ephemeris manage one of the two
    // additional states, but they also contain unmanaged copies of the other one
    Assert.assertFalse(propagator.isAdditionalStateManaged("dummy 1"));
    Assert.assertTrue(propagator.isAdditionalStateManaged("dummy 2"));
    Assert.assertFalse(ephemeris.isAdditionalStateManaged("dummy 1"));
    Assert.assertTrue(ephemeris.isAdditionalStateManaged("dummy 2"));
    Assert.assertEquals(2, ephemeris.getInitialState().getAdditionalState("dummy 1").length);
    Assert.assertEquals(1, ephemeris.getInitialState().getAdditionalState("dummy 2").length);
    return ephemeris;
}
Also used : SpacecraftState(org.orekit.propagation.SpacecraftState) ThirdBodyAttraction(org.orekit.forces.gravity.ThirdBodyAttraction) AdditionalStateProvider(org.orekit.propagation.AdditionalStateProvider) NumericalPropagator(org.orekit.propagation.numerical.NumericalPropagator) AdaptiveStepsizeIntegrator(org.hipparchus.ode.nonstiff.AdaptiveStepsizeIntegrator) DormandPrince853Integrator(org.hipparchus.ode.nonstiff.DormandPrince853Integrator) HolmesFeatherstoneAttractionModel(org.orekit.forces.gravity.HolmesFeatherstoneAttractionModel) BoundedPropagator(org.orekit.propagation.BoundedPropagator) ConstantThrustManeuver(org.orekit.forces.maneuvers.ConstantThrustManeuver)

Aggregations

AdditionalStateProvider (org.orekit.propagation.AdditionalStateProvider)13 SpacecraftState (org.orekit.propagation.SpacecraftState)11 Test (org.junit.Test)8 AbsoluteDate (org.orekit.time.AbsoluteDate)7 ArrayList (java.util.ArrayList)5 OrekitException (org.orekit.errors.OrekitException)5 CircularOrbit (org.orekit.orbits.CircularOrbit)5 KeplerianOrbit (org.orekit.orbits.KeplerianOrbit)5 BoundedPropagator (org.orekit.propagation.BoundedPropagator)5 NotSerializableException (java.io.NotSerializableException)4 Vector3D (org.hipparchus.geometry.euclidean.threed.Vector3D)4 LofOffset (org.orekit.attitudes.LofOffset)4 Orbit (org.orekit.orbits.Orbit)4 DateComponents (org.orekit.time.DateComponents)4 Serializable (java.io.Serializable)3 SmallManeuverAnalyticalModel (org.orekit.forces.maneuvers.SmallManeuverAnalyticalModel)3 TimeComponents (org.orekit.time.TimeComponents)3 PVCoordinates (org.orekit.utils.PVCoordinates)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ObjectOutputStream (java.io.ObjectOutputStream)2