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