1   /* Copyright 2002-2024 CS GROUP
2    * Licensed to CS GROUP (CS) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * CS licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.orekit.propagation.numerical;
18  
19  import java.util.ArrayList;
20  import java.util.Arrays;
21  import java.util.Collections;
22  import java.util.List;
23  
24  import org.hipparchus.exception.LocalizedCoreFormats;
25  import org.hipparchus.geometry.euclidean.threed.Vector3D;
26  import org.hipparchus.linear.MatrixUtils;
27  import org.hipparchus.linear.QRDecomposition;
28  import org.hipparchus.linear.RealMatrix;
29  import org.hipparchus.ode.ODEIntegrator;
30  import org.hipparchus.util.FastMath;
31  import org.hipparchus.util.Precision;
32  import org.orekit.annotation.DefaultDataContext;
33  import org.orekit.attitudes.Attitude;
34  import org.orekit.attitudes.AttitudeProvider;
35  import org.orekit.attitudes.AttitudeProviderModifier;
36  import org.orekit.data.DataContext;
37  import org.orekit.errors.OrekitException;
38  import org.orekit.errors.OrekitIllegalArgumentException;
39  import org.orekit.errors.OrekitInternalError;
40  import org.orekit.errors.OrekitMessages;
41  import org.orekit.forces.ForceModel;
42  import org.orekit.forces.gravity.NewtonianAttraction;
43  import org.orekit.forces.inertia.InertialForces;
44  import org.orekit.forces.maneuvers.Maneuver;
45  import org.orekit.forces.maneuvers.jacobians.Duration;
46  import org.orekit.forces.maneuvers.jacobians.MedianDate;
47  import org.orekit.forces.maneuvers.jacobians.TriggerDate;
48  import org.orekit.forces.maneuvers.trigger.ManeuverTriggers;
49  import org.orekit.frames.Frame;
50  import org.orekit.orbits.Orbit;
51  import org.orekit.orbits.OrbitType;
52  import org.orekit.orbits.PositionAngleType;
53  import org.orekit.propagation.AbstractMatricesHarvester;
54  import org.orekit.propagation.AdditionalStateProvider;
55  import org.orekit.propagation.MatricesHarvester;
56  import org.orekit.propagation.PropagationType;
57  import org.orekit.propagation.Propagator;
58  import org.orekit.propagation.SpacecraftState;
59  import org.orekit.propagation.events.EventDetector;
60  import org.orekit.propagation.events.ParameterDrivenDateIntervalDetector;
61  import org.orekit.propagation.integration.AbstractIntegratedPropagator;
62  import org.orekit.propagation.integration.AdditionalDerivativesProvider;
63  import org.orekit.propagation.integration.StateMapper;
64  import org.orekit.time.AbsoluteDate;
65  import org.orekit.utils.AbsolutePVCoordinates;
66  import org.orekit.utils.DoubleArrayDictionary;
67  import org.orekit.utils.PVCoordinates;
68  import org.orekit.utils.ParameterDriver;
69  import org.orekit.utils.ParameterDriversList;
70  import org.orekit.utils.ParameterDriversList.DelegatingDriver;
71  import org.orekit.utils.TimeSpanMap.Span;
72  import org.orekit.utils.ParameterObserver;
73  import org.orekit.utils.TimeSpanMap;
74  import org.orekit.utils.TimeStampedPVCoordinates;
75  
76  /** This class propagates {@link org.orekit.orbits.Orbit orbits} using
77   * numerical integration.
78   * <p>Numerical propagation is much more accurate than analytical propagation
79   * like for example {@link org.orekit.propagation.analytical.KeplerianPropagator
80   * Keplerian} or {@link org.orekit.propagation.analytical.EcksteinHechlerPropagator
81   * Eckstein-Hechler}, but requires a few more steps to set up to be used properly.
82   * Whereas analytical propagators are configured only thanks to their various
83   * constructors and can be used immediately after construction, numerical propagators
84   * configuration involve setting several parameters between construction time
85   * and propagation time.</p>
86   * <p>The configuration parameters that can be set are:</p>
87   * <ul>
88   *   <li>the initial spacecraft state ({@link #setInitialState(SpacecraftState)})</li>
89   *   <li>the central attraction coefficient ({@link #setMu(double)})</li>
90   *   <li>the various force models ({@link #addForceModel(ForceModel)},
91   *   {@link #removeForceModels()})</li>
92   *   <li>the {@link OrbitType type} of orbital parameters to be used for propagation
93   *   ({@link #setOrbitType(OrbitType)}),</li>
94   *   <li>the {@link PositionAngleType type} of position angle to be used in orbital parameters
95   *   to be used for propagation where it is relevant ({@link
96   *   #setPositionAngleType(PositionAngleType)}),</li>
97   *   <li>whether {@link MatricesHarvester state transition matrices and Jacobians matrices}
98   *   should be propagated along with orbital state ({@link
99   *   #setupMatricesComputation(String, RealMatrix, DoubleArrayDictionary)}),</li>
100  *   <li>whether {@link org.orekit.propagation.integration.AdditionalDerivativesProvider additional derivatives}
101  *   should be propagated along with orbital state ({@link
102  *   #addAdditionalDerivativesProvider(AdditionalDerivativesProvider)}),</li>
103  *   <li>the discrete events that should be triggered during propagation
104  *   ({@link #addEventDetector(EventDetector)},
105  *   {@link #clearEventsDetectors()})</li>
106  *   <li>the binding logic with the rest of the application ({@link #getMultiplexer()})</li>
107  * </ul>
108  * <p>From these configuration parameters, only the initial state is mandatory. The default
109  * propagation settings are in {@link OrbitType#EQUINOCTIAL equinoctial} parameters with
110  * {@link PositionAngleType#TRUE true} longitude argument. If the central attraction coefficient
111  * is not explicitly specified, the one used to define the initial orbit will be used.
112  * However, specifying only the initial state and perhaps the central attraction coefficient
113  * would mean the propagator would use only Keplerian forces. In this case, the simpler {@link
114  * org.orekit.propagation.analytical.KeplerianPropagator KeplerianPropagator} class would
115  * perhaps be more effective.</p>
116  * <p>The underlying numerical integrator set up in the constructor may also have its own
117  * configuration parameters. Typical configuration parameters for adaptive stepsize integrators
118  * are the min, max and perhaps start step size as well as the absolute and/or relative errors
119  * thresholds.</p>
120  * <p>The state that is seen by the integrator is a simple seven elements double array.
121  * The six first elements are either:
122  * <ul>
123  *   <li>the {@link org.orekit.orbits.EquinoctialOrbit equinoctial orbit parameters} (a, e<sub>x</sub>,
124  *   e<sub>y</sub>, h<sub>x</sub>, h<sub>y</sub>, λ<sub>M</sub> or λ<sub>E</sub>
125  *   or λ<sub>v</sub>) in meters and radians,</li>
126  *   <li>the {@link org.orekit.orbits.KeplerianOrbit Keplerian orbit parameters} (a, e, i, ω, Ω,
127  *   M or E or v) in meters and radians,</li>
128  *   <li>the {@link org.orekit.orbits.CircularOrbit circular orbit parameters} (a, e<sub>x</sub>, e<sub>y</sub>, i,
129  *   Ω, α<sub>M</sub> or α<sub>E</sub> or α<sub>v</sub>) in meters
130  *   and radians,</li>
131  *   <li>the {@link org.orekit.orbits.CartesianOrbit Cartesian orbit parameters} (x, y, z, v<sub>x</sub>,
132  *   v<sub>y</sub>, v<sub>z</sub>) in meters and meters per seconds.
133  * </ul>
134  * <p> The last element is the mass in kilograms and changes only during thrusters firings
135  *
136  * <p>The following code snippet shows a typical setting for Low Earth Orbit propagation in
137  * equinoctial parameters and true longitude argument:</p>
138  * <pre>
139  * final double dP       = 0.001;
140  * final double minStep  = 0.001;
141  * final double maxStep  = 500;
142  * final double initStep = 60;
143  * final double[][] tolerance = NumericalPropagator.tolerances(dP, orbit, OrbitType.EQUINOCTIAL);
144  * AdaptiveStepsizeIntegrator integrator = new DormandPrince853Integrator(minStep, maxStep, tolerance[0], tolerance[1]);
145  * integrator.setInitialStepSize(initStep);
146  * propagator = new NumericalPropagator(integrator);
147  * </pre>
148  * <p>By default, at the end of the propagation, the propagator resets the initial state to the final state,
149  * thus allowing a new propagation to be started from there without recomputing the part already performed.
150  * This behaviour can be changed by calling {@link #setResetAtEnd(boolean)}.
151  * </p>
152  * <p>Beware the same instance cannot be used simultaneously by different threads, the class is <em>not</em>
153  * thread-safe.</p>
154  *
155  * @see SpacecraftState
156  * @see ForceModel
157  * @see org.orekit.propagation.sampling.OrekitStepHandler
158  * @see org.orekit.propagation.sampling.OrekitFixedStepHandler
159  * @see org.orekit.propagation.integration.IntegratedEphemeris
160  * @see TimeDerivativesEquations
161  *
162  * @author Mathieu Rom&eacute;ro
163  * @author Luc Maisonobe
164  * @author Guylaine Prat
165  * @author Fabien Maussion
166  * @author V&eacute;ronique Pommier-Maurussane
167  */
168 public class NumericalPropagator extends AbstractIntegratedPropagator {
169 
170     /** Space dimension. */
171     private static final int SPACE_DIMENSION = 3;
172 
173     /** State dimension. */
174     private static final int STATE_DIMENSION = 2 * SPACE_DIMENSION;
175 
176     /** Threshold for matrix solving. */
177     private static final double THRESHOLD = Precision.SAFE_MIN;
178 
179     /** Force models used during the extrapolation of the orbit. */
180     private final List<ForceModel> forceModels;
181 
182     /** boolean to ignore or not the creation of a NewtonianAttraction. */
183     private boolean ignoreCentralAttraction;
184 
185     /**
186      * boolean to know if a full attitude (with rates) is needed when computing derivatives for the ODE.
187      * since 12.1
188      */
189     private boolean needFullAttitudeForDerivatives = true;
190 
191     /** Create a new instance of NumericalPropagator, based on orbit definition mu.
192      * After creation, the instance is empty, i.e. the attitude provider is set to an
193      * unspecified default law and there are no perturbing forces at all.
194      * This means that if {@link #addForceModel addForceModel} is not
195      * called after creation, the integrated orbit will follow a Keplerian
196      * evolution only. The defaults are {@link OrbitType#EQUINOCTIAL}
197      * for {@link #setOrbitType(OrbitType) propagation
198      * orbit type} and {@link PositionAngleType#TRUE} for {@link
199      * #setPositionAngleType(PositionAngleType) position angle type}.
200      *
201      * <p>This constructor uses the {@link DataContext#getDefault() default data context}.
202      *
203      * @param integrator numerical integrator to use for propagation.
204      * @see #NumericalPropagator(ODEIntegrator, AttitudeProvider)
205      */
206     @DefaultDataContext
207     public NumericalPropagator(final ODEIntegrator integrator) {
208         this(integrator,
209                 Propagator.getDefaultLaw(DataContext.getDefault().getFrames()));
210     }
211 
212     /** Create a new instance of NumericalPropagator, based on orbit definition mu.
213      * After creation, the instance is empty, i.e. the attitude provider is set to an
214      * unspecified default law and there are no perturbing forces at all.
215      * This means that if {@link #addForceModel addForceModel} is not
216      * called after creation, the integrated orbit will follow a Keplerian
217      * evolution only. The defaults are {@link OrbitType#EQUINOCTIAL}
218      * for {@link #setOrbitType(OrbitType) propagation
219      * orbit type} and {@link PositionAngleType#TRUE} for {@link
220      * #setPositionAngleType(PositionAngleType) position angle type}.
221      * @param integrator numerical integrator to use for propagation.
222      * @param attitudeProvider the attitude law.
223      * @since 10.1
224      */
225     public NumericalPropagator(final ODEIntegrator integrator,
226                                final AttitudeProvider attitudeProvider) {
227         super(integrator, PropagationType.OSCULATING);
228         forceModels             = new ArrayList<>();
229         ignoreCentralAttraction = false;
230         initMapper();
231         setAttitudeProvider(attitudeProvider);
232         clearStepHandlers();
233         setOrbitType(OrbitType.EQUINOCTIAL);
234         setPositionAngleType(PositionAngleType.TRUE);
235     }
236 
237     /** Set the flag to ignore or not the creation of a {@link NewtonianAttraction}.
238      * @param ignoreCentralAttraction if true, {@link NewtonianAttraction} is <em>not</em>
239      * added automatically if missing
240      */
241     public void setIgnoreCentralAttraction(final boolean ignoreCentralAttraction) {
242         this.ignoreCentralAttraction = ignoreCentralAttraction;
243     }
244 
245      /** Set the central attraction coefficient μ.
246       * <p>
247       * Setting the central attraction coefficient is
248       * equivalent to {@link #addForceModel(ForceModel) add}
249       * a {@link NewtonianAttraction} force model.
250       * * </p>
251       * @param mu central attraction coefficient (m³/s²)
252       * @see #addForceModel(ForceModel)
253       * @see #getAllForceModels()
254       */
255     @Override
256     public void setMu(final double mu) {
257         if (ignoreCentralAttraction) {
258             superSetMu(mu);
259         } else {
260             addForceModel(new NewtonianAttraction(mu));
261             superSetMu(mu);
262         }
263     }
264 
265     /** Set the central attraction coefficient μ only in upper class.
266      * @param mu central attraction coefficient (m³/s²)
267      */
268     private void superSetMu(final double mu) {
269         super.setMu(mu);
270     }
271 
272     /** Check if Newtonian attraction force model is available.
273      * <p>
274      * Newtonian attraction is always the last force model in the list.
275      * </p>
276      * @return true if Newtonian attraction force model is available
277      */
278     private boolean hasNewtonianAttraction() {
279         final int last = forceModels.size() - 1;
280         return last >= 0 && forceModels.get(last) instanceof NewtonianAttraction;
281     }
282 
283     /** Add a force model.
284      * <p>If this method is not called at all, the integrated orbit will follow
285      * a Keplerian evolution only.</p>
286      * @param model {@link ForceModel} to add (it can be either a perturbing force
287      * model or an instance of {@link NewtonianAttraction})
288      * @see #removeForceModels()
289      * @see #setMu(double)
290      */
291     public void addForceModel(final ForceModel model) {
292 
293         if (model instanceof NewtonianAttraction) {
294             // we want to add the central attraction force model
295 
296             try {
297                 // ensure we are notified of any mu change
298                 model.getParametersDrivers().get(0).addObserver(new ParameterObserver() {
299                     /** {@inheritDoc} */
300                     @Override
301                     public void valueSpanMapChanged(final TimeSpanMap<Double> previousValue, final ParameterDriver driver) {
302                         superSetMu(driver.getValue());
303                     }
304                     /** {@inheritDoc} */
305                     @Override
306                     public void valueChanged(final double previousValue, final ParameterDriver driver, final AbsoluteDate date) {
307                         superSetMu(driver.getValue());
308                     }
309                 });
310             } catch (OrekitException oe) {
311                 // this should never happen
312                 throw new OrekitInternalError(oe);
313             }
314 
315             if (hasNewtonianAttraction()) {
316                 // there is already a central attraction model, replace it
317                 forceModels.set(forceModels.size() - 1, model);
318             } else {
319                 // there are no central attraction model yet, add it at the end of the list
320                 forceModels.add(model);
321             }
322         } else {
323             // we want to add a perturbing force model
324             if (hasNewtonianAttraction()) {
325                 // insert the new force model before Newtonian attraction,
326                 // which should always be the last one in the list
327                 forceModels.add(forceModels.size() - 1, model);
328             } else {
329                 // we only have perturbing force models up to now, just append at the end of the list
330                 forceModels.add(model);
331             }
332         }
333 
334     }
335 
336     /** Remove all force models (except central attraction).
337      * <p>Once all perturbing forces have been removed (and as long as no new force
338      * model is added), the integrated orbit will follow a Keplerian evolution
339      * only.</p>
340      * @see #addForceModel(ForceModel)
341      */
342     public void removeForceModels() {
343         final int last = forceModels.size() - 1;
344         if (hasNewtonianAttraction()) {
345             // preserve the Newtonian attraction model at the end
346             final ForceModel newton = forceModels.get(last);
347             forceModels.clear();
348             forceModels.add(newton);
349         } else {
350             forceModels.clear();
351         }
352     }
353 
354     /** Get all the force models, perturbing forces and Newtonian attraction included.
355      * @return list of perturbing force models, with Newtonian attraction being the
356      * last one
357      * @see #addForceModel(ForceModel)
358      * @see #setMu(double)
359      */
360     public List<ForceModel> getAllForceModels() {
361         return Collections.unmodifiableList(forceModels);
362     }
363 
364     /** Set propagation orbit type.
365      * @param orbitType orbit type to use for propagation, null for
366      * propagating using {@link org.orekit.utils.AbsolutePVCoordinates} rather than {@link Orbit}
367      */
368     @Override
369     public void setOrbitType(final OrbitType orbitType) {
370         super.setOrbitType(orbitType);
371     }
372 
373     /** Get propagation parameter type.
374      * @return orbit type used for propagation, null for
375      * propagating using {@link org.orekit.utils.AbsolutePVCoordinates} rather than {@link Orbit}
376      */
377     @Override
378     public OrbitType getOrbitType() {
379         return super.getOrbitType();
380     }
381 
382     /** Set position angle type.
383      * <p>
384      * The position parameter type is meaningful only if {@link
385      * #getOrbitType() propagation orbit type}
386      * support it. As an example, it is not meaningful for propagation
387      * in {@link OrbitType#CARTESIAN Cartesian} parameters.
388      * </p>
389      * @param positionAngleType angle type to use for propagation
390      */
391     @Override
392     public void setPositionAngleType(final PositionAngleType positionAngleType) {
393         super.setPositionAngleType(positionAngleType);
394     }
395 
396     /** Get propagation parameter type.
397      * @return angle type to use for propagation
398      */
399     @Override
400     public PositionAngleType getPositionAngleType() {
401         return super.getPositionAngleType();
402     }
403 
404     /** Set the initial state.
405      * @param initialState initial state
406      */
407     public void setInitialState(final SpacecraftState initialState) {
408         resetInitialState(initialState);
409     }
410 
411     /** {@inheritDoc} */
412     @Override
413     public void resetInitialState(final SpacecraftState state) {
414         super.resetInitialState(state);
415         if (!hasNewtonianAttraction()) {
416             // use the state to define central attraction
417             setMu(state.getMu());
418         }
419         setStartDate(state.getDate());
420     }
421 
422     /** Get the names of the parameters in the matrix returned by {@link MatricesHarvester#getParametersJacobian}.
423      * @return names of the parameters (i.e. columns) of the Jacobian matrix
424      */
425     List<String> getJacobiansColumnsNames() {
426         final List<String> columnsNames = new ArrayList<>();
427         for (final ForceModel forceModel : getAllForceModels()) {
428             for (final ParameterDriver driver : forceModel.getParametersDrivers()) {
429                 if (driver.isSelected() && !columnsNames.contains(driver.getNamesSpanMap().getFirstSpan().getData())) {
430                     // As driver with same name should have same NamesSpanMap we only check if the first span is present,
431                     // if not we add all span names to columnsNames
432                     for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {
433                         columnsNames.add(span.getData());
434                     }
435                 }
436             }
437         }
438         Collections.sort(columnsNames);
439         return columnsNames;
440     }
441 
442     /** {@inheritDoc} */
443     @Override
444     protected AbstractMatricesHarvester createHarvester(final String stmName, final RealMatrix initialStm,
445                                                         final DoubleArrayDictionary initialJacobianColumns) {
446         return new NumericalPropagationHarvester(this, stmName, initialStm, initialJacobianColumns);
447     }
448 
449     /** {@inheritDoc} */
450     @Override
451     protected void setUpStmAndJacobianGenerators() {
452 
453         final AbstractMatricesHarvester harvester = getHarvester();
454         if (harvester != null) {
455 
456             // set up the additional equations and additional state providers
457             final StateTransitionMatrixGenerator stmGenerator = setUpStmGenerator();
458             final List<String> triggersDates = setUpTriggerDatesJacobiansColumns(stmGenerator.getName());
459             setUpRegularParametersJacobiansColumns(stmGenerator, triggersDates);
460 
461             // as we are now starting the propagation, everything is configured
462             // we can freeze the names in the harvester
463             harvester.freezeColumnsNames();
464 
465         }
466 
467     }
468 
469     /** Set up the State Transition Matrix Generator.
470      * @return State Transition Matrix Generator
471      * @since 11.1
472      */
473     private StateTransitionMatrixGenerator setUpStmGenerator() {
474 
475         final AbstractMatricesHarvester harvester = getHarvester();
476 
477         // add the STM generator corresponding to the current settings, and setup state accordingly
478         StateTransitionMatrixGenerator stmGenerator = null;
479         for (final AdditionalDerivativesProvider equations : getAdditionalDerivativesProviders()) {
480             if (equations instanceof StateTransitionMatrixGenerator &&
481                 equations.getName().equals(harvester.getStmName())) {
482                 // the STM generator has already been set up in a previous propagation
483                 stmGenerator = (StateTransitionMatrixGenerator) equations;
484                 break;
485             }
486         }
487         if (stmGenerator == null) {
488             // this is the first time we need the STM generate, create it
489             stmGenerator = new StateTransitionMatrixGenerator(harvester.getStmName(), getAllForceModels(), getAttitudeProvider());
490             addAdditionalDerivativesProvider(stmGenerator);
491         }
492 
493         if (!getInitialIntegrationState().hasAdditionalState(harvester.getStmName())) {
494             // add the initial State Transition Matrix if it is not already there
495             // (perhaps due to a previous propagation)
496             setInitialState(stmGenerator.setInitialStateTransitionMatrix(getInitialState(),
497                                                                          harvester.getInitialStateTransitionMatrix(),
498                                                                          getOrbitType(),
499                                                                          getPositionAngleType()));
500         }
501 
502         return stmGenerator;
503 
504     }
505 
506     /** Set up the Jacobians columns generator dedicated to trigger dates.
507      * @param stmName name of the State Transition Matrix state
508      * @return names of the columns corresponding to trigger dates
509      * @since 11.1
510      */
511     private List<String> setUpTriggerDatesJacobiansColumns(final String stmName) {
512 
513         final List<String> names = new ArrayList<>();
514         for (final ForceModel forceModel : getAllForceModels()) {
515             if (forceModel instanceof Maneuver) {
516                 final Maneuver maneuver = (Maneuver) forceModel;
517                 final ManeuverTriggers maneuverTriggers = maneuver.getManeuverTriggers();
518 
519                 maneuverTriggers.getEventDetectors().
520                         filter(d -> d instanceof ParameterDrivenDateIntervalDetector).
521                         map(d -> (ParameterDrivenDateIntervalDetector) d).
522                         forEach(d -> {
523                             TriggerDate start;
524                             TriggerDate stop;
525 
526                             if (d.getStartDriver().isSelected() || d.getMedianDriver().isSelected() || d.getDurationDriver().isSelected()) {
527                                 // normally datedriver should have only 1 span but just in case the user defines several span, there will
528                                 // be no problem here
529                                 for (Span<String> span = d.getStartDriver().getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {
530                                     start = manageTriggerDate(stmName, maneuver, maneuverTriggers, span.getData(), true, d.getThreshold());
531                                     names.add(start.getName());
532                                     start = null;
533                                 }
534                             }
535                             if (d.getStopDriver().isSelected() || d.getMedianDriver().isSelected() || d.getDurationDriver().isSelected()) {
536                                 // normally datedriver should have only 1 span but just in case the user defines several span, there will
537                                 // be no problem here
538                                 for (Span<String> span = d.getStopDriver().getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {
539                                     stop = manageTriggerDate(stmName, maneuver, maneuverTriggers, span.getData(), false, d.getThreshold());
540                                     names.add(stop.getName());
541                                     stop = null;
542                                 }
543                             }
544                             if (d.getMedianDriver().isSelected()) {
545                                 // for first span
546                                 Span<String> currentMedianNameSpan = d.getMedianDriver().getNamesSpanMap().getFirstSpan();
547                                 MedianDate median =
548                                         manageMedianDate(d.getStartDriver().getNamesSpanMap().getFirstSpan().getData(),
549                                                 d.getStopDriver().getNamesSpanMap().getFirstSpan().getData(), currentMedianNameSpan.getData());
550                                 names.add(median.getName());
551                                 // for all span
552                                 // normally datedriver should have only 1 span but just in case the user defines several span, there will
553                                 // be no problem here. /!\ medianDate driver, startDate driver and stopDate driver must have same span number
554                                 for (int spanNumber = 1; spanNumber < d.getMedianDriver().getNamesSpanMap().getSpansNumber(); ++spanNumber) {
555                                     currentMedianNameSpan = d.getMedianDriver().getNamesSpanMap().getSpan(currentMedianNameSpan.getEnd());
556                                     median =
557                                             manageMedianDate(d.getStartDriver().getNamesSpanMap().getSpan(currentMedianNameSpan.getStart()).getData(),
558                                                     d.getStopDriver().getNamesSpanMap().getSpan(currentMedianNameSpan.getStart()).getData(),
559                                                     currentMedianNameSpan.getData());
560                                     names.add(median.getName());
561 
562                                 }
563 
564                             }
565                             if (d.getDurationDriver().isSelected()) {
566                                 // for first span
567                                 Span<String> currentDurationNameSpan = d.getDurationDriver().getNamesSpanMap().getFirstSpan();
568                                 Duration duration =
569                                         manageManeuverDuration(d.getStartDriver().getNamesSpanMap().getFirstSpan().getData(),
570                                                 d.getStopDriver().getNamesSpanMap().getFirstSpan().getData(), currentDurationNameSpan.getData());
571                                 names.add(duration.getName());
572                                 // for all span
573                                 for (int spanNumber = 1; spanNumber < d.getDurationDriver().getNamesSpanMap().getSpansNumber(); ++spanNumber) {
574                                     currentDurationNameSpan = d.getDurationDriver().getNamesSpanMap().getSpan(currentDurationNameSpan.getEnd());
575                                     duration =
576                                             manageManeuverDuration(d.getStartDriver().getNamesSpanMap().getSpan(currentDurationNameSpan.getStart()).getData(),
577                                                     d.getStopDriver().getNamesSpanMap().getSpan(currentDurationNameSpan.getStart()).getData(),
578                                                     currentDurationNameSpan.getData());
579                                     names.add(duration.getName());
580 
581                                 }
582                             }
583                         });
584             }
585         }
586 
587         return names;
588 
589     }
590 
591     /** Manage a maneuver trigger date.
592      * @param stmName name of the State Transition Matrix state
593      * @param maneuver maneuver force model
594      * @param mt trigger to which the driver is bound
595      * @param driverName name of the date driver
596      * @param start if true, the driver is a maneuver start
597      * @param threshold event detector threshold
598      * @return generator for the date driver
599      * @since 11.1
600      */
601     private TriggerDate manageTriggerDate(final String stmName,
602                                           final Maneuver maneuver,
603                                           final ManeuverTriggers mt,
604                                           final String driverName,
605                                           final boolean start,
606                                           final double threshold) {
607 
608         TriggerDate triggerGenerator = null;
609 
610         // check if we already have set up the provider
611         for (final AdditionalStateProvider provider : getAdditionalStateProviders()) {
612             if (provider instanceof TriggerDate &&
613                 provider.getName().equals(driverName)) {
614                 // the Jacobian column generator has already been set up in a previous propagation
615                 triggerGenerator = (TriggerDate) provider;
616                 break;
617             }
618         }
619 
620         if (triggerGenerator == null) {
621             // this is the first time we need the Jacobian column generator, create it
622             triggerGenerator = new TriggerDate(stmName, driverName, start, maneuver, threshold);
623             mt.addResetter(triggerGenerator);
624             addAdditionalDerivativesProvider(triggerGenerator.getMassDepletionDelay());
625             addAdditionalStateProvider(triggerGenerator);
626         }
627 
628         if (!getInitialIntegrationState().hasAdditionalState(driverName)) {
629             // add the initial Jacobian column if it is not already there
630             // (perhaps due to a previous propagation)
631             setInitialColumn(triggerGenerator.getMassDepletionDelay().getName(), new double[6]);
632             setInitialColumn(driverName, getHarvester().getInitialJacobianColumn(driverName));
633         }
634 
635         return triggerGenerator;
636 
637     }
638 
639     /** Manage a maneuver median date.
640      * @param startName name of the start driver
641      * @param stopName name of the stop driver
642      * @param medianName name of the median driver
643      * @return generator for the median driver
644      * @since 11.1
645      */
646     private MedianDate manageMedianDate(final String startName, final String stopName, final String medianName) {
647 
648         MedianDate medianGenerator = null;
649 
650         // check if we already have set up the provider
651         for (final AdditionalStateProvider provider : getAdditionalStateProviders()) {
652             if (provider instanceof MedianDate &&
653                 provider.getName().equals(medianName)) {
654                 // the Jacobian column generator has already been set up in a previous propagation
655                 medianGenerator = (MedianDate) provider;
656                 break;
657             }
658         }
659 
660         if (medianGenerator == null) {
661             // this is the first time we need the Jacobian column generator, create it
662             medianGenerator = new MedianDate(startName, stopName, medianName);
663             addAdditionalStateProvider(medianGenerator);
664         }
665 
666         if (!getInitialIntegrationState().hasAdditionalState(medianName)) {
667             // add the initial Jacobian column if it is not already there
668             // (perhaps due to a previous propagation)
669             setInitialColumn(medianName, getHarvester().getInitialJacobianColumn(medianName));
670         }
671 
672         return medianGenerator;
673 
674     }
675 
676     /** Manage a maneuver duration.
677      * @param startName name of the start driver
678      * @param stopName name of the stop driver
679      * @param durationName name of the duration driver
680      * @return generator for the median driver
681      * @since 11.1
682      */
683     private Duration manageManeuverDuration(final String startName, final String stopName, final String durationName) {
684 
685         Duration durationGenerator = null;
686 
687         // check if we already have set up the provider
688         for (final AdditionalStateProvider provider : getAdditionalStateProviders()) {
689             if (provider instanceof Duration &&
690                 provider.getName().equals(durationName)) {
691                 // the Jacobian column generator has already been set up in a previous propagation
692                 durationGenerator = (Duration) provider;
693                 break;
694             }
695         }
696 
697         if (durationGenerator == null) {
698             // this is the first time we need the Jacobian column generator, create it
699             durationGenerator = new Duration(startName, stopName, durationName);
700             addAdditionalStateProvider(durationGenerator);
701         }
702 
703         if (!getInitialIntegrationState().hasAdditionalState(durationName)) {
704             // add the initial Jacobian column if it is not already there
705             // (perhaps due to a previous propagation)
706             setInitialColumn(durationName, getHarvester().getInitialJacobianColumn(durationName));
707         }
708 
709         return durationGenerator;
710 
711     }
712 
713     /** Set up the Jacobians columns generator for regular parameters.
714      * @param stmGenerator generator for the State Transition Matrix
715      * @param triggerDates names of the columns already managed as trigger dates
716      * @since 11.1
717      */
718     private void setUpRegularParametersJacobiansColumns(final StateTransitionMatrixGenerator stmGenerator,
719                                                         final List<String> triggerDates) {
720 
721         // first pass: gather all parameters (excluding trigger dates), binding similar names together
722         final ParameterDriversList selected = new ParameterDriversList();
723         for (final ForceModel forceModel : getAllForceModels()) {
724             for (final ParameterDriver driver : forceModel.getParametersDrivers()) {
725                 if (!triggerDates.contains(driver.getNamesSpanMap().getFirstSpan().getData())) {
726                     // if the first span is not in triggerdate means that the driver is not a trigger
727                     // date and can be selected here
728                     selected.add(driver);
729                 }
730             }
731         }
732 
733         // second pass: now that shared parameter names are bound together,
734         // their selections status have been synchronized, we can filter them
735         selected.filter(true);
736 
737         // third pass: sort parameters lexicographically
738         selected.sort();
739 
740         // add the Jacobians column generators corresponding to parameters, and setup state accordingly
741         // a new column is needed for each value estimated so for each span of the parameterDriver
742         for (final DelegatingDriver driver : selected.getDrivers()) {
743 
744             for (Span<String> currentNameSpan = driver.getNamesSpanMap().getFirstSpan(); currentNameSpan != null; currentNameSpan = currentNameSpan.next()) {
745 
746                 IntegrableJacobianColumnGenerator generator = null;
747                 // check if we already have set up the providers
748                 for (final AdditionalDerivativesProvider provider : getAdditionalDerivativesProviders()) {
749                     if (provider instanceof IntegrableJacobianColumnGenerator &&
750                         provider.getName().equals(currentNameSpan.getData())) {
751                         // the Jacobian column generator has already been set up in a previous propagation
752                         generator = (IntegrableJacobianColumnGenerator) provider;
753                         break;
754                     }
755 
756                 }
757 
758                 if (generator == null) {
759                     // this is the first time we need the Jacobian column generator, create it
760                     generator = new IntegrableJacobianColumnGenerator(stmGenerator, currentNameSpan.getData());
761                     addAdditionalDerivativesProvider(generator);
762                 }
763 
764                 if (!getInitialIntegrationState().hasAdditionalState(currentNameSpan.getData())) {
765                     // add the initial Jacobian column if it is not already there
766                     // (perhaps due to a previous propagation)
767                     setInitialColumn(currentNameSpan.getData(), getHarvester().getInitialJacobianColumn(currentNameSpan.getData()));
768                 }
769 
770             }
771 
772         }
773 
774     }
775 
776     /** Add the initial value of the column to the initial state.
777      * <p>
778      * The initial state must already contain the Cartesian State Transition Matrix.
779      * </p>
780      * @param columnName name of the column
781      * @param dYdQ column of the Jacobian ∂Y/∂qₘ with respect to propagation type,
782      * if null (which is the most frequent case), assumed to be 0
783      * @since 11.1
784      */
785     private void setInitialColumn(final String columnName, final double[] dYdQ) {
786 
787         final SpacecraftState state = getInitialState();
788 
789         if (dYdQ.length != STATE_DIMENSION) {
790             throw new OrekitException(LocalizedCoreFormats.DIMENSIONS_MISMATCH,
791                                       dYdQ.length, STATE_DIMENSION);
792         }
793 
794         // convert to Cartesian Jacobian
795         final double[][] dYdC = new double[STATE_DIMENSION][STATE_DIMENSION];
796         getOrbitType().convertType(state.getOrbit()).getJacobianWrtCartesian(getPositionAngleType(), dYdC);
797         final double[] column = new QRDecomposition(MatrixUtils.createRealMatrix(dYdC), THRESHOLD).
798                         getSolver().
799                         solve(MatrixUtils.createRealVector(dYdQ)).
800                         toArray();
801 
802         // set additional state
803         setInitialState(state.addAdditionalState(columnName, column));
804 
805     }
806 
807     /** {@inheritDoc} */
808     @Override
809     protected AttitudeProvider initializeAttitudeProviderForDerivatives() {
810         final AttitudeProvider attitudeProvider = getAttitudeProvider();
811         return needFullAttitudeForDerivatives ? attitudeProvider :
812                 AttitudeProviderModifier.getFrozenAttitudeProvider(attitudeProvider);
813     }
814 
815     /** {@inheritDoc} */
816     @Override
817     protected StateMapper createMapper(final AbsoluteDate referenceDate, final double mu,
818                                        final OrbitType orbitType, final PositionAngleType positionAngleType,
819                                        final AttitudeProvider attitudeProvider, final Frame frame) {
820         return new OsculatingMapper(referenceDate, mu, orbitType, positionAngleType, attitudeProvider, frame);
821     }
822 
823     /** Internal mapper using directly osculating parameters. */
824     private static class OsculatingMapper extends StateMapper {
825 
826         /** Simple constructor.
827          * <p>
828          * The position parameter type is meaningful only if {@link
829          * #getOrbitType() propagation orbit type}
830          * support it. As an example, it is not meaningful for propagation
831          * in {@link OrbitType#CARTESIAN Cartesian} parameters.
832          * </p>
833          * @param referenceDate reference date
834          * @param mu central attraction coefficient (m³/s²)
835          * @param orbitType orbit type to use for mapping (can be null for {@link AbsolutePVCoordinates})
836          * @param positionAngleType angle type to use for propagation
837          * @param attitudeProvider attitude provider
838          * @param frame inertial frame
839          */
840         OsculatingMapper(final AbsoluteDate referenceDate, final double mu,
841                          final OrbitType orbitType, final PositionAngleType positionAngleType,
842                          final AttitudeProvider attitudeProvider, final Frame frame) {
843             super(referenceDate, mu, orbitType, positionAngleType, attitudeProvider, frame);
844         }
845 
846         /** {@inheritDoc} */
847         public SpacecraftState mapArrayToState(final AbsoluteDate date, final double[] y, final double[] yDot,
848                                                final PropagationType type) {
849             // the parameter type is ignored for the Numerical Propagator
850 
851             final double mass = y[6];
852             if (mass <= 0.0) {
853                 throw new OrekitException(OrekitMessages.NOT_POSITIVE_SPACECRAFT_MASS, mass);
854             }
855 
856             if (getOrbitType() == null) {
857                 // propagation uses absolute position-velocity-acceleration
858                 final Vector3D p = new Vector3D(y[0],    y[1],    y[2]);
859                 final Vector3D v = new Vector3D(y[3],    y[4],    y[5]);
860                 final Vector3D a;
861                 final AbsolutePVCoordinates absPva;
862                 if (yDot == null) {
863                     absPva = new AbsolutePVCoordinates(getFrame(), new TimeStampedPVCoordinates(date, p, v));
864                 } else {
865                     a = new Vector3D(yDot[3], yDot[4], yDot[5]);
866                     absPva = new AbsolutePVCoordinates(getFrame(), new TimeStampedPVCoordinates(date, p, v, a));
867                 }
868 
869                 final Attitude attitude = getAttitudeProvider().getAttitude(absPva, date, getFrame());
870                 return new SpacecraftState(absPva, attitude, mass);
871             } else {
872                 // propagation uses regular orbits
873                 final Orbit orbit       = getOrbitType().mapArrayToOrbit(y, yDot, getPositionAngleType(), date, getMu(), getFrame());
874                 final Attitude attitude = getAttitudeProvider().getAttitude(orbit, date, getFrame());
875 
876                 return new SpacecraftState(orbit, attitude, mass);
877             }
878 
879         }
880 
881         /** {@inheritDoc} */
882         public void mapStateToArray(final SpacecraftState state, final double[] y, final double[] yDot) {
883             if (getOrbitType() == null) {
884                 // propagation uses absolute position-velocity-acceleration
885                 final Vector3D p = state.getAbsPVA().getPosition();
886                 final Vector3D v = state.getAbsPVA().getVelocity();
887                 y[0] = p.getX();
888                 y[1] = p.getY();
889                 y[2] = p.getZ();
890                 y[3] = v.getX();
891                 y[4] = v.getY();
892                 y[5] = v.getZ();
893                 y[6] = state.getMass();
894             }
895             else {
896                 getOrbitType().mapOrbitToArray(state.getOrbit(), getPositionAngleType(), y, yDot);
897                 y[6] = state.getMass();
898             }
899         }
900 
901     }
902 
903     /** {@inheritDoc} */
904     protected MainStateEquations getMainStateEquations(final ODEIntegrator integrator) {
905         return new Main(integrator);
906     }
907 
908     /** Internal class for osculating parameters integration. */
909     private class Main implements MainStateEquations, TimeDerivativesEquations {
910 
911         /** Derivatives array. */
912         private final double[] yDot;
913 
914         /** Current state. */
915         private SpacecraftState currentState;
916 
917         /** Jacobian of the orbital parameters with respect to the Cartesian parameters. */
918         private double[][] jacobian;
919 
920         /** Flag keeping track whether Jacobian matrix needs to be recomputed or not. */
921         private boolean recomputingJacobian;
922 
923         /** Simple constructor.
924          * @param integrator numerical integrator to use for propagation.
925          */
926         Main(final ODEIntegrator integrator) {
927 
928             this.yDot     = new double[7];
929             this.jacobian = new double[6][6];
930             this.recomputingJacobian = true;
931 
932             for (final ForceModel forceModel : forceModels) {
933                 forceModel.getEventDetectors().forEach(detector -> setUpEventDetector(integrator, detector));
934             }
935 
936             // default value for Jacobian is identity
937             for (int i = 0; i < jacobian.length; ++i) {
938                 Arrays.fill(jacobian[i], 0.0);
939                 jacobian[i][i] = 1.0;
940             }
941 
942         }
943 
944         /** {@inheritDoc} */
945         @Override
946         public void init(final SpacecraftState initialState, final AbsoluteDate target) {
947             needFullAttitudeForDerivatives = forceModels.stream().anyMatch(ForceModel::dependsOnAttitudeRate);
948 
949             forceModels.forEach(fm -> fm.init(initialState, target));
950 
951             final int numberOfForces = forceModels.size();
952             final OrbitType orbitType = getOrbitType();
953             if (orbitType != null && orbitType != OrbitType.CARTESIAN && numberOfForces > 0) {
954                 if (numberOfForces > 1) {
955                     recomputingJacobian = true;
956                 } else {
957                     recomputingJacobian = !(forceModels.get(0) instanceof NewtonianAttraction);
958                 }
959             } else {
960                 recomputingJacobian = false;
961             }
962         }
963 
964         /** {@inheritDoc} */
965         @Override
966         public double[] computeDerivatives(final SpacecraftState state) {
967 
968             currentState = state;
969             Arrays.fill(yDot, 0.0);
970             if (recomputingJacobian) {
971                 // propagation uses Jacobian matrix of orbital parameters w.r.t. Cartesian ones
972                 currentState.getOrbit().getJacobianWrtCartesian(getPositionAngleType(), jacobian);
973             }
974 
975             // compute the contributions of all perturbing forces,
976             // using the Kepler contribution at the end since
977             // NewtonianAttraction is always the last instance in the list
978             for (final ForceModel forceModel : forceModels) {
979                 forceModel.addContribution(state, this);
980             }
981 
982             if (getOrbitType() == null) {
983                 // position derivative is velocity, and was not added above in the force models
984                 // (it is added when orbit type is non-null because NewtonianAttraction considers it)
985                 final Vector3D velocity = currentState.getPVCoordinates().getVelocity();
986                 yDot[0] += velocity.getX();
987                 yDot[1] += velocity.getY();
988                 yDot[2] += velocity.getZ();
989             }
990 
991 
992             return yDot.clone();
993 
994         }
995 
996         /** {@inheritDoc} */
997         @Override
998         public void addKeplerContribution(final double mu) {
999             if (getOrbitType() == null) {
1000                 // if mu is neither 0 nor NaN, we want to include Newtonian acceleration
1001                 if (mu > 0) {
1002                     // velocity derivative is Newtonian acceleration
1003                     final Vector3D position = currentState.getPosition();
1004                     final double r2         = position.getNormSq();
1005                     final double coeff      = -mu / (r2 * FastMath.sqrt(r2));
1006                     yDot[3] += coeff * position.getX();
1007                     yDot[4] += coeff * position.getY();
1008                     yDot[5] += coeff * position.getZ();
1009                 }
1010 
1011             } else {
1012                 // propagation uses regular orbits
1013                 currentState.getOrbit().addKeplerContribution(getPositionAngleType(), mu, yDot);
1014             }
1015         }
1016 
1017         /** {@inheritDoc} */
1018         public void addNonKeplerianAcceleration(final Vector3D gamma) {
1019             for (int i = 0; i < 6; ++i) {
1020                 final double[] jRow = jacobian[i];
1021                 yDot[i] += jRow[3] * gamma.getX() + jRow[4] * gamma.getY() + jRow[5] * gamma.getZ();
1022             }
1023         }
1024 
1025         /** {@inheritDoc} */
1026         @Override
1027         public void addMassDerivative(final double q) {
1028             if (q > 0) {
1029                 throw new OrekitIllegalArgumentException(OrekitMessages.POSITIVE_FLOW_RATE, q);
1030             }
1031             yDot[6] += q;
1032         }
1033 
1034     }
1035 
1036     /** Estimate tolerance vectors for integrators when propagating in absolute position-velocity-acceleration.
1037      * @param dP user specified position error
1038      * @param absPva reference absolute position-velocity-acceleration
1039      * @return a two rows array, row 0 being the absolute tolerance error and row 1
1040      * being the relative tolerance error
1041      * @see NumericalPropagator#tolerances(double, Orbit, OrbitType)
1042      */
1043     public static double[][] tolerances(final double dP, final AbsolutePVCoordinates absPva) {
1044 
1045         final double relative = dP / absPva.getPosition().getNorm();
1046         final double dV = relative * absPva.getVelocity().getNorm();
1047 
1048         final double[] absTol = new double[7];
1049         final double[] relTol = new double[7];
1050 
1051         absTol[0] = dP;
1052         absTol[1] = dP;
1053         absTol[2] = dP;
1054         absTol[3] = dV;
1055         absTol[4] = dV;
1056         absTol[5] = dV;
1057 
1058         // we set the mass tolerance arbitrarily to 1.0e-6 kg, as mass evolves linearly
1059         // with trust, this often has no influence at all on propagation
1060         absTol[6] = 1.0e-6;
1061 
1062         Arrays.fill(relTol, relative);
1063 
1064         return new double[][] {
1065             absTol, relTol
1066         };
1067 
1068     }
1069 
1070     /** Estimate tolerance vectors for integrators when propagating in orbits.
1071      * <p>
1072      * The errors are estimated from partial derivatives properties of orbits,
1073      * starting from a scalar position error specified by the user.
1074      * Considering the energy conservation equation V = sqrt(mu (2/r - 1/a)),
1075      * we get at constant energy (i.e. on a Keplerian trajectory):
1076      * <pre>
1077      * V r² |dV| = mu |dr|
1078      * </pre>
1079      * <p> So we deduce a scalar velocity error consistent with the position error.
1080      * From here, we apply orbits Jacobians matrices to get consistent errors
1081      * on orbital parameters.
1082      *
1083      * <p>
1084      * The tolerances are only <em>orders of magnitude</em>, and integrator tolerances
1085      * are only local estimates, not global ones. So some care must be taken when using
1086      * these tolerances. Setting 1mm as a position error does NOT mean the tolerances
1087      * will guarantee a 1mm error position after several orbits integration.
1088      * </p>
1089      * @param dP user specified position error
1090      * @param orbit reference orbit
1091      * @param type propagation type for the meaning of the tolerance vectors elements
1092      * (it may be different from {@code orbit.getType()})
1093      * @return a two rows array, row 0 being the absolute tolerance error and row 1
1094      * being the relative tolerance error
1095      */
1096     public static double[][] tolerances(final double dP, final Orbit orbit, final OrbitType type) {
1097 
1098         // estimate the scalar velocity error
1099         final PVCoordinates pv = orbit.getPVCoordinates();
1100         final double r2 = pv.getPosition().getNormSq();
1101         final double v  = pv.getVelocity().getNorm();
1102         final double dV = orbit.getMu() * dP / (v * r2);
1103 
1104         return tolerances(dP, dV, orbit, type);
1105 
1106     }
1107 
1108     /** Estimate tolerance vectors for integrators when propagating in orbits.
1109      * <p>
1110      * The errors are estimated from partial derivatives properties of orbits,
1111      * starting from scalar position and velocity errors specified by the user.
1112      * <p>
1113      * The tolerances are only <em>orders of magnitude</em>, and integrator tolerances
1114      * are only local estimates, not global ones. So some care must be taken when using
1115      * these tolerances. Setting 1mm as a position error does NOT mean the tolerances
1116      * will guarantee a 1mm error position after several orbits integration.
1117      * </p>
1118      * @param dP user specified position error
1119      * @param dV user specified velocity error
1120      * @param orbit reference orbit
1121      * @param type propagation type for the meaning of the tolerance vectors elements
1122      * (it may be different from {@code orbit.getType()})
1123      * @return a two rows array, row 0 being the absolute tolerance error and row 1
1124      * being the relative tolerance error
1125      * @since 10.3
1126      */
1127     public static double[][] tolerances(final double dP, final double dV,
1128                                         final Orbit orbit, final OrbitType type) {
1129 
1130         final double[] absTol = new double[7];
1131         final double[] relTol = new double[7];
1132 
1133         // we set the mass tolerance arbitrarily to 1.0e-6 kg, as mass evolves linearly
1134         // with trust, this often has no influence at all on propagation
1135         absTol[6] = 1.0e-6;
1136 
1137         if (type == OrbitType.CARTESIAN) {
1138             absTol[0] = dP;
1139             absTol[1] = dP;
1140             absTol[2] = dP;
1141             absTol[3] = dV;
1142             absTol[4] = dV;
1143             absTol[5] = dV;
1144         } else {
1145 
1146             // convert the orbit to the desired type
1147             final double[][] jacobian = new double[6][6];
1148             final Orbit converted = type.convertType(orbit);
1149             converted.getJacobianWrtCartesian(PositionAngleType.TRUE, jacobian);
1150 
1151             for (int i = 0; i < 6; ++i) {
1152                 final double[] row = jacobian[i];
1153                 absTol[i] = FastMath.abs(row[0]) * dP +
1154                             FastMath.abs(row[1]) * dP +
1155                             FastMath.abs(row[2]) * dP +
1156                             FastMath.abs(row[3]) * dV +
1157                             FastMath.abs(row[4]) * dV +
1158                             FastMath.abs(row[5]) * dV;
1159                 if (Double.isNaN(absTol[i])) {
1160                     throw new OrekitException(OrekitMessages.SINGULAR_JACOBIAN_FOR_ORBIT_TYPE, type);
1161                 }
1162             }
1163 
1164         }
1165 
1166         Arrays.fill(relTol, dP / FastMath.sqrt(orbit.getPosition().getNormSq()));
1167 
1168         return new double[][] {
1169             absTol, relTol
1170         };
1171 
1172     }
1173 
1174     /** {@inheritDoc} */
1175     @Override
1176     protected void beforeIntegration(final SpacecraftState initialState, final AbsoluteDate tEnd) {
1177 
1178         if (!getFrame().isPseudoInertial()) {
1179 
1180             // inspect all force models to find InertialForces
1181             for (ForceModel force : forceModels) {
1182                 if (force instanceof InertialForces) {
1183                     return;
1184                 }
1185             }
1186 
1187             // throw exception if no inertial forces found
1188             throw new OrekitException(OrekitMessages.INERTIAL_FORCE_MODEL_MISSING, getFrame().getName());
1189 
1190         }
1191 
1192     }
1193 
1194 }