use of org.orekit.propagation.BoundedPropagator in project Orekit by CS-SI.
the class EcksteinHechlerPropagatorTest method testIssue224Forward.
@Test
public void testIssue224Forward() throws OrekitException, IOException, ClassNotFoundException {
AbsoluteDate date = AbsoluteDate.J2000_EPOCH.shiftedBy(154.);
Frame itrf = FramesFactory.getITRF(IERSConventions.IERS_2010, true);
Frame eme2000 = FramesFactory.getEME2000();
Vector3D pole = itrf.getTransformTo(eme2000, date).transformVector(Vector3D.PLUS_K);
Frame poleAligned = new Frame(FramesFactory.getEME2000(), new Transform(date, new Rotation(pole, Vector3D.PLUS_K)), "pole aligned", true);
CircularOrbit initial = new CircularOrbit(7208669.8179538045, 1.3740461966386876E-4, -3.2364250248363356E-5, FastMath.toRadians(97.40236024565775), FastMath.toRadians(166.15873160992115), FastMath.toRadians(90.1282370098961), PositionAngle.MEAN, poleAligned, date, provider.getMu());
EcksteinHechlerPropagator propagator = new EcksteinHechlerPropagator(initial, new LofOffset(poleAligned, LOFType.VVLH), 1000.0, provider);
propagator.addAdditionalStateProvider(new SevenProvider());
propagator.setEphemerisMode();
// Impulsive burns
final AbsoluteDate burn1Date = initial.getDate().shiftedBy(200);
ImpulseManeuver<DateDetector> impulsiveBurn1 = new ImpulseManeuver<DateDetector>(new DateDetector(burn1Date), new Vector3D(0.0, 500.0, 0.0), 320);
propagator.addEventDetector(impulsiveBurn1);
final AbsoluteDate burn2Date = initial.getDate().shiftedBy(300);
ImpulseManeuver<DateDetector> impulsiveBurn2 = new ImpulseManeuver<DateDetector>(new DateDetector(burn2Date), new Vector3D(0.0, 500.0, 0.0), 320);
propagator.addEventDetector(impulsiveBurn2);
propagator.propagate(initial.getDate().shiftedBy(400));
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(propagator.getGeneratedEphemeris());
Assert.assertTrue(bos.size() > 2950);
Assert.assertTrue(bos.size() < 3050);
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bis);
BoundedPropagator ephemeris = (BoundedPropagator) ois.readObject();
ephemeris.setMasterMode(10, new OrekitFixedStepHandler() {
public void handleStep(SpacecraftState currentState, boolean isLast) {
if (currentState.getDate().durationFrom(burn1Date) < -0.001) {
Assert.assertEquals(97.402, FastMath.toDegrees(currentState.getI()), 1.0e-3);
} else if (currentState.getDate().durationFrom(burn1Date) > 0.001 && currentState.getDate().durationFrom(burn2Date) < -0.001) {
Assert.assertEquals(98.183, FastMath.toDegrees(currentState.getI()), 1.0e-3);
} else if (currentState.getDate().durationFrom(burn2Date) > 0.001) {
Assert.assertEquals(99.310, FastMath.toDegrees(currentState.getI()), 1.0e-3);
}
}
});
ephemeris.propagate(ephemeris.getMaxDate());
}
use of org.orekit.propagation.BoundedPropagator in project Orekit by CS-SI.
the class AggregateBoundedPropagatorTest method testGap.
/**
* Check {@link AggregateBoundedPropagator#propagateOrbit(AbsoluteDate)} with a gap
* between the constituent propagators.
*
* @throws Exception on error.
*/
@Test
public void testGap() throws Exception {
// setup
AbsoluteDate date = AbsoluteDate.CCSDS_EPOCH;
BoundedPropagator p1 = createPropagator(date, date.shiftedBy(1), 0);
BoundedPropagator p2 = createPropagator(date.shiftedBy(10), date.shiftedBy(20), 1);
// action
BoundedPropagator actual = new AggregateBoundedPropagator(Arrays.asList(p1, p2));
// verify
int ulps = 0;
Assert.assertThat(actual.getFrame(), CoreMatchers.is(p1.getFrame()));
Assert.assertThat(actual.getMinDate(), CoreMatchers.is(date));
Assert.assertThat(actual.getMaxDate(), CoreMatchers.is(date.shiftedBy(20)));
Assert.assertThat(actual.propagate(date).getPVCoordinates(), OrekitMatchers.pvCloseTo(p1.propagate(date).getPVCoordinates(), ulps));
Assert.assertThat(actual.propagate(date.shiftedBy(10)).getPVCoordinates(), OrekitMatchers.pvCloseTo(p2.propagate(date.shiftedBy(10)).getPVCoordinates(), ulps));
Assert.assertThat(actual.propagate(date.shiftedBy(15)).getPVCoordinates(), OrekitMatchers.pvCloseTo(p2.propagate(date.shiftedBy(15)).getPVCoordinates(), ulps));
Assert.assertThat(actual.propagate(date.shiftedBy(20)).getPVCoordinates(), OrekitMatchers.pvCloseTo(p2.propagate(date.shiftedBy(20)).getPVCoordinates(), ulps));
try {
// may or may not throw an exception depending on the type of propagator.
Assert.assertThat(actual.propagate(date.shiftedBy(5)).getPVCoordinates(), OrekitMatchers.pvCloseTo(p1.propagate(date.shiftedBy(5)).getPVCoordinates(), ulps));
} catch (OrekitException e) {
// expected
}
}
use of org.orekit.propagation.BoundedPropagator in project Orekit by CS-SI.
the class AggregateBoundedPropagatorTest method testResetState.
/**
* Check that resetting the state is prohibited.
*
* @throws OrekitException on error.
*/
@Test
public void testResetState() throws OrekitException {
// setup
AbsoluteDate date = AbsoluteDate.CCSDS_EPOCH;
BoundedPropagator p1 = createPropagator(date, date.shiftedBy(10), 0);
BoundedPropagator p2 = createPropagator(date.shiftedBy(10), date.shiftedBy(20), 1);
SpacecraftState ic = p2.getInitialState();
// action
BoundedPropagator actual = new AggregateBoundedPropagator(Arrays.asList(p1, p2));
// verify
try {
actual.resetInitialState(ic);
Assert.fail("Expected Exception");
} catch (OrekitException e) {
// expected
}
}
use of org.orekit.propagation.BoundedPropagator in project Orekit by CS-SI.
the class DSSTPropagation method run.
private void run(final File input, final File output) throws IOException, IllegalArgumentException, OrekitException, ParseException {
// read input parameters
KeyValueFileParser<ParameterKey> parser = new KeyValueFileParser<ParameterKey>(ParameterKey.class);
try (final FileInputStream fis = new FileInputStream(input)) {
parser.parseInput(input.getAbsolutePath(), fis);
}
// check mandatory input parameters
if (!parser.containsKey(ParameterKey.ORBIT_DATE)) {
throw new IOException("Orbit date is not defined.");
}
if (!parser.containsKey(ParameterKey.DURATION) && !parser.containsKey(ParameterKey.DURATION_IN_DAYS)) {
throw new IOException("Propagation duration is not defined.");
}
// All dates in UTC
final TimeScale utc = TimeScalesFactory.getUTC();
final double rotationRate;
if (!parser.containsKey(ParameterKey.CENTRAL_BODY_ROTATION_RATE)) {
rotationRate = Constants.WGS84_EARTH_ANGULAR_VELOCITY;
} else {
rotationRate = parser.getDouble(ParameterKey.CENTRAL_BODY_ROTATION_RATE);
}
final int degree = parser.getInt(ParameterKey.CENTRAL_BODY_DEGREE);
final int order = FastMath.min(degree, parser.getInt(ParameterKey.CENTRAL_BODY_ORDER));
// Potential coefficients providers
final UnnormalizedSphericalHarmonicsProvider unnormalized = GravityFieldFactory.getConstantUnnormalizedProvider(degree, order);
final NormalizedSphericalHarmonicsProvider normalized = GravityFieldFactory.getConstantNormalizedProvider(degree, order);
// Central body attraction coefficient (m³/s²)
final double mu = unnormalized.getMu();
// Earth frame definition
final Frame earthFrame;
if (!parser.containsKey(ParameterKey.BODY_FRAME)) {
earthFrame = FramesFactory.getITRF(IERSConventions.IERS_2010, true);
} else {
earthFrame = parser.getEarthFrame(ParameterKey.BODY_FRAME);
}
// Orbit definition
final Orbit orbit = createOrbit(parser, utc, mu);
// DSST propagator definition
double mass = 1000.0;
if (parser.containsKey(ParameterKey.MASS)) {
mass = parser.getDouble(ParameterKey.MASS);
}
boolean initialIsOsculating = false;
if (parser.containsKey(ParameterKey.INITIAL_ORBIT_IS_OSCULATING)) {
initialIsOsculating = parser.getBoolean(ParameterKey.INITIAL_ORBIT_IS_OSCULATING);
}
boolean outputIsOsculating = initialIsOsculating;
if (parser.containsKey(ParameterKey.OUTPUT_ORBIT_IS_OSCULATING)) {
outputIsOsculating = parser.getBoolean(ParameterKey.OUTPUT_ORBIT_IS_OSCULATING);
}
List<String> shortPeriodCoefficients = null;
if (parser.containsKey(ParameterKey.OUTPUT_SHORT_PERIOD_COEFFICIENTS)) {
shortPeriodCoefficients = parser.getStringsList(ParameterKey.OUTPUT_SHORT_PERIOD_COEFFICIENTS, ',');
if (shortPeriodCoefficients.size() == 1 && shortPeriodCoefficients.get(0).equalsIgnoreCase("all")) {
// special case, we use the empty list to represent all possible (unknown) keys
// we don't use Collections.emptyList() because we want the list to be populated later on
shortPeriodCoefficients = new ArrayList<String>();
} else if (shortPeriodCoefficients.size() == 1 && shortPeriodCoefficients.get(0).equalsIgnoreCase("none")) {
// special case, we use null to select no coefficients at all
shortPeriodCoefficients = null;
} else {
// general case, we have an explicit list of coefficients names
Collections.sort(shortPeriodCoefficients);
}
if (shortPeriodCoefficients != null && !outputIsOsculating) {
System.out.println("\nWARNING:");
System.out.println("Short periodic coefficients can be output only if output orbit is osculating.");
System.out.println("No coefficients will be computed here.\n");
}
}
double fixedStepSize = -1.;
double minStep = 6000.0;
double maxStep = 86400.0;
double dP = 1.0;
if (parser.containsKey(ParameterKey.FIXED_INTEGRATION_STEP)) {
fixedStepSize = parser.getDouble(ParameterKey.FIXED_INTEGRATION_STEP);
} else {
if (parser.containsKey(ParameterKey.MIN_VARIABLE_INTEGRATION_STEP)) {
minStep = parser.getDouble(ParameterKey.MIN_VARIABLE_INTEGRATION_STEP);
}
if (parser.containsKey(ParameterKey.MAX_VARIABLE_INTEGRATION_STEP)) {
maxStep = parser.getDouble(ParameterKey.MAX_VARIABLE_INTEGRATION_STEP);
}
if (parser.containsKey(ParameterKey.POSITION_TOLERANCE_VARIABLE_INTEGRATION_STEP)) {
dP = parser.getDouble(ParameterKey.POSITION_TOLERANCE_VARIABLE_INTEGRATION_STEP);
}
}
final DSSTPropagator dsstProp = createDSSTProp(orbit, mass, initialIsOsculating, outputIsOsculating, fixedStepSize, minStep, maxStep, dP, shortPeriodCoefficients);
if (parser.containsKey(ParameterKey.FIXED_NUMBER_OF_INTERPOLATION_POINTS)) {
if (parser.containsKey(ParameterKey.MAX_TIME_GAP_BETWEEN_INTERPOLATION_POINTS)) {
throw new OrekitException(LocalizedCoreFormats.SIMPLE_MESSAGE, "cannot specify both fixed.number.of.interpolation.points" + " and max.time.gap.between.interpolation.points");
}
dsstProp.setInterpolationGridToFixedNumberOfPoints(parser.getInt(ParameterKey.FIXED_NUMBER_OF_INTERPOLATION_POINTS));
} else if (parser.containsKey(ParameterKey.MAX_TIME_GAP_BETWEEN_INTERPOLATION_POINTS)) {
dsstProp.setInterpolationGridToMaxTimeGap(parser.getDouble(ParameterKey.MAX_TIME_GAP_BETWEEN_INTERPOLATION_POINTS));
} else {
dsstProp.setInterpolationGridToFixedNumberOfPoints(3);
}
// Set Force models
setForceModel(parser, unnormalized, earthFrame, rotationRate, dsstProp);
// Simulation properties
AbsoluteDate start;
if (parser.containsKey(ParameterKey.START_DATE)) {
start = parser.getDate(ParameterKey.START_DATE, utc);
} else {
start = parser.getDate(ParameterKey.ORBIT_DATE, utc);
}
double duration = 0.;
if (parser.containsKey(ParameterKey.DURATION)) {
duration = parser.getDouble(ParameterKey.DURATION);
}
if (parser.containsKey(ParameterKey.DURATION_IN_DAYS)) {
duration = parser.getDouble(ParameterKey.DURATION_IN_DAYS) * Constants.JULIAN_DAY;
}
double outStep = parser.getDouble(ParameterKey.OUTPUT_STEP);
boolean displayKeplerian = true;
if (parser.containsKey(ParameterKey.OUTPUT_KEPLERIAN)) {
displayKeplerian = parser.getBoolean(ParameterKey.OUTPUT_KEPLERIAN);
}
boolean displayEquinoctial = true;
if (parser.containsKey(ParameterKey.OUTPUT_EQUINOCTIAL)) {
displayEquinoctial = parser.getBoolean(ParameterKey.OUTPUT_EQUINOCTIAL);
}
boolean displayCartesian = true;
if (parser.containsKey(ParameterKey.OUTPUT_CARTESIAN)) {
displayCartesian = parser.getBoolean(ParameterKey.OUTPUT_CARTESIAN);
}
// DSST Propagation
dsstProp.setEphemerisMode();
final double dsstOn = System.currentTimeMillis();
dsstProp.propagate(start, start.shiftedBy(duration));
final double dsstOff = System.currentTimeMillis();
System.out.println("DSST execution time (without large file write) : " + (dsstOff - dsstOn) / 1000.);
System.out.println("writing file...");
final BoundedPropagator dsstEphem = dsstProp.getGeneratedEphemeris();
dsstEphem.setMasterMode(outStep, new OutputHandler(output, displayKeplerian, displayEquinoctial, displayCartesian, shortPeriodCoefficients));
dsstEphem.propagate(start, start.shiftedBy(duration));
System.out.println("DSST results saved as file " + output);
// Check if we want to compare numerical to DSST propagator (default is false)
if (parser.containsKey(ParameterKey.NUMERICAL_COMPARISON) && parser.getBoolean(ParameterKey.NUMERICAL_COMPARISON)) {
if (!outputIsOsculating) {
System.out.println("\nWARNING:");
System.out.println("The DSST propagator considers a mean orbit while the numerical will consider an osculating one.");
System.out.println("The comparison will be meaningless.\n");
}
// Numerical propagator definition
final NumericalPropagator numProp = createNumProp(orbit, mass);
// Set Force models
setForceModel(parser, normalized, earthFrame, numProp);
// Numerical Propagation without output
numProp.setEphemerisMode();
final double numOn = System.currentTimeMillis();
numProp.propagate(start, start.shiftedBy(duration));
final double numOff = System.currentTimeMillis();
System.out.println("Numerical execution time (including output): " + (numOff - numOn) / 1000.);
// Add output
final BoundedPropagator numEphemeris = numProp.getGeneratedEphemeris();
File numOutput = new File(input.getParentFile(), "numerical-propagation.out");
numEphemeris.setMasterMode(outStep, new OutputHandler(numOutput, displayKeplerian, displayEquinoctial, displayCartesian, null));
System.out.println("Writing file, this may take some time ...");
numEphemeris.propagate(numEphemeris.getMaxDate());
System.out.println("Numerical results saved as file " + numOutput);
}
}
use of org.orekit.propagation.BoundedPropagator in project Orekit by CS-SI.
the class EphemerisMode method main.
/**
* Program entry point.
* @param args program arguments (unused here)
*/
public static void main(String[] args) {
try {
// configure Orekit
File home = new File(System.getProperty("user.home"));
File orekitData = new File(home, "orekit-data");
if (!orekitData.exists()) {
System.err.format(Locale.US, "Failed to find %s folder%n", orekitData.getAbsolutePath());
System.err.format(Locale.US, "You need to download %s from the %s page and unzip it in %s for this tutorial to work%n", "orekit-data.zip", "https://www.orekit.org/forge/projects/orekit/files", home.getAbsolutePath());
System.exit(1);
}
DataProvidersManager manager = DataProvidersManager.getInstance();
manager.addProvider(new DirectoryCrawler(orekitData));
// Initial orbit parameters
// semi major axis in meters
double a = 24396159;
// eccentricity
double e = 0.72831215;
// inclination
double i = FastMath.toRadians(7);
// perigee argument
double omega = FastMath.toRadians(180);
// right ascension of ascending node
double raan = FastMath.toRadians(261);
// mean anomaly
double lM = 0;
// Inertial frame
Frame inertialFrame = FramesFactory.getEME2000();
// Initial date in UTC time scale
TimeScale utc = TimeScalesFactory.getUTC();
AbsoluteDate initialDate = new AbsoluteDate(2004, 01, 01, 23, 30, 00.000, utc);
// gravitation coefficient
double mu = 3.986004415e+14;
// Orbit construction as Keplerian
Orbit initialOrbit = new KeplerianOrbit(a, e, i, omega, raan, lM, PositionAngle.MEAN, inertialFrame, initialDate, mu);
// Initialize state
SpacecraftState initialState = new SpacecraftState(initialOrbit);
// Numerical propagation with no perturbation (only Keplerian movement)
// Using a very simple integrator with a fixed step: classical Runge-Kutta
// the step is ten seconds
double stepSize = 10;
AbstractIntegrator integrator = new ClassicalRungeKuttaIntegrator(stepSize);
NumericalPropagator propagator = new NumericalPropagator(integrator);
// Set the propagator to ephemeris mode
propagator.setEphemerisMode();
// Initialize propagation
propagator.setInitialState(initialState);
// Propagation with storage of the results in an integrated ephemeris
SpacecraftState finalState = propagator.propagate(initialDate.shiftedBy(6000));
System.out.println(" Numerical propagation :");
System.out.println(" Final date : " + finalState.getDate());
System.out.println(" " + finalState.getOrbit());
// Getting the integrated ephemeris
BoundedPropagator ephemeris = propagator.getGeneratedEphemeris();
System.out.println(" Ephemeris defined from " + ephemeris.getMinDate() + " to " + ephemeris.getMaxDate());
System.out.println(" Ephemeris propagation :");
AbsoluteDate intermediateDate = initialDate.shiftedBy(3000);
SpacecraftState intermediateState = ephemeris.propagate(intermediateDate);
System.out.println(" date : " + intermediateState.getDate());
System.out.println(" " + intermediateState.getOrbit());
intermediateDate = finalState.getDate();
intermediateState = ephemeris.propagate(intermediateDate);
System.out.println(" date : " + intermediateState.getDate());
System.out.println(" " + intermediateState.getOrbit());
intermediateDate = initialDate.shiftedBy(-1000);
System.out.println();
System.out.println("Attempting to propagate to date " + intermediateDate + " which is OUT OF RANGE");
System.out.println("This propagation attempt should fail, " + "so an error message shoud appear below, " + "this is expected and shows that errors are handled correctly");
intermediateState = ephemeris.propagate(intermediateDate);
// these two print should never happen as en exception should have been triggered
System.out.println(" date : " + intermediateState.getDate());
System.out.println(" " + intermediateState.getOrbit());
} catch (OrekitException oe) {
System.out.println(oe.getMessage());
}
}
Aggregations