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);
}
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);
}
}
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()]));
}
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());
}
}
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
}
}
Aggregations