use of org.hipparchus.ode.nonstiff.DormandPrince853Integrator 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;
}
use of org.hipparchus.ode.nonstiff.DormandPrince853Integrator in project Orekit by CS-SI.
the class Phasing method run.
private void run(final File input) throws IOException, IllegalArgumentException, ParseException, OrekitException {
// read input parameters
KeyValueFileParser<ParameterKey> parser = new KeyValueFileParser<ParameterKey>(ParameterKey.class);
try (final FileInputStream fis = new FileInputStream(input)) {
parser.parseInput(input.getAbsolutePath(), fis);
}
TimeScale utc = TimeScalesFactory.getUTC();
// simulation properties
AbsoluteDate date = parser.getDate(ParameterKey.ORBIT_DATE, utc);
int nbOrbits = parser.getInt(ParameterKey.PHASING_ORBITS_NUMBER);
int nbDays = parser.getInt(ParameterKey.PHASING_DAYS_NUMBER);
double latitude = parser.getAngle(ParameterKey.SUN_SYNCHRONOUS_REFERENCE_LATITUDE);
boolean ascending = parser.getBoolean(ParameterKey.SUN_SYNCHRONOUS_REFERENCE_ASCENDING);
double mst = parser.getTime(ParameterKey.SUN_SYNCHRONOUS_MEAN_SOLAR_TIME).getSecondsInUTCDay() / 3600;
int degree = parser.getInt(ParameterKey.GRAVITY_FIELD_DEGREE);
int order = parser.getInt(ParameterKey.GRAVITY_FIELD_ORDER);
String gridOutput = parser.getString(ParameterKey.GRID_OUTPUT);
double[] gridLatitudes = new double[] { parser.getAngle(ParameterKey.GRID_LATITUDE_1), parser.getAngle(ParameterKey.GRID_LATITUDE_2), parser.getAngle(ParameterKey.GRID_LATITUDE_3), parser.getAngle(ParameterKey.GRID_LATITUDE_4), parser.getAngle(ParameterKey.GRID_LATITUDE_5) };
boolean[] gridAscending = new boolean[] { parser.getBoolean(ParameterKey.GRID_ASCENDING_1), parser.getBoolean(ParameterKey.GRID_ASCENDING_2), parser.getBoolean(ParameterKey.GRID_ASCENDING_3), parser.getBoolean(ParameterKey.GRID_ASCENDING_4), parser.getBoolean(ParameterKey.GRID_ASCENDING_5) };
gravityField = GravityFieldFactory.getNormalizedProvider(degree, order);
// initial guess for orbit
CircularOrbit orbit = guessOrbit(date, FramesFactory.getEME2000(), nbOrbits, nbDays, latitude, ascending, mst);
System.out.println("initial orbit: " + orbit);
System.out.println("please wait while orbit is adjusted...");
System.out.println();
// numerical model for improving orbit
double[][] tolerances = NumericalPropagator.tolerances(0.1, orbit, OrbitType.CIRCULAR);
DormandPrince853Integrator integrator = new DormandPrince853Integrator(1.0e-4 * orbit.getKeplerianPeriod(), 1.0e-1 * orbit.getKeplerianPeriod(), tolerances[0], tolerances[1]);
integrator.setInitialStepSize(1.0e-2 * orbit.getKeplerianPeriod());
NumericalPropagator propagator = new NumericalPropagator(integrator);
propagator.addForceModel(new HolmesFeatherstoneAttractionModel(FramesFactory.getGTOD(IERSConventions.IERS_2010, true), gravityField));
propagator.addForceModel(new ThirdBodyAttraction(CelestialBodyFactory.getSun()));
propagator.addForceModel(new ThirdBodyAttraction(CelestialBodyFactory.getMoon()));
double deltaP = Double.POSITIVE_INFINITY;
double deltaV = Double.POSITIVE_INFINITY;
int counter = 0;
DecimalFormat f = new DecimalFormat("0.000E00", new DecimalFormatSymbols(Locale.US));
while (deltaP > 3.0e-1 || deltaV > 3.0e-4) {
CircularOrbit previous = orbit;
CircularOrbit tmp1 = improveEarthPhasing(previous, nbOrbits, nbDays, propagator);
CircularOrbit tmp2 = improveSunSynchronization(tmp1, nbOrbits * tmp1.getKeplerianPeriod(), latitude, ascending, mst, propagator);
orbit = improveFrozenEccentricity(tmp2, nbOrbits * tmp2.getKeplerianPeriod(), propagator);
double da = orbit.getA() - previous.getA();
double dex = orbit.getCircularEx() - previous.getCircularEx();
double dey = orbit.getCircularEy() - previous.getCircularEy();
double di = FastMath.toDegrees(orbit.getI() - previous.getI());
double dr = FastMath.toDegrees(orbit.getRightAscensionOfAscendingNode() - previous.getRightAscensionOfAscendingNode());
System.out.println(" iteration " + (++counter) + ": deltaA = " + f.format(da) + " m, deltaEx = " + f.format(dex) + ", deltaEy = " + f.format(dey) + ", deltaI = " + f.format(di) + " deg, deltaRAAN = " + f.format(dr) + " deg");
PVCoordinates delta = new PVCoordinates(previous.getPVCoordinates(), orbit.getPVCoordinates());
deltaP = delta.getPosition().getNorm();
deltaV = delta.getVelocity().getNorm();
}
// final orbit
System.out.println();
System.out.println("final orbit (osculating): " + orbit);
// generate the ground track grid file
try (PrintStream output = new PrintStream(new File(input.getParent(), gridOutput), "UTF-8")) {
for (int i = 0; i < gridLatitudes.length; ++i) {
printGridPoints(output, gridLatitudes[i], gridAscending[i], orbit, propagator, nbOrbits);
}
}
}
use of org.hipparchus.ode.nonstiff.DormandPrince853Integrator in project Orekit by CS-SI.
the class PropagatorConversion 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));
// gravity field
NormalizedSphericalHarmonicsProvider provider = GravityFieldFactory.getNormalizedProvider(2, 0);
double mu = provider.getMu();
// inertial frame
Frame inertialFrame = FramesFactory.getEME2000();
// Initial date
AbsoluteDate initialDate = new AbsoluteDate(2004, 01, 01, 23, 30, 00.000, TimeScalesFactory.getUTC());
// Initial orbit (GTO)
// 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 ascention of ascending node
final double raan = FastMath.toRadians(261);
// mean anomaly
final double lM = 0;
Orbit initialOrbit = new KeplerianOrbit(a, e, i, omega, raan, lM, PositionAngle.MEAN, inertialFrame, initialDate, mu);
final double period = initialOrbit.getKeplerianPeriod();
// Initial state definition
final SpacecraftState initialState = new SpacecraftState(initialOrbit);
// Adaptive step integrator with a minimum step of 0.001 and a maximum step of 1000
final double minStep = 0.001;
final double maxStep = 1000.;
final double dP = 1.e-2;
final OrbitType orbType = OrbitType.CARTESIAN;
final double[][] tol = NumericalPropagator.tolerances(dP, initialOrbit, orbType);
final AbstractIntegrator integrator = new DormandPrince853Integrator(minStep, maxStep, tol[0], tol[1]);
// Propagator
NumericalPropagator numProp = new NumericalPropagator(integrator);
numProp.setInitialState(initialState);
numProp.setOrbitType(orbType);
// Force Models:
// 1 - Perturbing gravity field (only J2 is considered here)
ForceModel gravity = new HolmesFeatherstoneAttractionModel(FramesFactory.getITRF(IERSConventions.IERS_2010, true), provider);
// Add force models to the propagator
numProp.addForceModel(gravity);
// Propagator factory
PropagatorBuilder builder = new KeplerianPropagatorBuilder(initialOrbit, PositionAngle.TRUE, dP);
// Propagator converter
PropagatorConverter fitter = new FiniteDifferencePropagatorConverter(builder, 1.e-6, 5000);
// Resulting propagator
KeplerianPropagator kepProp = (KeplerianPropagator) fitter.convert(numProp, 2 * period, 251);
// Step handlers
StatesHandler numStepHandler = new StatesHandler();
StatesHandler kepStepHandler = new StatesHandler();
// Set up operating mode for the propagator as master mode
// with fixed step and specialized step handler
numProp.setMasterMode(60., numStepHandler);
kepProp.setMasterMode(60., kepStepHandler);
// Extrapolate from the initial to the final date
numProp.propagate(initialDate.shiftedBy(10. * period));
kepProp.propagate(initialDate.shiftedBy(10. * period));
// retrieve the states
List<SpacecraftState> numStates = numStepHandler.getStates();
List<SpacecraftState> kepStates = kepStepHandler.getStates();
// Print the results on the output file
File output = new File(new File(System.getProperty("user.home")), "elements.dat");
try (final PrintStream stream = new PrintStream(output, "UTF-8")) {
stream.println("# date Anum Akep Enum Ekep Inum Ikep LMnum LMkep");
for (SpacecraftState numState : numStates) {
for (SpacecraftState kepState : kepStates) {
if (numState.getDate().compareTo(kepState.getDate()) == 0) {
stream.println(numState.getDate() + " " + numState.getA() + " " + kepState.getA() + " " + numState.getE() + " " + kepState.getE() + " " + FastMath.toDegrees(numState.getI()) + " " + FastMath.toDegrees(kepState.getI()) + " " + FastMath.toDegrees(MathUtils.normalizeAngle(numState.getLM(), FastMath.PI)) + " " + FastMath.toDegrees(MathUtils.normalizeAngle(kepState.getLM(), FastMath.PI)));
break;
}
}
}
}
System.out.println("Results saved as file " + output);
File output1 = new File(new File(System.getProperty("user.home")), "elts_pv.dat");
try (final PrintStream stream = new PrintStream(output1, "UTF-8")) {
stream.println("# date pxn pyn pzn vxn vyn vzn pxk pyk pzk vxk vyk vzk");
for (SpacecraftState numState : numStates) {
for (SpacecraftState kepState : kepStates) {
if (numState.getDate().compareTo(kepState.getDate()) == 0) {
final double pxn = numState.getPVCoordinates().getPosition().getX();
final double pyn = numState.getPVCoordinates().getPosition().getY();
final double pzn = numState.getPVCoordinates().getPosition().getZ();
final double vxn = numState.getPVCoordinates().getVelocity().getX();
final double vyn = numState.getPVCoordinates().getVelocity().getY();
final double vzn = numState.getPVCoordinates().getVelocity().getZ();
final double pxk = kepState.getPVCoordinates().getPosition().getX();
final double pyk = kepState.getPVCoordinates().getPosition().getY();
final double pzk = kepState.getPVCoordinates().getPosition().getZ();
final double vxk = kepState.getPVCoordinates().getVelocity().getX();
final double vyk = kepState.getPVCoordinates().getVelocity().getY();
final double vzk = kepState.getPVCoordinates().getVelocity().getZ();
stream.println(numState.getDate() + " " + pxn + " " + pyn + " " + pzn + " " + vxn + " " + vyn + " " + vzn + " " + pxk + " " + pyk + " " + pzk + " " + vxk + " " + vyk + " " + vzk);
break;
}
}
}
}
System.out.println("Results saved as file " + output1);
} catch (OrekitException oe) {
System.err.println(oe.getLocalizedMessage());
System.exit(1);
} catch (IOException ioe) {
System.err.println(ioe.getLocalizedMessage());
System.exit(1);
}
}
use of org.hipparchus.ode.nonstiff.DormandPrince853Integrator in project Orekit by CS-SI.
the class DSSTPropagation method createDSSTProp.
/**
* Set up the DSST Propagator
*
* @param orbit initial orbit
* @param mass S/C mass (kg)
* @param initialIsOsculating if initial orbital elements are osculating
* @param outputIsOsculating if we want to output osculating parameters
* @param fixedStepSize step size for fixed step integrator (s)
* @param minStep minimum step size, if step is not fixed (s)
* @param maxStep maximum step size, if step is not fixed (s)
* @param dP position tolerance for step size control, if step is not fixed (m)
* @param shortPeriodCoefficients list of short periodic coefficients
* to output (null means no coefficients at all, empty list means all
* possible coefficients)
* @throws OrekitException
*/
private DSSTPropagator createDSSTProp(final Orbit orbit, final double mass, final boolean initialIsOsculating, final boolean outputIsOsculating, final double fixedStepSize, final double minStep, final double maxStep, final double dP, final List<String> shortPeriodCoefficients) throws OrekitException {
AbstractIntegrator integrator;
if (fixedStepSize > 0.) {
integrator = new ClassicalRungeKuttaIntegrator(fixedStepSize);
} else {
final double[][] tol = DSSTPropagator.tolerances(dP, orbit);
integrator = new DormandPrince853Integrator(minStep, maxStep, tol[0], tol[1]);
((AdaptiveStepsizeIntegrator) integrator).setInitialStepSize(10. * minStep);
}
DSSTPropagator dsstProp = new DSSTPropagator(integrator, !outputIsOsculating);
dsstProp.setInitialState(new SpacecraftState(orbit, mass), initialIsOsculating);
dsstProp.setSelectedCoefficients(shortPeriodCoefficients == null ? null : new HashSet<String>(shortPeriodCoefficients));
return dsstProp;
}
use of org.hipparchus.ode.nonstiff.DormandPrince853Integrator in project Orekit by CS-SI.
the class DSSTPropagation method createNumProp.
/**
* Create the numerical propagator
*
* @param orbit initial orbit
* @param mass S/C mass (kg)
* @throws OrekitException
*/
private NumericalPropagator createNumProp(final Orbit orbit, final double mass) throws OrekitException {
final double[][] tol = NumericalPropagator.tolerances(1.0, orbit, orbit.getType());
final double minStep = 1.e-3;
final double maxStep = 1.e+3;
AdaptiveStepsizeIntegrator integrator = new DormandPrince853Integrator(minStep, maxStep, tol[0], tol[1]);
integrator.setInitialStepSize(100.);
NumericalPropagator numProp = new NumericalPropagator(integrator);
numProp.setInitialState(new SpacecraftState(orbit, mass));
return numProp;
}
Aggregations