Weird behaviour causing JavaError

Hello everyone, I’ve recently encounter this issue:
I have 2 scripts, let’s call them script A and script B. Script A contains almost no calls to Orekit, all it does is call its Constants class to get some data, and then solves a minimization problem based on an analytical formulation of an orbital mechanics problem. Then, I save the solution computed to a txt file which is used to initialize script B. Script B makes instead extensive use of Orekit as it is meant to propagate the solution computed by the analytical model in a more physically meaningful dynamical model. In particular, it uses a NumericalPropagator to propagate the effect of the maneuvers computed in script A and it also uses a DSSTPropagator to compute the corresponding mean elements. However, when I run script B after running script A, NumericalPropagator returns this error:

JavaError: <super: <class 'JavaError'>, <JavaError object>>
    Java stacktrace:
java.lang.ArrayIndexOutOfBoundsException: 1
	at org.orekit.forces.gravity.OceanTidesField$TideHarmonics.getNormalizedCnm(OceanTidesField.java:223)
	at org.orekit.forces.gravity.potential.CachedNormalizedSphericalHarmonicsProvider$Generator.fillArray(CachedNormalizedSphericalHarmonicsProvider.java:205)
	at org.orekit.forces.gravity.potential.CachedNormalizedSphericalHarmonicsProvider$Generator.generate(CachedNormalizedSphericalHarmonicsProvider.java:158)
	at org.orekit.utils.GenericTimeStampedCache$Slot.generateAndCheck(GenericTimeStampedCache.java:793)
	at org.orekit.utils.GenericTimeStampedCache$Slot.<init>(GenericTimeStampedCache.java:447)
	at org.orekit.utils.GenericTimeStampedCache.selectSlot(GenericTimeStampedCache.java:369)
	at org.orekit.utils.GenericTimeStampedCache.getNeighbors(GenericTimeStampedCache.java:292)
	at org.orekit.forces.gravity.potential.CachedNormalizedSphericalHarmonicsProvider.onDate(CachedNormalizedSphericalHarmonicsProvider.java:127)
	at org.orekit.forces.gravity.HolmesFeatherstoneAttractionModel.gradient(HolmesFeatherstoneAttractionModel.java:280)
	at org.orekit.forces.gravity.HolmesFeatherstoneAttractionModel.acceleration(HolmesFeatherstoneAttractionModel.java:1039)
	at org.orekit.forces.gravity.OceanTides.acceleration(OceanTides.java:176)
	at org.orekit.forces.ForceModel.addContribution(ForceModel.java:109)
	at org.orekit.propagation.numerical.NumericalPropagator$Main.computeDerivatives(NumericalPropagator.java:899)
	at org.orekit.propagation.integration.AbstractIntegratedPropagator$ConvertedMainStateEquations.computeDerivatives(AbstractIntegratedPropagator.java:758)
	at org.hipparchus.ode.ExpandableODE.computeDerivatives(ExpandableODE.java:134)
	at org.hipparchus.ode.AbstractIntegrator.computeDerivatives(AbstractIntegrator.java:265)
	at org.hipparchus.ode.AbstractIntegrator.initIntegration(AbstractIntegrator.java:217)
	at org.hipparchus.ode.nonstiff.EmbeddedRungeKuttaIntegrator.integrate(EmbeddedRungeKuttaIntegrator.java:196)
	at org.orekit.propagation.integration.AbstractIntegratedPropagator.integrateDynamics(AbstractIntegratedPropagator.java:477)
	at org.orekit.propagation.integration.AbstractIntegratedPropagator.propagate(AbstractIntegratedPropagator.java:425)
	at org.orekit.propagation.integration.AbstractIntegratedPropagator.propagate(AbstractIntegratedPropagator.java:385)

The force models I use are defined like this:

n, m = 4, 4;
nonSphericalGravity = HolmesFeatherstoneAttractionModel(FramesFactory.getITRF(IERSConventions.IERS_2010, True),
                                                        GravityFieldFactory.getConstantNormalizedProvider(n,m));        
sunThirdBody = ThirdBodyAttraction(CelestialBodyFactory.getSun());
moonThirdBody = ThirdBodyAttraction(CelestialBodyFactory.getMoon());
dragForce = DragForce(HarrisPriester(CelestialBodyFactory.getSun(), earth), IsotropicDrag(area, CD));
srpForce = SolarRadiationPressure(CelestialBodyFactory.getSun(),
                                  Re, IsotropicRadiationSingleCoefficient(area, CR));
oceanicTides = OceanTides(FramesFactory.getITRF(IERSConventions.IERS_2010, True),
                          Re, mu, n, m, IERSConventions.IERS_2010, 
                          TimeScalesFactory.getUT1(IERSConventions.IERS_2010, True));
solidTides = SolidTides(FramesFactory.getITRF(IERSConventions.IERS_2010, True),
                        Re, mu, GravityFieldFactory.getConstantNormalizedProvider(n, m).getTideSystem(),
                        IERSConventions.IERS_2010, TimeScalesFactory.getUT1(IERSConventions.IERS_2010, True),
                        [CelestialBodyFactory.getSun(), CelestialBodyFactory.getMoon()]);
forces = [nonSphericalGravity, sunThirdBody, moonThirdBody, dragForce, srpForce, oceanicTides, solidTides];

(I know that I probably shouldn’t add OceanicTides and SolidTides since they don’t have a DSST equivalent, but let’s sidestep that for a moment)

What is really weird is the fact that if I restart my console and run script B (without running script A) the propagator doesn’t encounter this error. It also works fine if I run B → A → B on a fresh console. Basically the propagation fails if A is the absolute first script run.
Any ideas on what is causing this issue?

Hi Emiliano,

This may be linked to this

Best,
Romain.

Hi @Emiliano and @Serrof,

I agree with you Romain.
Emiliano, there’s already an issue opened about this.
A workaround is to use two different DataContext for the two scripts.

Maxime

Hello @Serrof and @MaximeJ,

Thank you for your answers. Before posting this I read that thread as well, but I thought it was a different issue since in my case I’m only building the OceanTides once (in the second script) so I thought it had nothing to do with caching.

Emiliano

Hmm… :thinking:

Now that you mention this, I may have read your first post too fast…
Could you provide a small runnable example of the issue?

Hello @MaximeJ, sorry for the late reply :sweat_smile:

Something even weirder just happened… I tried again this morning, and… the error doesn’t get raised anymore. I have literally no clue what’s going on :confused:

Hi @Emiliano,

That’s weird. If you run into the problem again, feel free to share a bit of code so we can all investigate.