Search in sources :

Example 1 with AdditionalStateProvider

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

the class NumericalPropagatorTest method testAdditionalStateEvent.

@Test
public void testAdditionalStateEvent() throws OrekitException {
    propagator.addAdditionalEquations(new AdditionalEquations() {

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

        public double[] computeDerivatives(SpacecraftState s, double[] pDot) {
            pDot[0] = 1.0;
            return new double[7];
        }
    });
    try {
        propagator.addAdditionalEquations(new AdditionalEquations() {

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

            public double[] computeDerivatives(SpacecraftState s, double[] pDot) {
                pDot[0] = 1.0;
                return new double[7];
            }
        });
        Assert.fail("an exception should have been thrown");
    } catch (OrekitException oe) {
        Assert.assertEquals(oe.getSpecifier(), OrekitMessages.ADDITIONAL_STATE_NAME_ALREADY_IN_USE);
    }
    try {
        propagator.addAdditionalStateProvider(new AdditionalStateProvider() {

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

            public double[] getAdditionalState(SpacecraftState state) {
                return null;
            }
        });
        Assert.fail("an exception should have been thrown");
    } catch (OrekitException oe) {
        Assert.assertEquals(oe.getSpecifier(), OrekitMessages.ADDITIONAL_STATE_NAME_ALREADY_IN_USE);
    }
    propagator.addAdditionalStateProvider(new AdditionalStateProvider() {

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

        public double[] getAdditionalState(SpacecraftState state) {
            return new double[] { 1.0 };
        }
    });
    Assert.assertTrue(propagator.isAdditionalStateManaged("linear"));
    Assert.assertTrue(propagator.isAdditionalStateManaged("constant"));
    Assert.assertFalse(propagator.isAdditionalStateManaged("non-managed"));
    Assert.assertEquals(2, propagator.getManagedAdditionalStates().length);
    propagator.setInitialState(propagator.getInitialState().addAdditionalState("linear", 1.5));
    CheckingHandler<AdditionalStateLinearDetector> checking = new CheckingHandler<AdditionalStateLinearDetector>(Action.STOP);
    propagator.addEventDetector(new AdditionalStateLinearDetector(10.0, 1.0e-8).withHandler(checking));
    final double dt = 3200;
    checking.assertEvent(false);
    final SpacecraftState finalState = propagator.propagate(initDate.shiftedBy(dt));
    checking.assertEvent(true);
    Assert.assertEquals(3.0, finalState.getAdditionalState("linear")[0], 1.0e-8);
    Assert.assertEquals(1.5, finalState.getDate().durationFrom(initDate), 1.0e-8);
}
Also used : SpacecraftState(org.orekit.propagation.SpacecraftState) FieldSpacecraftState(org.orekit.propagation.FieldSpacecraftState) AdditionalEquations(org.orekit.propagation.integration.AdditionalEquations) AdditionalStateProvider(org.orekit.propagation.AdditionalStateProvider) OrekitException(org.orekit.errors.OrekitException) Test(org.junit.Test)

Example 2 with AdditionalStateProvider

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

the class KeplerianPropagator 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 SpacecraftState[] allStates;
        final SortedSet<TimeSpanMap.Transition<SpacecraftState>> transitions = states.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;
            allStates = null;
        } else {
            transitionDates = new AbsoluteDate[transitions.size()];
            allStates = new SpacecraftState[transitions.size() + 1];
            int i = 0;
            for (final TimeSpanMap.Transition<SpacecraftState> transition : transitions) {
                if (i == 0) {
                    // state before the first transition
                    allStates[i] = transition.getBefore();
                }
                transitionDates[i] = transition.getDate();
                allStates[++i] = transition.getAfter();
            }
        }
        return new DataTransferObject(getInitialState().getOrbit(), getAttitudeProvider(), getInitialState().getMu(), getInitialState().getMass(), transitionDates, allStates, 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) SpacecraftState(org.orekit.propagation.SpacecraftState) NotSerializableException(java.io.NotSerializableException) AdditionalStateProvider(org.orekit.propagation.AdditionalStateProvider) TimeSpanMap(org.orekit.utils.TimeSpanMap) OrekitException(org.orekit.errors.OrekitException)

Example 3 with AdditionalStateProvider

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

the class IntegratedEphemeris method writeReplace.

/**
 * Replace the instance with a data transfer object for serialization.
 * @return data transfer object that will be serialized
 * @exception NotSerializableException if the state mapper cannot be serialized (typically for DSST propagator)
 */
private Object writeReplace() throws NotSerializableException {
    // unmanaged additional states
    final String[] unmanagedNames = new String[unmanaged.size()];
    final double[][] unmanagedValues = new double[unmanaged.size()][];
    int i = 0;
    for (Map.Entry<String, double[]> entry : unmanaged.entrySet()) {
        unmanagedNames[i] = entry.getKey();
        unmanagedValues[i] = entry.getValue();
        ++i;
    }
    // managed states providers
    final List<AdditionalStateProvider> serializableProviders = new ArrayList<AdditionalStateProvider>();
    final List<String> equationNames = new ArrayList<String>();
    for (final AdditionalStateProvider provider : getAdditionalStateProviders()) {
        if (provider instanceof LocalProvider) {
            equationNames.add(((LocalProvider) provider).getName());
        } else if (provider instanceof Serializable) {
            serializableProviders.add(provider);
        }
    }
    return new DataTransferObject(startDate, minDate, maxDate, mapper, meanOrbit, model, unmanagedNames, unmanagedValues, serializableProviders.toArray(new AdditionalStateProvider[serializableProviders.size()]), equationNames.toArray(new String[equationNames.size()]));
}
Also used : Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) AdditionalStateProvider(org.orekit.propagation.AdditionalStateProvider) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with AdditionalStateProvider

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

the class NumericalPropagatorTest method testEphemerisAdditionalState.

@Test
public void testEphemerisAdditionalState() throws OrekitException, IOException {
    // Propagation of the initial at t + dt
    final double dt = -3200;
    final double rate = 2.0;
    propagator.addAdditionalStateProvider(new AdditionalStateProvider() {

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

        public double[] getAdditionalState(SpacecraftState state) {
            return new double[] { state.getA() * state.getA() };
        }
    });
    propagator.addAdditionalEquations(new AdditionalEquations() {

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

        public double[] computeDerivatives(SpacecraftState s, double[] pDot) {
            pDot[0] = rate;
            return null;
        }
    });
    propagator.setInitialState(propagator.getInitialState().addAdditionalState("extra", 1.5));
    propagator.setOrbitType(OrbitType.CARTESIAN);
    propagator.setEphemerisMode();
    propagator.propagate(initDate.shiftedBy(dt));
    final BoundedPropagator ephemeris1 = propagator.getGeneratedEphemeris();
    Assert.assertEquals(initDate.shiftedBy(dt), ephemeris1.getMinDate());
    Assert.assertEquals(initDate, ephemeris1.getMaxDate());
    try {
        ephemeris1.propagate(ephemeris1.getMinDate().shiftedBy(-10.0));
        Assert.fail("an exception should have been thrown");
    } catch (OrekitException pe) {
        Assert.assertEquals(OrekitMessages.OUT_OF_RANGE_EPHEMERIDES_DATE, pe.getSpecifier());
    }
    try {
        ephemeris1.propagate(ephemeris1.getMaxDate().shiftedBy(+10.0));
        Assert.fail("an exception should have been thrown");
    } catch (OrekitException pe) {
        Assert.assertEquals(OrekitMessages.OUT_OF_RANGE_EPHEMERIDES_DATE, pe.getSpecifier());
    }
    double shift = -60;
    SpacecraftState s = ephemeris1.propagate(initDate.shiftedBy(shift));
    Assert.assertEquals(2, s.getAdditionalStates().size());
    Assert.assertTrue(s.hasAdditionalState("squaredA"));
    Assert.assertTrue(s.hasAdditionalState("extra"));
    Assert.assertEquals(s.getA() * s.getA(), s.getAdditionalState("squaredA")[0], 1.0e-10);
    Assert.assertEquals(1.5 + shift * rate, s.getAdditionalState("extra")[0], 1.0e-10);
    try {
        ephemeris1.resetInitialState(s);
        Assert.fail("an exception should have been thrown");
    } catch (OrekitException oe) {
        Assert.assertEquals(OrekitMessages.NON_RESETABLE_STATE, oe.getSpecifier());
    }
}
Also used : SpacecraftState(org.orekit.propagation.SpacecraftState) FieldSpacecraftState(org.orekit.propagation.FieldSpacecraftState) AdditionalEquations(org.orekit.propagation.integration.AdditionalEquations) AdditionalStateProvider(org.orekit.propagation.AdditionalStateProvider) OrekitException(org.orekit.errors.OrekitException) BoundedPropagator(org.orekit.propagation.BoundedPropagator) Test(org.junit.Test)

Example 5 with AdditionalStateProvider

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

the class KeplerianPropagatorTest method testNonSerializableStateProvider.

@Test
public void testNonSerializableStateProvider() throws OrekitException, IOException {
    KeplerianPropagator propagator = new KeplerianPropagator(new KeplerianOrbit(7.8e6, 0.032, 0.4, 0.1, 0.2, 0.3, PositionAngle.TRUE, FramesFactory.getEME2000(), AbsoluteDate.J2000_EPOCH, Constants.WGS84_EARTH_MU));
    // this serialization should work
    new ObjectOutputStream(new ByteArrayOutputStream()).writeObject(propagator);
    propagator.addAdditionalStateProvider(new AdditionalStateProvider() {

        public String getName() {
            return "not serializable";
        }

        public double[] getAdditionalState(SpacecraftState state) {
            return new double[] { 0 };
        }
    });
    try {
        // this serialization should not work
        new ObjectOutputStream(new ByteArrayOutputStream()).writeObject(propagator);
        Assert.fail("an exception should have been thrown");
    } catch (NotSerializableException nse) {
    // expected
    }
}
Also used : SpacecraftState(org.orekit.propagation.SpacecraftState) NotSerializableException(java.io.NotSerializableException) AdditionalStateProvider(org.orekit.propagation.AdditionalStateProvider) KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) Test(org.junit.Test)

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