Advice on setting up an orbit propagation loop


Dear Colleagues,

I am writing to ask for advice on propagating an orbit and getting results out from the propagator. Please bare in mind that this comes from someone quite new to Java and brand new to Orekit.

Let’s say that I am interested in calculating the semimajor axis and eccentricity of an orbit and also their respective standard deviations by propagating uncertainties with Orekit’s field methods.

Right now I use this structure together with a custom handleStep similar to the one in the Orekit FieldPropagation tutorial.

// propagation loop
for ( int i = 0; i < stepCnt; ++i ) {

System.out.printf( "step: %d%n", i );
// propagates
s = prop.propagate( propDate );

semiMajHist[i] = s.getA().getReal();
eccHist[i] = s.getE().getReal();
// advances propagation time
propDate = new FieldAbsoluteDate<>( startDate, (i + 1) * tStep, utc );

} // for i

To my surprise, I found out that the PrintWriter called inside the handleStep writes the values of the standard deviation and eccentricity twice for steps 1 to stepCnt-1. I tried to find why this happened on my own by looking at the default handleStep but I couldn’t figure it out. I assumed that the handleStep is called twice, after step 0 and the workaround was to use the isLast boolean as a “fix” like so

if ( isLast ) {
PW.printf( “%f\t”, statSemiMaj.getStandardDeviation() );
PW.printf( “%f\t”, statEcc.getStandardDeviation() );

which worked to get results written once.

On the other hand, when I used

s = rop.propagate( startDate.shiftedBy( propParams.getDuration() ) );

the behavior of the stepHandler was the expected one and the uncertainties were written to file only once from 0 to stepCnt - 1.

Is this an expected behavior of the stepHandler? If it is, am I missing something fundamental in Java programming when I set a propagation loop as the one I pasted above?

Thank you!



If you want to print something at regular steps, it is better to use master mode, i.e. to call propagate only once with the final date (not using a loop), and to rely on a fixed step handler to be called as a callback directly by the propagator. It is generally much faster (et least for numerical propagators) as the integrator can use step sizes larger than the output step.

In most cases, either you want only one result and you don’t use a step handler but only the final state returned by propagate, or you want intermediate data and then you ignore the final state.

Letting the propagator handle the loop by itself is much simpler when you consider that in addition to regular continuous propagation it also handles discrete events. It can do that and it is difficult to get right, so it is better if the propagator validated algorithms handle both the continuous time and the discrete events by itself.


Thank you @luc! My using the propagator in slave mode came from the first version of the code that I developed in MATLAB to call Orekit methods. I am now rewriting/updating to full Java and I occasionally get stuck, as I shed old habits.

The UML and rail diagrams of the propagator architecture also helped as well as the tutorial.