use of org.orekit.errors.OrekitException in project Orekit by CS-SI.
the class FieldNumericalPropagatorTest method doTestException.
private <T extends RealFieldElement<T>> void doTestException(Field<T> field) throws OrekitException {
T zero = field.getZero();
// setup
final FieldAbsoluteDate<T> initDate = FieldAbsoluteDate.getJ2000Epoch(field);
FieldSpacecraftState<T> initialState;
FieldNumericalPropagator<T> propagator;
final FieldVector3D<T> position = new FieldVector3D<>(zero.add(7.0e6), zero.add(1.0e6), zero.add(4.0e6));
final FieldVector3D<T> velocity = new FieldVector3D<>(zero.add(-500.0), zero.add(8000.0), zero.add(1000.0));
final FieldOrbit<T> orbit = new FieldEquinoctialOrbit<>(new FieldPVCoordinates<>(position, velocity), FramesFactory.getEME2000(), initDate, mu);
initialState = new FieldSpacecraftState<>(orbit);
OrbitType type = OrbitType.EQUINOCTIAL;
double[][] tolerance = NumericalPropagator.tolerances(0.001, orbit.toOrbit(), type);
AdaptiveStepsizeFieldIntegrator<T> integrator = new DormandPrince853FieldIntegrator<>(field, 0.001, 200, tolerance[0], tolerance[1]);
integrator.setInitialStepSize(zero.add(60));
propagator = new FieldNumericalPropagator<>(field, integrator);
propagator.setOrbitType(type);
propagator.setInitialState(initialState);
propagator.setMasterMode(new FieldOrekitStepHandler<T>() {
private int countDown = 3;
private FieldAbsoluteDate<T> previousCall = null;
public void init(FieldSpacecraftState<T> s0, FieldAbsoluteDate<T> t) {
}
public void handleStep(FieldOrekitStepInterpolator<T> interpolator, boolean isLast) throws OrekitException {
if (previousCall != null) {
System.out.println(interpolator.getCurrentState().getDate().compareTo(previousCall) < 0);
}
if (--countDown == 0) {
throw new OrekitException(LocalizedCoreFormats.SIMPLE_MESSAGE, "dummy error");
}
}
});
propagator.propagate(initDate.shiftedBy(-3600));
}
use of org.orekit.errors.OrekitException in project Orekit by CS-SI.
the class NumericalPropagatorTest method testParallelismIssue258.
@Test
public void testParallelismIssue258() throws OrekitException, InterruptedException, ExecutionException, FileNotFoundException {
Utils.setDataRoot("regular-data:atmosphere:potential/grgs-format");
GravityFieldFactory.addPotentialCoefficientsReader(new GRGSFormatReader("grim4s4_gr", true));
final double mu = GravityFieldFactory.getNormalizedProvider(2, 2).getMu();
// Geostationary transfer orbit
// semi major axis in meters
final double a = 24396159;
// eccentricity
final double e = 0.72831215;
// inclination
final double i = FastMath.toRadians(7);
// perigee argument
final double omega = FastMath.toRadians(180);
// right ascension of ascending node
final double raan = FastMath.toRadians(261);
// mean anomaly
final double lM = 0;
final Frame inertialFrame = FramesFactory.getEME2000();
final TimeScale utc = TimeScalesFactory.getUTC();
final AbsoluteDate initialDate = new AbsoluteDate(2003, 1, 1, 00, 00, 00.000, utc);
final Orbit initialOrbit = new CartesianOrbit(new KeplerianOrbit(a, e, i, omega, raan, lM, PositionAngle.MEAN, inertialFrame, initialDate, mu));
final SpacecraftState initialState = new SpacecraftState(initialOrbit, 1000);
// initialize the testing points
final List<SpacecraftState> states = new ArrayList<SpacecraftState>();
final NumericalPropagator propagator = createPropagator(initialState, OrbitType.CARTESIAN, PositionAngle.TRUE);
final double samplingStep = 10000.0;
propagator.setMasterMode(samplingStep, (state, isLast) -> states.add(state));
propagator.propagate(initialDate.shiftedBy(5 * samplingStep));
// compute reference errors, using serial computation in a for loop
final double[][] referenceErrors = new double[states.size() - 1][];
for (int startIndex = 0; startIndex < states.size() - 1; ++startIndex) {
referenceErrors[startIndex] = recomputeFollowing(startIndex, states);
}
final Consumer<SpacecraftState> checker = point -> {
try {
final int startIndex = states.indexOf(point);
double[] errors = recomputeFollowing(startIndex, states);
for (int k = 0; k < errors.length; ++k) {
Assert.assertEquals(startIndex + " to " + (startIndex + k + 1), referenceErrors[startIndex][k], errors[k], 1.0e-9);
}
} catch (OrekitException oe) {
Assert.fail(oe.getLocalizedMessage());
}
};
// serial propagation using Stream
states.stream().forEach(checker);
// parallel propagation using parallelStream
states.parallelStream().forEach(checker);
}
use of org.orekit.errors.OrekitException in project Orekit by CS-SI.
the class NumericalPropagatorTest method testIssue157.
@Test
public void testIssue157() throws OrekitException {
try {
Orbit orbit = new KeplerianOrbit(13378000, 0.05, 0, 0, FastMath.PI, 0, PositionAngle.MEAN, FramesFactory.getTOD(false), new AbsoluteDate(2003, 5, 6, TimeScalesFactory.getUTC()), Constants.EIGEN5C_EARTH_MU);
NumericalPropagator.tolerances(1.0, orbit, OrbitType.KEPLERIAN);
Assert.fail("an exception should have been thrown");
} catch (OrekitException pe) {
Assert.assertEquals(OrekitMessages.SINGULAR_JACOBIAN_FOR_ORBIT_TYPE, pe.getSpecifier());
}
}
use of org.orekit.errors.OrekitException 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.errors.OrekitException in project Orekit by CS-SI.
the class PartialDerivativesTest method testWrongParametersDimension.
@Test
public void testWrongParametersDimension() throws OrekitException {
Orbit initialOrbit = new KeplerianOrbit(8000000.0, 0.01, 0.1, 0.7, 0, 1.2, PositionAngle.TRUE, FramesFactory.getEME2000(), AbsoluteDate.J2000_EPOCH, Constants.EIGEN5C_EARTH_MU);
double dP = 0.001;
ForceModel sunAttraction = new ThirdBodyAttraction(CelestialBodyFactory.getSun());
sunAttraction.getParameterDriver("Sun attraction coefficient").setSelected(true);
ForceModel moonAttraction = new ThirdBodyAttraction(CelestialBodyFactory.getMoon());
NumericalPropagator propagator = setUpPropagator(initialOrbit, dP, OrbitType.EQUINOCTIAL, PositionAngle.TRUE, sunAttraction, moonAttraction);
PartialDerivativesEquations partials = new PartialDerivativesEquations("partials", propagator);
try {
partials.setInitialJacobians(new SpacecraftState(initialOrbit), new double[6][6], new double[6][3]);
partials.computeDerivatives(new SpacecraftState(initialOrbit), new double[6]);
Assert.fail("an exception should have been thrown");
} catch (OrekitException oe) {
Assert.assertEquals(OrekitMessages.INITIAL_MATRIX_AND_PARAMETERS_NUMBER_MISMATCH, oe.getSpecifier());
}
}
Aggregations