use of org.orekit.propagation.SpacecraftState in project Orekit by CS-SI.
the class Phasing method findLatitudeCrossing.
/**
* Find the state at which the reference latitude is crossed.
* @param latitude latitude to search for
* @param guessDate guess date for the crossing
* @param endDate maximal date not to overtake
* @param shift shift value used to evaluate the latitude function bracketing around the guess date
* @param maxShift maximum value that the shift value can take
* @param propagator propagator used
* @return state at latitude crossing time
* @throws OrekitException if state cannot be propagated
* @throws MathRuntimeException if latitude cannot be bracketed in the search interval
*/
private SpacecraftState findLatitudeCrossing(final double latitude, final AbsoluteDate guessDate, final AbsoluteDate endDate, final double shift, final double maxShift, final Propagator propagator) throws OrekitException, MathRuntimeException {
// function evaluating to 0 at latitude crossings
final UnivariateFunction latitudeFunction = new UnivariateFunction() {
/**
* {@inheritDoc}
*/
public double value(double x) {
try {
final SpacecraftState state = propagator.propagate(guessDate.shiftedBy(x));
final Vector3D position = state.getPVCoordinates(earth.getBodyFrame()).getPosition();
final GeodeticPoint point = earth.transform(position, earth.getBodyFrame(), state.getDate());
return point.getLatitude() - latitude;
} catch (OrekitException oe) {
throw new RuntimeException(oe);
}
}
};
// try to bracket the encounter
double span;
if (guessDate.shiftedBy(shift).compareTo(endDate) > 0) {
// Take a 1e-3 security margin
span = endDate.durationFrom(guessDate) - 1e-3;
} else {
span = shift;
}
while (!UnivariateSolverUtils.isBracketing(latitudeFunction, -span, span)) {
if (2 * span > maxShift) {
// let the Hipparchus exception be thrown
UnivariateSolverUtils.verifyBracketing(latitudeFunction, -span, span);
} else if (guessDate.shiftedBy(2 * span).compareTo(endDate) > 0) {
// Out of range :
return null;
}
// expand the search interval
span *= 2;
}
// find the encounter in the bracketed interval
final BaseUnivariateSolver<UnivariateFunction> solver = new BracketingNthOrderBrentSolver(0.1, 5);
final double dt = solver.solve(1000, latitudeFunction, -span, span);
return propagator.propagate(guessDate.shiftedBy(dt));
}
use of org.orekit.propagation.SpacecraftState in project Orekit by CS-SI.
the class SecularAndHarmonicTest method createPropagator.
private NumericalPropagator createPropagator(CircularOrbit orbit) throws OrekitException {
OrbitType type = OrbitType.CIRCULAR;
double[][] tolerances = NumericalPropagator.tolerances(0.1, orbit, type);
DormandPrince853Integrator integrator = new DormandPrince853Integrator(1.0, 600, tolerances[0], tolerances[1]);
integrator.setInitialStepSize(60.0);
NumericalPropagator propagator = new NumericalPropagator(integrator);
propagator.addForceModel(new HolmesFeatherstoneAttractionModel(earth.getBodyFrame(), gravityField));
propagator.addForceModel(new ThirdBodyAttraction(CelestialBodyFactory.getSun()));
propagator.addForceModel(new ThirdBodyAttraction(CelestialBodyFactory.getMoon()));
propagator.setOrbitType(type);
propagator.resetInitialState(new SpacecraftState(orbit));
return propagator;
}
use of org.orekit.propagation.SpacecraftState in project Orekit by CS-SI.
the class OrekitStepHandlerTest method testIsInterpolated.
/**
* Check {@link OrekitStepInterpolator#isPreviousStateInterpolated()} and {@link
* OrekitStepInterpolator#isCurrentStateInterpolated()}.
*
* @throws OrekitException on error.
*/
@Test
public void testIsInterpolated() throws OrekitException {
// setup
NumericalPropagator propagator = new NumericalPropagator(new ClassicalRungeKuttaIntegrator(60));
AbsoluteDate date = AbsoluteDate.J2000_EPOCH;
Frame eci = FramesFactory.getGCRF();
SpacecraftState ic = new SpacecraftState(new KeplerianOrbit(6378137 + 500e3, 1e-3, 0, 0, 0, 0, PositionAngle.TRUE, eci, date, Constants.EIGEN5C_EARTH_MU));
propagator.setInitialState(ic);
propagator.setOrbitType(OrbitType.CARTESIAN);
// detector triggers half way through second step
DateDetector detector = new DateDetector(date.shiftedBy(90)).withHandler(new ContinueOnEvent<>());
propagator.addEventDetector(detector);
// action and verify
Queue<Boolean> expected = new ArrayDeque<>(Arrays.asList(false, false, false, true, true, false));
propagator.setMasterMode(new OrekitStepHandler() {
@Override
public void handleStep(OrekitStepInterpolator interpolator, boolean isLast) {
assertEquals(expected.poll(), interpolator.isPreviousStateInterpolated());
assertEquals(expected.poll(), interpolator.isCurrentStateInterpolated());
}
});
final AbsoluteDate end = date.shiftedBy(120);
assertEquals(end, propagator.propagate(end).getDate());
}
use of org.orekit.propagation.SpacecraftState in project Orekit by CS-SI.
the class KeplerianPropagator method resetInitialState.
/**
* {@inheritDoc}
*/
public void resetInitialState(final SpacecraftState state) throws OrekitException {
// ensure the orbit use the specified mu and has no non-Keplerian derivatives
final double mu = initialState == null ? state.getMu() : initialState.getMu();
final SpacecraftState fixedState = fixState(state.getOrbit(), state.getAttitude(), state.getMass(), mu, state.getAdditionalStates());
initialState = fixedState;
states = new TimeSpanMap<SpacecraftState>(initialState);
super.resetInitialState(fixedState);
}
use of org.orekit.propagation.SpacecraftState in project Orekit by CS-SI.
the class KeplerianPropagator method fixState.
/**
* Fix state to use a specified mu and remove derivatives.
* <p>
* This ensures the propagation model (which is based on calling
* {@link Orbit#shiftedBy(double)}) is Keplerian only and uses a specified mu.
* </p>
* @param orbit orbit to fix
* @param attitude current attitude
* @param mass current mass
* @param mu gravity coefficient to use
* @param additionalStates additional states
* @return fixed orbit
*/
private SpacecraftState fixState(final Orbit orbit, final Attitude attitude, final double mass, final double mu, final Map<String, double[]> additionalStates) {
final OrbitType type = orbit.getType();
final double[] stateVector = new double[6];
type.mapOrbitToArray(orbit, PositionAngle.TRUE, stateVector, null);
final Orbit fixedOrbit = type.mapArrayToOrbit(stateVector, null, PositionAngle.TRUE, orbit.getDate(), mu, orbit.getFrame());
SpacecraftState fixedState = new SpacecraftState(fixedOrbit, attitude, mass);
for (final Map.Entry<String, double[]> entry : additionalStates.entrySet()) {
fixedState = fixedState.addAdditionalState(entry.getKey(), entry.getValue());
}
return fixedState;
}
Aggregations