1   /* Copyright 2002-2025 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.CalculusFieldElement;
25  import org.hipparchus.Field;
26  import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
27  import org.hipparchus.ode.FieldODEIntegrator;
28  import org.hipparchus.util.MathArrays;
29  import org.orekit.annotation.DefaultDataContext;
30  import org.orekit.attitudes.AttitudeProvider;
31  import org.orekit.attitudes.AttitudeProviderModifier;
32  import org.orekit.attitudes.FieldAttitude;
33  import org.orekit.data.DataContext;
34  import org.orekit.errors.OrekitException;
35  import org.orekit.errors.OrekitIllegalArgumentException;
36  import org.orekit.errors.OrekitInternalError;
37  import org.orekit.errors.OrekitMessages;
38  import org.orekit.forces.ForceModel;
39  import org.orekit.forces.gravity.NewtonianAttraction;
40  import org.orekit.frames.Frame;
41  import org.orekit.orbits.FieldOrbit;
42  import org.orekit.orbits.OrbitType;
43  import org.orekit.orbits.PositionAngleType;
44  import org.orekit.propagation.CartesianToleranceProvider;
45  import org.orekit.propagation.FieldSpacecraftState;
46  import org.orekit.propagation.PropagationType;
47  import org.orekit.propagation.Propagator;
48  import org.orekit.propagation.ToleranceProvider;
49  import org.orekit.propagation.events.FieldEventDetector;
50  import org.orekit.propagation.integration.FieldAbstractIntegratedPropagator;
51  import org.orekit.propagation.integration.FieldStateMapper;
52  import org.orekit.time.AbsoluteDate;
53  import org.orekit.time.FieldAbsoluteDate;
54  import org.orekit.utils.FieldAbsolutePVCoordinates;
55  import org.orekit.utils.ParameterDriver;
56  import org.orekit.utils.ParameterObserver;
57  import org.orekit.utils.TimeSpanMap;
58  import org.orekit.utils.TimeStampedFieldPVCoordinates;
59  
60  /** This class propagates {@link org.orekit.orbits.FieldOrbit orbits} using
61   * numerical integration.
62   * <p>Numerical propagation is much more accurate than analytical propagation
63   * like for example {@link org.orekit.propagation.analytical.KeplerianPropagator
64   * Keplerian} or {@link org.orekit.propagation.analytical.EcksteinHechlerPropagator
65   * Eckstein-Hechler}, but requires a few more steps to set up to be used properly.
66   * Whereas analytical propagators are configured only thanks to their various
67   * constructors and can be used immediately after construction, numerical propagators
68   * configuration involve setting several parameters between construction time
69   * and propagation time.</p>
70   * <p>The configuration parameters that can be set are:</p>
71   * <ul>
72   *   <li>the initial spacecraft state ({@link #setInitialState(FieldSpacecraftState)})</li>
73   *   <li>the central attraction coefficient ({@link #setMu(CalculusFieldElement)})</li>
74   *   <li>the various force models ({@link #addForceModel(ForceModel)},
75   *   {@link #removeForceModels()})</li>
76   *   <li>the {@link OrbitType type} of orbital parameters to be used for propagation
77   *   ({@link #setOrbitType(OrbitType)}),
78   *   <li>the {@link PositionAngleType type} of position angle to be used in orbital parameters
79   *   to be used for propagation where it is relevant ({@link
80   *   #setPositionAngleType(PositionAngleType)}),
81   *   <li>whether {@link org.orekit.propagation.integration.FieldAdditionalDerivativesProvider additional derivatives providers}
82   *   should be propagated along with orbital state
83   *   ({@link #addAdditionalDerivativesProvider(org.orekit.propagation.integration.FieldAdditionalDerivativesProvider)}),
84   *   <li>the discrete events that should be triggered during propagation
85   *   ({@link #addEventDetector(FieldEventDetector)},
86   *   {@link #clearEventsDetectors()})</li>
87   *   <li>the binding logic with the rest of the application ({@link #getMultiplexer()})</li>
88   * </ul>
89   * <p>From these configuration parameters, only the initial state is mandatory. The default
90   * propagation settings are in {@link OrbitType#EQUINOCTIAL equinoctial} parameters with
91   * {@link PositionAngleType#ECCENTRIC} longitude argument. If the central attraction coefficient
92   * is not explicitly specified, the one used to define the initial orbit will be used.
93   * However, specifying only the initial state and perhaps the central attraction coefficient
94   * would mean the propagator would use only Keplerian forces. In this case, the simpler {@link
95   * org.orekit.propagation.analytical.KeplerianPropagator KeplerianPropagator} class would
96   * perhaps be more effective.</p>
97   * <p>The underlying numerical integrator set up in the constructor may also have its own
98   * configuration parameters. Typical configuration parameters for adaptive stepsize integrators
99   * are the min, max and perhaps start step size as well as the absolute and/or relative errors
100  * thresholds.</p>
101  * <p>The state that is seen by the integrator is a simple seven elements double array.
102  * The six first elements are either:
103  * <ul>
104  *   <li>the {@link org.orekit.orbits.FieldEquinoctialOrbit equinoctial orbit parameters} (a, e<sub>x</sub>,
105  *   e<sub>y</sub>, h<sub>x</sub>, h<sub>y</sub>, λ<sub>M</sub> or λ<sub>E</sub>
106  *   or λ<sub>v</sub>) in meters and radians,</li>
107  *   <li>the {@link org.orekit.orbits.FieldKeplerianOrbit Keplerian orbit parameters} (a, e, i, ω, Ω,
108  *   M or E or v) in meters and radians,</li>
109  *   <li>the {@link org.orekit.orbits.FieldCircularOrbit circular orbit parameters} (a, e<sub>x</sub>, e<sub>y</sub>, i,
110  *   Ω, α<sub>M</sub> or α<sub>E</sub> or α<sub>v</sub>) in meters
111  *   and radians,</li>
112  *   <li>the {@link org.orekit.orbits.FieldCartesianOrbit Cartesian orbit parameters} (x, y, z, v<sub>x</sub>,
113  *   v<sub>y</sub>, v<sub>z</sub>) in meters and meters per seconds.
114  * </ul>
115  * The last element is the mass in kilograms.
116  * <p>The following code snippet shows a typical setting for Low Earth Orbit propagation in
117  * equinoctial parameters and true longitude argument:</p>
118  * <pre>
119  * final T          zero      = field.getZero();
120  * final T          dP        = zero.add(0.001);
121  * final T          minStep   = zero.add(0.001);
122  * final T          maxStep   = zero.add(500);
123  * final T          initStep  = zero.add(60);
124  * final double[][] tolerance = ToleranceProvider.getDefaultToleranceProvider(dP).getTolerances(orbit, OrbitType.EQUINOCTIAL);
125  * AdaptiveStepsizeFieldIntegrator&lt;T&gt; integrator = new DormandPrince853FieldIntegrator&lt;&gt;(field, minStep, maxStep, tolerance[0], tolerance[1]);
126  * integrator.setInitialStepSize(initStep);
127  * propagator = new FieldNumericalPropagator&lt;&gt;(field, integrator);
128  * </pre>
129  * <p>By default, at the end of the propagation, the propagator resets the initial state to the final state,
130  * thus allowing a new propagation to be started from there without recomputing the part already performed.
131  * This behaviour can be changed by calling {@link #setResetAtEnd(boolean)}.
132  * </p>
133  * <p>Beware the same instance cannot be used simultaneously by different threads, the class is <em>not</em>
134  * thread-safe.</p>
135 
136  * @see FieldSpacecraftState
137  * @see ForceModel
138  * @see org.orekit.propagation.sampling.FieldOrekitStepHandler
139  * @see org.orekit.propagation.sampling.FieldOrekitFixedStepHandler
140  * @see org.orekit.propagation.integration.FieldIntegratedEphemeris
141  * @see FieldTimeDerivativesEquations
142  *
143  * @author Mathieu Rom&eacute;ro
144  * @author Luc Maisonobe
145  * @author Guylaine Prat
146  * @author Fabien Maussion
147  * @author V&eacute;ronique Pommier-Maurussane
148  * @param <T> type of the field elements
149  */
150 public class FieldNumericalPropagator<T extends CalculusFieldElement<T>> extends FieldAbstractIntegratedPropagator<T> {
151 
152     /** Force models used during the extrapolation of the FieldOrbit<T>, without Jacobians. */
153     private final List<ForceModel> forceModels;
154 
155     /** Field used by this class.*/
156     private final Field<T> field;
157 
158     /** boolean to ignore or not the creation of a NewtonianAttraction. */
159     private boolean ignoreCentralAttraction = false;
160 
161     /**
162      * boolean to know if a full attitude (with rates) is needed when computing derivatives for the ODE.
163      */
164     private boolean needFullAttitudeForDerivatives = true;
165 
166     /** Create a new instance of NumericalPropagator, based on orbit definition mu.
167      * After creation, the instance is empty, i.e. the attitude provider is set to an
168      * unspecified default law and there are no perturbing forces at all.
169      * This means that if {@link #addForceModel addForceModel} is not
170      * called after creation, the integrated orbit will follow a Keplerian
171      * evolution only. The defaults are {@link OrbitType#EQUINOCTIAL}
172      * for {@link #setOrbitType(OrbitType) propagation
173      * orbit type} and {@link PositionAngleType#ECCENTRIC} for {@link
174      * #setPositionAngleType(PositionAngleType) position angle type}.
175      *
176      * <p>This constructor uses the {@link DataContext#getDefault() default data context}.
177      *
178      * @param integrator numerical integrator to use for propagation.
179      * @param field Field used by default
180      * @see #FieldNumericalPropagator(Field, FieldODEIntegrator, AttitudeProvider)
181      */
182     @DefaultDataContext
183     public FieldNumericalPropagator(final Field<T> field, final FieldODEIntegrator<T> integrator) {
184         this(field, integrator, Propagator.getDefaultLaw(DataContext.getDefault().getFrames()));
185     }
186 
187     /** Create a new instance of NumericalPropagator, based on orbit definition mu.
188      * After creation, the instance is empty, i.e. the attitude provider is set to an
189      * unspecified default law and there are no perturbing forces at all.
190      * This means that if {@link #addForceModel addForceModel} is not
191      * called after creation, the integrated orbit will follow a Keplerian
192      * evolution only. The defaults are {@link OrbitType#EQUINOCTIAL}
193      * for {@link #setOrbitType(OrbitType) propagation
194      * orbit type} and {@link PositionAngleType#ECCENTRIC} for {@link
195      * #setPositionAngleType(PositionAngleType) position angle type}.
196      * @param field Field used by default
197      * @param integrator numerical integrator to use for propagation.
198      * @param attitudeProvider attitude law to use.
199      * @since 10.1
200      */
201     public FieldNumericalPropagator(final Field<T> field,
202                                     final FieldODEIntegrator<T> integrator,
203                                     final AttitudeProvider attitudeProvider) {
204         super(field, integrator, PropagationType.OSCULATING);
205         this.field = field;
206         forceModels = new ArrayList<>();
207         initMapper(field);
208         setAttitudeProvider(attitudeProvider);
209         setMu(field.getZero().add(Double.NaN));
210         clearStepHandlers();
211         setOrbitType(NumericalPropagator.DEFAULT_ORBIT_TYPE);
212         setPositionAngleType(NumericalPropagator.DEFAULT_POSITION_ANGLE_TYPE);
213     }
214 
215     /** Set the flag to ignore or not the creation of a {@link NewtonianAttraction}.
216      * @param ignoreCentralAttraction if true, {@link NewtonianAttraction} is <em>not</em>
217      * added automatically if missing
218      */
219     public void setIgnoreCentralAttraction(final boolean ignoreCentralAttraction) {
220         this.ignoreCentralAttraction = ignoreCentralAttraction;
221     }
222 
223     /** Set the central attraction coefficient μ.
224      * <p>
225      * Setting the central attraction coefficient is
226      * equivalent to {@link #addForceModel(ForceModel) add}
227      * a {@link NewtonianAttraction} force model.
228      * </p>
229      * @param mu central attraction coefficient (m³/s²)
230      * @see #addForceModel(ForceModel)
231      * @see #getAllForceModels()
232      */
233     @Override
234     public void setMu(final T mu) {
235         if (ignoreCentralAttraction) {
236             superSetMu(mu);
237         } else {
238             addForceModel(new NewtonianAttraction(mu.getReal()));
239         }
240     }
241 
242     /** Set the central attraction coefficient μ only in upper class.
243      * @param mu central attraction coefficient (m³/s²)
244      */
245     private void superSetMu(final T mu) {
246         super.setMu(mu);
247     }
248 
249     /** Check if Newtonian attraction force model is available.
250      * <p>
251      * Newtonian attraction is always the last force model in the list.
252      * </p>
253      * @return true if Newtonian attraction force model is available
254      */
255     private boolean hasNewtonianAttraction() {
256         final int last = forceModels.size() - 1;
257         return last >= 0 && forceModels.get(last) instanceof NewtonianAttraction;
258     }
259 
260     /** Add a force model to the global perturbation model.
261      * <p>If this method is not called at all, the integrated orbit will follow
262      * a Keplerian evolution only.</p>
263      * @param model perturbing {@link ForceModel} to add
264      * @see #removeForceModels()
265      * @see #setMu(CalculusFieldElement)
266      */
267     public void addForceModel(final ForceModel model) {
268 
269         if (model instanceof NewtonianAttraction) {
270             // we want to add the central attraction force model
271 
272             try {
273                 // ensure we are notified of any mu change
274                 model.getParametersDrivers().get(0).addObserver(new ParameterObserver() {
275                     /** {@inheritDoc} */
276                     @Override
277                     public void valueChanged(final double previousValue, final ParameterDriver driver, final AbsoluteDate date) {
278                         // mu PDriver should have only 1 span
279                         superSetMu(field.getZero().newInstance(driver.getValue(date)));
280                     }
281                     /** {@inheritDoc} */
282                     @Override
283                     public void valueSpanMapChanged(final TimeSpanMap<Double> previousValue, final ParameterDriver driver) {
284                         // mu PDriver should have only 1 span
285                         superSetMu(field.getZero().newInstance(driver.getValue()));
286                     }
287                 });
288             } catch (OrekitException oe) {
289                 // this should never happen
290                 throw new OrekitInternalError(oe);
291             }
292 
293             if (hasNewtonianAttraction()) {
294                 // there is already a central attraction model, replace it
295                 forceModels.set(forceModels.size() - 1, model);
296             } else {
297                 // there are no central attraction model yet, add it at the end of the list
298                 forceModels.add(model);
299             }
300         } else {
301             // we want to add a perturbing force model
302             if (hasNewtonianAttraction()) {
303                 // insert the new force model before Newtonian attraction,
304                 // which should always be the last one in the list
305                 forceModels.add(forceModels.size() - 1, model);
306             } else {
307                 // we only have perturbing force models up to now, just append at the end of the list
308                 forceModels.add(model);
309             }
310         }
311 
312     }
313 
314     /** Remove all perturbing force models from the global perturbation model.
315      * <p>Once all perturbing forces have been removed (and as long as no new force
316      * model is added), the integrated orbit will follow a Keplerian evolution
317      * only.</p>
318      * @see #addForceModel(ForceModel)
319      */
320     public void removeForceModels() {
321         forceModels.clear();
322     }
323 
324     /** Get all the force models, perturbing forces and Newtonian attraction included.
325      * @return list of perturbing force models, with Newtonian attraction being the
326      * last one
327      * @see #addForceModel(ForceModel)
328      * @see #setMu(CalculusFieldElement)
329      * @since 9.1
330      */
331     public List<ForceModel> getAllForceModels() {
332         return Collections.unmodifiableList(forceModels);
333     }
334 
335     /** Set propagation orbit type.
336      * @param orbitType orbit type to use for propagation
337      */
338     @Override
339     public void setOrbitType(final OrbitType orbitType) {
340         super.setOrbitType(orbitType);
341     }
342 
343     /** Get propagation parameter type.
344      * @return orbit type used for propagation
345      */
346     @Override
347     public OrbitType getOrbitType() {
348         return superGetOrbitType();
349     }
350 
351     /** Get propagation parameter type.
352      * @return orbit type used for propagation
353      */
354     private OrbitType superGetOrbitType() {
355         return super.getOrbitType();
356     }
357 
358     /** Set position angle type.
359      * <p>
360      * The position parameter type is meaningful only if {@link
361      * #getOrbitType() propagation orbit type}
362      * support it. As an example, it is not meaningful for propagation
363      * in {@link OrbitType#CARTESIAN Cartesian} parameters.
364      * </p>
365      * @param positionAngleType angle type to use for propagation
366      */
367     @Override
368     public void setPositionAngleType(final PositionAngleType positionAngleType) {
369         super.setPositionAngleType(positionAngleType);
370     }
371 
372     /** Get propagation parameter type.
373      * @return angle type to use for propagation
374      */
375     @Override
376     public PositionAngleType getPositionAngleType() {
377         return super.getPositionAngleType();
378     }
379 
380     /** Set the initial state.
381      * @param initialState initial state
382      */
383     public void setInitialState(final FieldSpacecraftState<T> initialState) {
384         resetInitialState(initialState);
385     }
386 
387     /** {@inheritDoc} */
388     @Override
389     public void resetInitialState(final FieldSpacecraftState<T> state) {
390         super.resetInitialState(state);
391         if (!hasNewtonianAttraction()) {
392             setMu(state.getOrbit().getMu());
393         }
394         setStartDate(state.getDate());
395     }
396 
397     /** {@inheritDoc} */
398     @Override
399     protected AttitudeProvider initializeAttitudeProviderForDerivatives() {
400         final AttitudeProvider attitudeProvider = getAttitudeProvider();
401         return needFullAttitudeForDerivatives ? attitudeProvider :
402             AttitudeProviderModifier.getFrozenAttitudeProvider(attitudeProvider);
403     }
404 
405     /** {@inheritDoc} */
406     protected FieldStateMapper<T> createMapper(final FieldAbsoluteDate<T> referenceDate, final T mu,
407                                        final OrbitType orbitType, final PositionAngleType positionAngleType,
408                                        final AttitudeProvider attitudeProvider, final Frame frame) {
409         return new FieldOsculatingMapper(referenceDate, mu, orbitType, positionAngleType, attitudeProvider, frame);
410     }
411 
412     /** Internal mapper using directly osculating parameters. */
413     private class FieldOsculatingMapper extends FieldStateMapper<T> {
414 
415         /** Simple constructor.
416          * <p>
417          * The position parameter type is meaningful only if {@link
418          * #getOrbitType() propagation orbit type}
419          * support it. As an example, it is not meaningful for propagation
420          * in {@link OrbitType#CARTESIAN Cartesian} parameters.
421          * </p>
422          * @param referenceDate reference date
423          * @param mu central attraction coefficient (m³/s²)
424          * @param orbitType orbit type to use for mapping
425          * @param positionAngleType angle type to use for propagation
426          * @param attitudeProvider attitude provider
427          * @param frame inertial frame
428          */
429         FieldOsculatingMapper(final FieldAbsoluteDate<T> referenceDate, final T mu,
430                               final OrbitType orbitType, final PositionAngleType positionAngleType,
431                               final AttitudeProvider attitudeProvider, final Frame frame) {
432             super(referenceDate, mu, orbitType, positionAngleType, attitudeProvider, frame);
433         }
434 
435         /** {@inheritDoc} */
436         public FieldSpacecraftState<T> mapArrayToState(final FieldAbsoluteDate<T> date, final T[] y, final T[] yDot,
437                                                        final PropagationType type) {
438             // the parameter type is ignored for the Numerical Propagator
439 
440             final T mass = y[6];
441             if (mass.getReal() <= 0.0) {
442                 throw new OrekitException(OrekitMessages.NOT_POSITIVE_SPACECRAFT_MASS, mass);
443             }
444 
445             if (superGetOrbitType() == null) {
446                 // propagation uses absolute position-velocity-acceleration
447                 final FieldVector3D<T> p = new FieldVector3D<>(y[0],    y[1],    y[2]);
448                 final FieldVector3D<T> v = new FieldVector3D<>(y[3],    y[4],    y[5]);
449                 final FieldVector3D<T> a;
450                 final FieldAbsolutePVCoordinates<T> absPva;
451                 if (yDot == null) {
452                     absPva = new FieldAbsolutePVCoordinates<>(getFrame(), new TimeStampedFieldPVCoordinates<>(date, p, v, FieldVector3D.getZero(date.getField())));
453                 } else {
454                     a = new FieldVector3D<>(yDot[3], yDot[4], yDot[5]);
455                     absPva = new FieldAbsolutePVCoordinates<>(getFrame(), new TimeStampedFieldPVCoordinates<>(date, p, v, a));
456                 }
457 
458                 final FieldAttitude<T> attitude = getAttitudeProvider().getAttitude(absPva, date, getFrame());
459                 return new FieldSpacecraftState<>(absPva, attitude).withMass(mass);
460             } else {
461                 // propagation uses regular orbits
462                 final FieldOrbit<T> orbit       = superGetOrbitType().mapArrayToOrbit(y, yDot, super.getPositionAngleType(), date, getMu(), getFrame());
463                 final FieldAttitude<T> attitude = getAttitudeProvider().getAttitude(orbit, date, getFrame());
464                 return new FieldSpacecraftState<>(orbit, attitude).withMass(mass);
465             }
466         }
467 
468         /** {@inheritDoc} */
469         public void mapStateToArray(final FieldSpacecraftState<T> state, final T[] y, final T[] yDot) {
470             if (superGetOrbitType() == null) {
471                 // propagation uses absolute position-velocity-acceleration
472                 final FieldVector3D<T> p = state.getAbsPVA().getPosition();
473                 final FieldVector3D<T> v = state.getAbsPVA().getVelocity();
474                 y[0] = p.getX();
475                 y[1] = p.getY();
476                 y[2] = p.getZ();
477                 y[3] = v.getX();
478                 y[4] = v.getY();
479                 y[5] = v.getZ();
480                 y[6] = state.getMass();
481             }
482             else {
483                 superGetOrbitType().mapOrbitToArray(state.getOrbit(), super.getPositionAngleType(), y, yDot);
484                 y[6] = state.getMass();
485             }
486         }
487 
488     }
489 
490     /** {@inheritDoc} */
491     protected MainStateEquations<T> getMainStateEquations(final FieldODEIntegrator<T> integrator) {
492         return new Main(integrator);
493     }
494 
495     /** Internal class for osculating parameters integration. */
496     private class Main implements MainStateEquations<T>, FieldTimeDerivativesEquations<T> {
497 
498         /** Derivatives array. */
499         private final T[] yDot;
500 
501         /** Current state. */
502         private FieldSpacecraftState<T> currentState;
503 
504         /** Jacobian of the orbital parameters with respect to the Cartesian parameters. */
505         private T[][] jacobian;
506 
507         /** Flag keeping track whether Jacobian matrix needs to be recomputed or not. */
508         private boolean recomputingJacobian;
509 
510         /** Simple constructor.
511          * @param integrator numerical integrator to use for propagation.
512          */
513         Main(final FieldODEIntegrator<T> integrator) {
514 
515             this.yDot     = MathArrays.buildArray(getField(),  7);
516             this.jacobian = MathArrays.buildArray(getField(),  6, 6);
517             this.recomputingJacobian = true;
518 
519             // feed internal event detectors
520             for (final ForceModel forceModel : forceModels) {
521                 forceModel.getFieldEventDetectors(getField()).forEach(detector -> setUpEventDetector(integrator, detector));
522             }
523             getAttitudeProvider().getFieldEventDetectors(getField()).forEach(detector -> setUpEventDetector(integrator, detector));
524 
525             // default value for Jacobian is identity
526             for (int i = 0; i < jacobian.length; ++i) {
527                 Arrays.fill(jacobian[i], getField().getZero());
528                 jacobian[i][i] = getField().getOne();
529             }
530 
531         }
532 
533         /** {@inheritDoc} */
534         @Override
535         public void init(final FieldSpacecraftState<T> initialState, final FieldAbsoluteDate<T> target) {
536             needFullAttitudeForDerivatives = forceModels.stream().anyMatch(ForceModel::dependsOnAttitudeRate);
537 
538             forceModels.forEach(fm -> fm.init(initialState, target));
539 
540             final int numberOfForces = forceModels.size();
541             final OrbitType orbitType = superGetOrbitType();
542             if (orbitType != null && orbitType != OrbitType.CARTESIAN && numberOfForces > 0) {
543                 if (numberOfForces > 1) {
544                     recomputingJacobian = true;
545                 } else {
546                     recomputingJacobian = !(forceModels.get(0) instanceof NewtonianAttraction);
547                 }
548             } else {
549                 recomputingJacobian = false;
550             }
551         }
552 
553         /** {@inheritDoc} */
554         @Override
555         public T[] computeDerivatives(final FieldSpacecraftState<T> state) {
556             final T zero = state.getMass().getField().getZero();
557             currentState = state;
558             Arrays.fill(yDot, zero);
559             if (recomputingJacobian) {
560                 // propagation uses Jacobian matrix of orbital parameters w.r.t. Cartesian ones
561                 currentState.getOrbit().getJacobianWrtCartesian(getPositionAngleType(), jacobian);
562             }
563 
564             // compute the contributions of all perturbing forces,
565             // using the Kepler contribution at the end since
566             // NewtonianAttraction is always the last instance in the list
567             for (final ForceModel forceModel : forceModels) {
568                 forceModel.addContribution(state, this);
569             }
570 
571             if (superGetOrbitType() == null) {
572                 // position derivative is velocity, and was not added above in the force models
573                 // (it is added when orbit type is non-null because NewtonianAttraction considers it)
574                 final FieldVector3D<T> velocity = currentState.getPVCoordinates().getVelocity();
575                 yDot[0] = yDot[0].add(velocity.getX());
576                 yDot[1] = yDot[1].add(velocity.getY());
577                 yDot[2] = yDot[2].add(velocity.getZ());
578             }
579 
580             return yDot.clone();
581 
582         }
583 
584         /** {@inheritDoc} */
585         @Override
586         public void addKeplerContribution(final T mu) {
587             if (superGetOrbitType() == null) {
588 
589                 // if mu is neither 0 nor NaN, we want to include Newtonian acceleration
590                 if (mu.getReal() > 0) {
591                     // velocity derivative is Newtonian acceleration
592                     final FieldVector3D<T> position = currentState.getPosition();
593                     final T r2         = position.getNormSq();
594                     final T coeff      = r2.multiply(r2.sqrt()).reciprocal().negate().multiply(mu);
595                     yDot[3] = yDot[3].add(coeff.multiply(position.getX()));
596                     yDot[4] = yDot[4].add(coeff.multiply(position.getY()));
597                     yDot[5] = yDot[5].add(coeff.multiply(position.getZ()));
598                 }
599 
600             } else {
601                 // propagation uses regular orbits
602                 currentState.getOrbit().addKeplerContribution(getPositionAngleType(), mu, yDot);
603             }
604         }
605 
606         /** {@inheritDoc} */
607         @Override
608         public void addNonKeplerianAcceleration(final FieldVector3D<T> gamma) {
609             for (int i = 0; i < 6; ++i) {
610                 final T[] jRow = jacobian[i];
611                 yDot[i] = yDot[i].add(jRow[3].linearCombination(jRow[3], gamma.getX(),
612                                                                 jRow[4], gamma.getY(),
613                                                                 jRow[5], gamma.getZ()));
614             }
615         }
616 
617         /** {@inheritDoc} */
618         @Override
619         public void addMassDerivative(final T q) {
620             if (q.getReal() > 0) {
621                 throw new OrekitIllegalArgumentException(OrekitMessages.POSITIVE_FLOW_RATE, q);
622             }
623             yDot[6] = yDot[6].add(q);
624         }
625 
626     }
627 
628     /** Estimate tolerance vectors for integrators.
629      * <p>
630      * The errors are estimated from partial derivatives properties of orbits,
631      * starting from a scalar position error specified by the user.
632      * Considering the energy conservation equation V = sqrt(mu (2/r - 1/a)),
633      * we get at constant energy (i.e. on a Keplerian trajectory):
634      * <pre>
635      * V r² |dV| = mu |dr|
636      * </pre>
637      * So we deduce a scalar velocity error consistent with the position error.
638      * From here, we apply orbits Jacobians matrices to get consistent errors
639      * on orbital parameters.
640      * <p>
641      * The tolerances are only <em>orders of magnitude</em>, and integrator tolerances
642      * are only local estimates, not global ones. So some care must be taken when using
643      * these tolerances. Setting 1mm as a position error does NOT mean the tolerances
644      * will guarantee a 1mm error position after several orbits integration.
645      * </p>
646      * @param dP user specified position error
647      * @param orbit reference orbit
648      * @param type propagation type for the meaning of the tolerance vectors elements
649      * (it may be different from {@code orbit.getType()})
650      * @return a two rows array, row 0 being the absolute tolerance error and row 1
651      * being the relative tolerance error
652      * @param <T> elements type
653      * @deprecated since 13.0. Use {@link ToleranceProvider} for default and custom tolerances.
654      */
655     @Deprecated
656     public static <T extends CalculusFieldElement<T>> double[][] tolerances(final T dP, final FieldOrbit<T> orbit,
657                                                                             final OrbitType type) {
658 
659         return ToleranceProvider.getDefaultToleranceProvider(dP.getReal()).getTolerances(orbit, type, PositionAngleType.TRUE);
660     }
661 
662     /** Estimate tolerance vectors for integrators when propagating in orbits.
663      * <p>
664      * The errors are estimated from partial derivatives properties of orbits,
665      * starting from scalar position and velocity errors specified by the user.
666      * <p>
667      * The tolerances are only <em>orders of magnitude</em>, and integrator tolerances
668      * are only local estimates, not global ones. So some care must be taken when using
669      * these tolerances. Setting 1mm as a position error does NOT mean the tolerances
670      * will guarantee a 1mm error position after several orbits integration.
671      * </p>
672      * @param <T> elements type
673      * @param dP user specified position error
674      * @param dV user specified velocity error
675      * @param orbit reference orbit
676      * @param type propagation type for the meaning of the tolerance vectors elements
677      * (it may be different from {@code orbit.getType()})
678      * @return a two rows array, row 0 being the absolute tolerance error and row 1
679      * being the relative tolerance error
680      * @since 10.3
681      * @deprecated since 13.0. Use {@link ToleranceProvider} for default and custom tolerances.
682      */
683     @Deprecated
684     public static <T extends CalculusFieldElement<T>> double[][] tolerances(final T dP, final T dV,
685                                                                             final FieldOrbit<T> orbit,
686                                                                             final OrbitType type) {
687 
688         return ToleranceProvider.of(CartesianToleranceProvider.of(dP.getReal(), dV.getReal(),
689                 CartesianToleranceProvider.DEFAULT_ABSOLUTE_MASS_TOLERANCE)).getTolerances(orbit, type, PositionAngleType.TRUE);
690     }
691 
692 }
693