AbstractIntegratedPropagator.java

  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.integration;

  18. import java.util.ArrayList;
  19. import java.util.Arrays;
  20. import java.util.Collection;
  21. import java.util.Collections;
  22. import java.util.HashMap;
  23. import java.util.LinkedList;
  24. import java.util.List;
  25. import java.util.Map;
  26. import java.util.Queue;

  27. import org.hipparchus.analysis.UnivariateFunction;
  28. import org.hipparchus.analysis.solvers.BracketedUnivariateSolver;
  29. import org.hipparchus.analysis.solvers.BracketingNthOrderBrentSolver;
  30. import org.hipparchus.exception.MathRuntimeException;
  31. import org.hipparchus.ode.DenseOutputModel;
  32. import org.hipparchus.ode.ExpandableODE;
  33. import org.hipparchus.ode.ODEIntegrator;
  34. import org.hipparchus.ode.ODEState;
  35. import org.hipparchus.ode.ODEStateAndDerivative;
  36. import org.hipparchus.ode.OrdinaryDifferentialEquation;
  37. import org.hipparchus.ode.SecondaryODE;
  38. import org.hipparchus.ode.events.Action;
  39. import org.hipparchus.ode.events.AdaptableInterval;
  40. import org.hipparchus.ode.events.ODEEventDetector;
  41. import org.hipparchus.ode.events.ODEEventHandler;
  42. import org.hipparchus.ode.sampling.AbstractODEStateInterpolator;
  43. import org.hipparchus.ode.sampling.ODEStateInterpolator;
  44. import org.hipparchus.ode.sampling.ODEStepHandler;
  45. import org.hipparchus.util.Precision;
  46. import org.orekit.attitudes.AttitudeProvider;
  47. import org.orekit.errors.OrekitException;
  48. import org.orekit.errors.OrekitInternalError;
  49. import org.orekit.errors.OrekitMessages;
  50. import org.orekit.frames.Frame;
  51. import org.orekit.orbits.OrbitType;
  52. import org.orekit.orbits.PositionAngleType;
  53. import org.orekit.propagation.AbstractPropagator;
  54. import org.orekit.propagation.BoundedPropagator;
  55. import org.orekit.propagation.EphemerisGenerator;
  56. import org.orekit.propagation.PropagationType;
  57. import org.orekit.propagation.SpacecraftState;
  58. import org.orekit.propagation.events.EventDetector;
  59. import org.orekit.propagation.events.handlers.EventHandler;
  60. import org.orekit.propagation.sampling.OrekitStepHandler;
  61. import org.orekit.propagation.sampling.OrekitStepInterpolator;
  62. import org.orekit.time.AbsoluteDate;
  63. import org.orekit.utils.DoubleArrayDictionary;


  64. /** Common handling of {@link org.orekit.propagation.Propagator Propagator}
  65.  *  methods for both numerical and semi-analytical propagators.
  66.  *  @author Luc Maisonobe
  67.  */
  68. public abstract class AbstractIntegratedPropagator extends AbstractPropagator {

  69.     /** Internal name used for complete secondary state dimension.
  70.      * @since 11.1
  71.      */
  72.     private static final String SECONDARY_DIMENSION = "Orekit-secondary-dimension";

  73.     /** Event detectors not related to force models. */
  74.     private final List<EventDetector> detectors;

  75.     /** Step handlers dedicated to ephemeris generation. */
  76.     private final List<StoringStepHandler> ephemerisGenerators;

  77.     /** Integrator selected by the user for the orbital extrapolation process. */
  78.     private final ODEIntegrator integrator;

  79.     /** Offsets of secondary states managed by {@link AdditionalDerivativesProvider}.
  80.      * @since 11.1
  81.      */
  82.     private final Map<String, Integer> secondaryOffsets;

  83.     /** Additional derivatives providers.
  84.      * @since 11.1
  85.      */
  86.     private final List<AdditionalDerivativesProvider> additionalDerivativesProviders;

  87.     /** Map of secondary equation offset in main
  88.     /** Counter for differential equations calls. */
  89.     private int calls;

  90.     /** Mapper between raw double components and space flight dynamics objects. */
  91.     private StateMapper stateMapper;

  92.     /**
  93.      * Attitude provider when evaluating derivatives. Can be a frozen one for performance.
  94.      * @since 12.1
  95.      */
  96.     private AttitudeProvider attitudeProviderForDerivatives;

  97.     /** Flag for resetting the state at end of propagation. */
  98.     private boolean resetAtEnd;

  99.     /** Type of orbit to output (mean or osculating) <br/>
  100.      * <p>
  101.      * This is used only in the case of semi-analytical propagators where there is a clear separation between
  102.      * mean and short periodic elements. It is ignored by the Numerical propagator.
  103.      * </p>
  104.      */
  105.     private final PropagationType propagationType;

  106.     /** Build a new instance.
  107.      * @param integrator numerical integrator to use for propagation.
  108.      * @param propagationType type of orbit to output (mean or osculating).
  109.      */
  110.     protected AbstractIntegratedPropagator(final ODEIntegrator integrator, final PropagationType propagationType) {
  111.         detectors                      = new ArrayList<>();
  112.         ephemerisGenerators            = new ArrayList<>();
  113.         additionalDerivativesProviders = new ArrayList<>();
  114.         this.secondaryOffsets          = new HashMap<>();
  115.         this.integrator                = integrator;
  116.         this.propagationType           = propagationType;
  117.         this.resetAtEnd                = true;
  118.     }

  119.     /** Allow/disallow resetting the initial state at end of propagation.
  120.      * <p>
  121.      * By default, at the end of the propagation, the propagator resets the initial state
  122.      * to the final state, thus allowing a new propagation to be started from there without
  123.      * recomputing the part already performed. Calling this method with {@code resetAtEnd} set
  124.      * to false changes prevents such reset.
  125.      * </p>
  126.      * @param resetAtEnd if true, at end of each propagation, the {@link
  127.      * #getInitialState() initial state} will be reset to the final state of
  128.      * the propagation, otherwise the initial state will be preserved
  129.      * @since 9.0
  130.      */
  131.     public void setResetAtEnd(final boolean resetAtEnd) {
  132.         this.resetAtEnd = resetAtEnd;
  133.     }

  134.     /** Getter for the resetting flag regarding initial state.
  135.      * @return resetting flag
  136.      * @since 12.0
  137.      */
  138.     public boolean getResetAtEnd() {
  139.         return this.resetAtEnd;
  140.     }

  141.     /**
  142.      * Method called when initializing the attitude provider used when evaluating derivatives.
  143.      * @return attitude provider for derivatives
  144.      */
  145.     protected AttitudeProvider initializeAttitudeProviderForDerivatives() {
  146.         return getAttitudeProvider();
  147.     }

  148.     /** Initialize the mapper. */
  149.     protected void initMapper() {
  150.         stateMapper = createMapper(null, Double.NaN, null, null, null, null);
  151.     }

  152.     /** Get the integrator's name.
  153.      * @return name of underlying integrator
  154.      * @since 12.0
  155.      */
  156.     public String getIntegratorName() {
  157.         return integrator.getName();
  158.     }

  159.     /**  {@inheritDoc} */
  160.     @Override
  161.     public void setAttitudeProvider(final AttitudeProvider attitudeProvider) {
  162.         super.setAttitudeProvider(attitudeProvider);
  163.         stateMapper = createMapper(stateMapper.getReferenceDate(), stateMapper.getMu(),
  164.                                    stateMapper.getOrbitType(), stateMapper.getPositionAngleType(),
  165.                                    attitudeProvider, stateMapper.getFrame());
  166.     }

  167.     /** Set propagation orbit type.
  168.      * @param orbitType orbit type to use for propagation, null for
  169.      * propagating using {@link org.orekit.utils.AbsolutePVCoordinates AbsolutePVCoordinates}
  170.      * rather than {@link org.orekit.orbits Orbit}
  171.      */
  172.     protected void setOrbitType(final OrbitType orbitType) {
  173.         stateMapper = createMapper(stateMapper.getReferenceDate(), stateMapper.getMu(),
  174.                                    orbitType, stateMapper.getPositionAngleType(),
  175.                                    stateMapper.getAttitudeProvider(), stateMapper.getFrame());
  176.     }

  177.     /** Get propagation parameter type.
  178.      * @return orbit type used for propagation, null for
  179.      * propagating using {@link org.orekit.utils.AbsolutePVCoordinates AbsolutePVCoordinates}
  180.      * rather than {@link org.orekit.orbits Orbit}
  181.      */
  182.     protected OrbitType getOrbitType() {
  183.         return stateMapper.getOrbitType();
  184.     }

  185.     /** Get the propagation type.
  186.      * @return propagation type.
  187.      * @since 11.1
  188.      */
  189.     public PropagationType getPropagationType() {
  190.         return propagationType;
  191.     }

  192.     /** Set position angle type.
  193.      * <p>
  194.      * The position parameter type is meaningful only if {@link
  195.      * #getOrbitType() propagation orbit type}
  196.      * support it. As an example, it is not meaningful for propagation
  197.      * in {@link OrbitType#CARTESIAN Cartesian} parameters.
  198.      * </p>
  199.      * @param positionAngleType angle type to use for propagation
  200.      */
  201.     protected void setPositionAngleType(final PositionAngleType positionAngleType) {
  202.         stateMapper = createMapper(stateMapper.getReferenceDate(), stateMapper.getMu(),
  203.                                    stateMapper.getOrbitType(), positionAngleType,
  204.                                    stateMapper.getAttitudeProvider(), stateMapper.getFrame());
  205.     }

  206.     /** Get propagation parameter type.
  207.      * @return angle type to use for propagation
  208.      */
  209.     protected PositionAngleType getPositionAngleType() {
  210.         return stateMapper.getPositionAngleType();
  211.     }

  212.     /** Set the central attraction coefficient μ.
  213.      * @param mu central attraction coefficient (m³/s²)
  214.      */
  215.     public void setMu(final double mu) {
  216.         stateMapper = createMapper(stateMapper.getReferenceDate(), mu,
  217.                                    stateMapper.getOrbitType(), stateMapper.getPositionAngleType(),
  218.                                    stateMapper.getAttitudeProvider(), stateMapper.getFrame());
  219.     }

  220.     /** Get the central attraction coefficient μ.
  221.      * @return mu central attraction coefficient (m³/s²)
  222.      * @see #setMu(double)
  223.      */
  224.     public double getMu() {
  225.         return stateMapper.getMu();
  226.     }

  227.     /** Get the number of calls to the differential equations computation method.
  228.      * <p>The number of calls is reset each time the {@link #propagate(AbsoluteDate)}
  229.      * method is called.</p>
  230.      * @return number of calls to the differential equations computation method
  231.      */
  232.     public int getCalls() {
  233.         return calls;
  234.     }

  235.     /** {@inheritDoc} */
  236.     @Override
  237.     public boolean isAdditionalStateManaged(final String name) {

  238.         // first look at already integrated states
  239.         if (super.isAdditionalStateManaged(name)) {
  240.             return true;
  241.         }

  242.         // then look at states we integrate ourselves
  243.         for (final AdditionalDerivativesProvider provider : additionalDerivativesProviders) {
  244.             if (provider.getName().equals(name)) {
  245.                 return true;
  246.             }
  247.         }

  248.         return false;
  249.     }

  250.     /** {@inheritDoc} */
  251.     @Override
  252.     public String[] getManagedAdditionalStates() {
  253.         final String[] alreadyIntegrated = super.getManagedAdditionalStates();
  254.         final String[] managed = new String[alreadyIntegrated.length + additionalDerivativesProviders.size()];
  255.         System.arraycopy(alreadyIntegrated, 0, managed, 0, alreadyIntegrated.length);
  256.         for (int i = 0; i < additionalDerivativesProviders.size(); ++i) {
  257.             managed[i + alreadyIntegrated.length] = additionalDerivativesProviders.get(i).getName();
  258.         }
  259.         return managed;
  260.     }

  261.     /** Add a provider for user-specified state derivatives to be integrated along with the orbit propagation.
  262.      * @param provider provider for additional derivatives
  263.      * @see #addAdditionalStateProvider(org.orekit.propagation.AdditionalStateProvider)
  264.      * @since 11.1
  265.      */
  266.     public void addAdditionalDerivativesProvider(final AdditionalDerivativesProvider provider) {

  267.         // check if the name is already used
  268.         if (isAdditionalStateManaged(provider.getName())) {
  269.             // these derivatives are already registered, complain
  270.             throw new OrekitException(OrekitMessages.ADDITIONAL_STATE_NAME_ALREADY_IN_USE,
  271.                                       provider.getName());
  272.         }

  273.         // this is really a new set of derivatives, add it
  274.         additionalDerivativesProviders.add(provider);

  275.         secondaryOffsets.clear();

  276.     }

  277.     /** Get an unmodifiable list of providers for additional derivatives.
  278.      * @return providers for the additional derivatives
  279.      * @since 11.1
  280.      */
  281.     public List<AdditionalDerivativesProvider> getAdditionalDerivativesProviders() {
  282.         return Collections.unmodifiableList(additionalDerivativesProviders);
  283.     }

  284.     /** {@inheritDoc} */
  285.     public void addEventDetector(final EventDetector detector) {
  286.         detectors.add(detector);
  287.     }

  288.     /** {@inheritDoc} */
  289.     public Collection<EventDetector> getEventsDetectors() {
  290.         return Collections.unmodifiableCollection(detectors);
  291.     }

  292.     /** {@inheritDoc} */
  293.     public void clearEventsDetectors() {
  294.         detectors.clear();
  295.     }

  296.     /** Set up all user defined event detectors.
  297.      */
  298.     protected void setUpUserEventDetectors() {
  299.         for (final EventDetector detector : detectors) {
  300.             setUpEventDetector(integrator, detector);
  301.         }
  302.     }

  303.     /** Wrap an Orekit event detector and register it to the integrator.
  304.      * @param integ integrator into which event detector should be registered
  305.      * @param detector event detector to wrap
  306.      */
  307.     protected void setUpEventDetector(final ODEIntegrator integ, final EventDetector detector) {
  308.         integ.addEventDetector(new AdaptedEventDetector(detector));
  309.     }

  310.     /** {@inheritDoc} */
  311.     @Override
  312.     public EphemerisGenerator getEphemerisGenerator() {
  313.         final StoringStepHandler storingHandler = new StoringStepHandler();
  314.         ephemerisGenerators.add(storingHandler);
  315.         return storingHandler;
  316.     }

  317.     /** Create a mapper between raw double components and spacecraft state.
  318.     /** Simple constructor.
  319.      * <p>
  320.      * The position parameter type is meaningful only if {@link
  321.      * #getOrbitType() propagation orbit type}
  322.      * support it. As an example, it is not meaningful for propagation
  323.      * in {@link OrbitType#CARTESIAN Cartesian} parameters.
  324.      * </p>
  325.      * @param referenceDate reference date
  326.      * @param mu central attraction coefficient (m³/s²)
  327.      * @param orbitType orbit type to use for mapping
  328.      * @param positionAngleType angle type to use for propagation
  329.      * @param attitudeProvider attitude provider
  330.      * @param frame inertial frame
  331.      * @return new mapper
  332.      */
  333.     protected abstract StateMapper createMapper(AbsoluteDate referenceDate, double mu,
  334.                                                 OrbitType orbitType, PositionAngleType positionAngleType,
  335.                                                 AttitudeProvider attitudeProvider, Frame frame);

  336.     /** Get the differential equations to integrate (for main state only).
  337.      * @param integ numerical integrator to use for propagation.
  338.      * @return differential equations for main state
  339.      */
  340.     protected abstract MainStateEquations getMainStateEquations(ODEIntegrator integ);

  341.     /** {@inheritDoc} */
  342.     @Override
  343.     public SpacecraftState propagate(final AbsoluteDate target) {
  344.         if (getStartDate() == null) {
  345.             if (getInitialState() == null) {
  346.                 throw new OrekitException(OrekitMessages.INITIAL_STATE_NOT_SPECIFIED_FOR_ORBIT_PROPAGATION);
  347.             }
  348.             setStartDate(getInitialState().getDate());
  349.         }
  350.         return propagate(getStartDate(), target);
  351.     }

  352.     /** {@inheritDoc} */
  353.     public SpacecraftState propagate(final AbsoluteDate tStart, final AbsoluteDate tEnd) {

  354.         if (getInitialState() == null) {
  355.             throw new OrekitException(OrekitMessages.INITIAL_STATE_NOT_SPECIFIED_FOR_ORBIT_PROPAGATION);
  356.         }

  357.         // make sure the integrator will be reset properly even if we change its events handlers and step handlers
  358.         try (IntegratorResetter resetter = new IntegratorResetter(integrator)) {

  359.             // prepare handling of STM and Jacobian matrices
  360.             setUpStmAndJacobianGenerators();

  361.             // Initialize additional states
  362.             initializeAdditionalStates(tEnd);

  363.             if (!tStart.equals(getInitialState().getDate())) {
  364.                 // if propagation start date is not initial date,
  365.                 // propagate from initial to start date without event detection
  366.                 try (IntegratorResetter startResetter = new IntegratorResetter(integrator)) {
  367.                     integrateDynamics(tStart, true);
  368.                 }
  369.             }

  370.             // set up events added by user
  371.             setUpUserEventDetectors();

  372.             // set up step handlers
  373.             for (final OrekitStepHandler handler : getMultiplexer().getHandlers()) {
  374.                 integrator.addStepHandler(new AdaptedStepHandler(handler));
  375.             }
  376.             for (final StoringStepHandler generator : ephemerisGenerators) {
  377.                 generator.setEndDate(tEnd);
  378.                 integrator.addStepHandler(generator);
  379.             }

  380.             // propagate from start date to end date with event detection
  381.             final SpacecraftState finalState = integrateDynamics(tEnd, false);

  382.             return finalState;

  383.         }

  384.     }

  385.     /** Set up State Transition Matrix and Jacobian matrix handling.
  386.      * @since 11.1
  387.      */
  388.     protected void setUpStmAndJacobianGenerators() {
  389.         // nothing to do by default
  390.     }

  391.     /** Propagation with or without event detection.
  392.      * @param tEnd target date to which orbit should be propagated
  393.      * @param forceResetAtEnd flag to force resetting state and date after integration
  394.      * @return state at end of propagation
  395.      */
  396.     private SpacecraftState integrateDynamics(final AbsoluteDate tEnd, final boolean forceResetAtEnd) {
  397.         try {

  398.             initializePropagation();

  399.             if (getInitialState().getDate().equals(tEnd)) {
  400.                 // don't extrapolate
  401.                 return getInitialState();
  402.             }

  403.             // space dynamics view
  404.             stateMapper = createMapper(getInitialState().getDate(), stateMapper.getMu(),
  405.                                        stateMapper.getOrbitType(), stateMapper.getPositionAngleType(),
  406.                                        stateMapper.getAttitudeProvider(), getInitialState().getFrame());
  407.             attitudeProviderForDerivatives = initializeAttitudeProviderForDerivatives();

  408.             if (Double.isNaN(getMu())) {
  409.                 setMu(getInitialState().getMu());
  410.             }

  411.             if (getInitialState().getMass() <= 0.0) {
  412.                 throw new OrekitException(OrekitMessages.NOT_POSITIVE_SPACECRAFT_MASS,
  413.                                           getInitialState().getMass());
  414.             }

  415.             // convert space flight dynamics API to math API
  416.             final SpacecraftState initialIntegrationState = getInitialIntegrationState();
  417.             final ODEState mathInitialState = createInitialState(initialIntegrationState);
  418.             final ExpandableODE mathODE = createODE(integrator);

  419.             // mathematical integration
  420.             final ODEStateAndDerivative mathFinalState;
  421.             beforeIntegration(initialIntegrationState, tEnd);
  422.             mathFinalState = integrator.integrate(mathODE, mathInitialState,
  423.                                                   tEnd.durationFrom(getInitialState().getDate()));
  424.             afterIntegration();

  425.             // get final state
  426.             SpacecraftState finalState =
  427.                             stateMapper.mapArrayToState(stateMapper.mapDoubleToDate(mathFinalState.getTime(),
  428.                                                                                     tEnd),
  429.                                                         mathFinalState.getPrimaryState(),
  430.                                                         mathFinalState.getPrimaryDerivative(),
  431.                                                         propagationType);

  432.             finalState = updateAdditionalStatesAndDerivatives(finalState, mathFinalState);

  433.             if (resetAtEnd || forceResetAtEnd) {
  434.                 resetInitialState(finalState);
  435.                 setStartDate(finalState.getDate());
  436.             }

  437.             return finalState;

  438.         } catch (MathRuntimeException mre) {
  439.             throw OrekitException.unwrap(mre);
  440.         }
  441.     }

  442.     /**
  443.      * Returns an updated version of the inputted state with additional states, including
  444.      * from derivatives providers.
  445.      * @param originalState input state
  446.      * @param os ODE state and derivative
  447.      * @return new state
  448.      * @since 12.1
  449.      */
  450.     private SpacecraftState updateAdditionalStatesAndDerivatives(final SpacecraftState originalState,
  451.                                                                  final ODEStateAndDerivative os) {
  452.         SpacecraftState updatedState = originalState;
  453.         if (os.getNumberOfSecondaryStates() > 0) {
  454.             final double[] secondary           = os.getSecondaryState(1);
  455.             final double[] secondaryDerivative = os.getSecondaryDerivative(1);
  456.             for (final AdditionalDerivativesProvider provider : additionalDerivativesProviders) {
  457.                 final String name      = provider.getName();
  458.                 final int    offset    = secondaryOffsets.get(name);
  459.                 final int    dimension = provider.getDimension();
  460.                 updatedState = updatedState.addAdditionalState(name, Arrays.copyOfRange(secondary, offset, offset + dimension));
  461.                 updatedState = updatedState.addAdditionalStateDerivative(name, Arrays.copyOfRange(secondaryDerivative, offset, offset + dimension));
  462.             }
  463.         }
  464.         return updateAdditionalStates(updatedState);
  465.     }

  466.     /** Get the initial state for integration.
  467.      * @return initial state for integration
  468.      */
  469.     protected SpacecraftState getInitialIntegrationState() {
  470.         return getInitialState();
  471.     }

  472.     /** Create an initial state.
  473.      * @param initialState initial state in flight dynamics world
  474.      * @return initial state in mathematics world
  475.      */
  476.     private ODEState createInitialState(final SpacecraftState initialState) {

  477.         // retrieve initial state
  478.         final double[] primary = new double[getBasicDimension()];
  479.         stateMapper.mapStateToArray(initialState, primary, null);

  480.         if (secondaryOffsets.isEmpty()) {
  481.             // compute dimension of the secondary state
  482.             int offset = 0;
  483.             for (final AdditionalDerivativesProvider provider : additionalDerivativesProviders) {
  484.                 secondaryOffsets.put(provider.getName(), offset);
  485.                 offset += provider.getDimension();
  486.             }
  487.             secondaryOffsets.put(SECONDARY_DIMENSION, offset);
  488.         }

  489.         return new ODEState(0.0, primary, secondary(initialState));

  490.     }

  491.     /** Create secondary state.
  492.      * @param state spacecraft state
  493.      * @return secondary state
  494.      * @since 11.1
  495.      */
  496.     private double[][] secondary(final SpacecraftState state) {

  497.         if (secondaryOffsets.isEmpty()) {
  498.             return null;
  499.         }

  500.         final double[][] secondary = new double[1][secondaryOffsets.get(SECONDARY_DIMENSION)];
  501.         for (final AdditionalDerivativesProvider provider : additionalDerivativesProviders) {
  502.             final String   name       = provider.getName();
  503.             final int      offset     = secondaryOffsets.get(name);
  504.             final double[] additional = state.getAdditionalState(name);
  505.             System.arraycopy(additional, 0, secondary[0], offset, additional.length);
  506.         }

  507.         return secondary;

  508.     }

  509.     /** Create secondary state derivative.
  510.      * @param state spacecraft state
  511.      * @return secondary state derivative
  512.      * @since 11.1
  513.      */
  514.     private double[][] secondaryDerivative(final SpacecraftState state) {

  515.         if (secondaryOffsets.isEmpty()) {
  516.             return null;
  517.         }

  518.         final double[][] secondaryDerivative = new double[1][secondaryOffsets.get(SECONDARY_DIMENSION)];
  519.         for (final AdditionalDerivativesProvider provider : additionalDerivativesProviders) {
  520.             final String   name       = provider.getName();
  521.             final int      offset     = secondaryOffsets.get(name);
  522.             final double[] additionalDerivative = state.getAdditionalStateDerivative(name);
  523.             System.arraycopy(additionalDerivative, 0, secondaryDerivative[0], offset, additionalDerivative.length);
  524.         }

  525.         return secondaryDerivative;

  526.     }

  527.     /** Create an ODE with all equations.
  528.      * @param integ numerical integrator to use for propagation.
  529.      * @return a new ode
  530.      */
  531.     private ExpandableODE createODE(final ODEIntegrator integ) {

  532.         final ExpandableODE ode =
  533.                 new ExpandableODE(new ConvertedMainStateEquations(getMainStateEquations(integ)));

  534.         // secondary part of the ODE
  535.         if (!additionalDerivativesProviders.isEmpty()) {
  536.             ode.addSecondaryEquations(new ConvertedSecondaryStateEquations());
  537.         }

  538.         return ode;

  539.     }

  540.     /** Method called just before integration.
  541.      * <p>
  542.      * The default implementation does nothing, it may be specialized in subclasses.
  543.      * </p>
  544.      * @param initialState initial state
  545.      * @param tEnd target date at which state should be propagated
  546.      */
  547.     protected void beforeIntegration(final SpacecraftState initialState,
  548.                                      final AbsoluteDate tEnd) {
  549.         // do nothing by default
  550.     }

  551.     /** Method called just after integration.
  552.      * <p>
  553.      * The default implementation does nothing, it may be specialized in subclasses.
  554.      * </p>
  555.      */
  556.     protected void afterIntegration() {
  557.         // do nothing by default
  558.     }

  559.     /** Get state vector dimension without additional parameters.
  560.      * @return state vector dimension without additional parameters.
  561.      */
  562.     public int getBasicDimension() {
  563.         return 7;
  564.     }

  565.     /** Get the integrator used by the propagator.
  566.      * @return the integrator.
  567.      */
  568.     protected ODEIntegrator getIntegrator() {
  569.         return integrator;
  570.     }

  571.     /** Convert a state from mathematical world to space flight dynamics world.
  572.      * @param os mathematical state
  573.      * @return space flight dynamics state
  574.      */
  575.     private SpacecraftState convert(final ODEStateAndDerivative os) {

  576.         final SpacecraftState s = stateMapper.mapArrayToState(os.getTime(), os.getPrimaryState(),
  577.             os.getPrimaryDerivative(), propagationType);
  578.         return updateAdditionalStatesAndDerivatives(s, os);
  579.     }

  580.     /** Convert a state from space flight dynamics world to mathematical world.
  581.      * @param state space flight dynamics state
  582.      * @return mathematical state
  583.      */
  584.     private ODEStateAndDerivative convert(final SpacecraftState state) {

  585.         // retrieve initial state
  586.         final double[] primary    = new double[getBasicDimension()];
  587.         final double[] primaryDot = new double[getBasicDimension()];
  588.         stateMapper.mapStateToArray(state, primary, primaryDot);

  589.         // secondary part of the ODE
  590.         final double[][] secondary           = secondary(state);
  591.         final double[][] secondaryDerivative = secondaryDerivative(state);

  592.         return new ODEStateAndDerivative(stateMapper.mapDateToDouble(state.getDate()),
  593.                                          primary, primaryDot,
  594.                                          secondary, secondaryDerivative);

  595.     }

  596.     /** Differential equations for the main state (orbit, attitude and mass). */
  597.     public interface MainStateEquations {

  598.         /**
  599.          * Initialize the equations at the start of propagation. This method will be
  600.          * called before any calls to {@link #computeDerivatives(SpacecraftState)}.
  601.          *
  602.          * <p> The default implementation of this method does nothing.
  603.          *
  604.          * @param initialState initial state information at the start of propagation.
  605.          * @param target       date of propagation. Not equal to {@code
  606.          *                     initialState.getDate()}.
  607.          */
  608.         default void init(final SpacecraftState initialState, final AbsoluteDate target) {
  609.         }

  610.         /** Compute differential equations for main state.
  611.          * @param state current state
  612.          * @return derivatives of main state
  613.          */
  614.         double[] computeDerivatives(SpacecraftState state);

  615.     }

  616.     /** Differential equations for the main state (orbit, attitude and mass), with converted API. */
  617.     private class ConvertedMainStateEquations implements OrdinaryDifferentialEquation {

  618.         /** Main state equations. */
  619.         private final MainStateEquations main;

  620.         /** Simple constructor.
  621.          * @param main main state equations
  622.          */
  623.         ConvertedMainStateEquations(final MainStateEquations main) {
  624.             this.main = main;
  625.             calls = 0;
  626.         }

  627.         /** {@inheritDoc} */
  628.         public int getDimension() {
  629.             return getBasicDimension();
  630.         }

  631.         @Override
  632.         public void init(final double t0, final double[] y0, final double finalTime) {
  633.             // update space dynamics view
  634.             SpacecraftState initialState = stateMapper.mapArrayToState(t0, y0, null, PropagationType.MEAN);
  635.             initialState = updateAdditionalStates(initialState);
  636.             initialState = updateStatesFromAdditionalDerivativesIfKnown(initialState);
  637.             final AbsoluteDate target = stateMapper.mapDoubleToDate(finalTime);
  638.             main.init(initialState, target);
  639.             attitudeProviderForDerivatives = initializeAttitudeProviderForDerivatives();
  640.         }

  641.         /**
  642.          * Returns an updated version of the inputted state, with additional states from
  643.          * derivatives providers as given in the stored initial state.
  644.          * @param originalState input state
  645.          * @return new state
  646.          * @since 12.1
  647.          */
  648.         private SpacecraftState updateStatesFromAdditionalDerivativesIfKnown(final SpacecraftState originalState) {
  649.             SpacecraftState updatedState = originalState;
  650.             final SpacecraftState storedInitialState = getInitialState();
  651.             final double originalTime = stateMapper.mapDateToDouble(originalState.getDate());
  652.             if (storedInitialState != null && stateMapper.mapDateToDouble(storedInitialState.getDate()) == originalTime) {
  653.                 for (final AdditionalDerivativesProvider provider: additionalDerivativesProviders) {
  654.                     final String name = provider.getName();
  655.                     final double[] value = storedInitialState.getAdditionalState(name);
  656.                     updatedState = updatedState.addAdditionalState(name, value);
  657.                 }
  658.             }
  659.             return updatedState;
  660.         }

  661.         /** {@inheritDoc} */
  662.         public double[] computeDerivatives(final double t, final double[] y) {

  663.             // increment calls counter
  664.             ++calls;

  665.             // update space dynamics view
  666.             stateMapper.setAttitudeProvider(attitudeProviderForDerivatives);
  667.             SpacecraftState currentState = stateMapper.mapArrayToState(t, y, null, PropagationType.MEAN);
  668.             stateMapper.setAttitudeProvider(getAttitudeProvider());

  669.             currentState = updateAdditionalStates(currentState);
  670.             // compute main state differentials
  671.             return main.computeDerivatives(currentState);

  672.         }

  673.     }

  674.     /** Differential equations for the secondary state (Jacobians, user variables ...), with converted API. */
  675.     private class ConvertedSecondaryStateEquations implements SecondaryODE {

  676.         /** Dimension of the combined additional states. */
  677.         private final int combinedDimension;

  678.         /** Simple constructor.
  679.           */
  680.         ConvertedSecondaryStateEquations() {
  681.             this.combinedDimension = secondaryOffsets.get(SECONDARY_DIMENSION);
  682.         }

  683.         /** {@inheritDoc} */
  684.         @Override
  685.         public int getDimension() {
  686.             return combinedDimension;
  687.         }

  688.         /** {@inheritDoc} */
  689.         @Override
  690.         public void init(final double t0, final double[] primary0,
  691.                          final double[] secondary0, final double finalTime) {
  692.             // update space dynamics view
  693.             final SpacecraftState initialState = convert(t0, primary0, null, secondary0);

  694.             final AbsoluteDate target = stateMapper.mapDoubleToDate(finalTime);
  695.             for (final AdditionalDerivativesProvider provider : additionalDerivativesProviders) {
  696.                 provider.init(initialState, target);
  697.             }

  698.         }

  699.         /** {@inheritDoc} */
  700.         @Override
  701.         public double[] computeDerivatives(final double t, final double[] primary,
  702.                                            final double[] primaryDot, final double[] secondary) {

  703.             // update space dynamics view
  704.             // the integrable generators generate method will be called here,
  705.             // according to the generators yield order
  706.             SpacecraftState updated = convert(t, primary, primaryDot, secondary);

  707.             // set up queue for equations
  708.             final Queue<AdditionalDerivativesProvider> pending = new LinkedList<>(additionalDerivativesProviders);

  709.             // gather the derivatives from all additional equations, taking care of dependencies
  710.             final double[] secondaryDot = new double[combinedDimension];
  711.             int yieldCount = 0;
  712.             while (!pending.isEmpty()) {
  713.                 final AdditionalDerivativesProvider provider = pending.remove();
  714.                 if (provider.yields(updated)) {
  715.                     // this provider has to wait for another one,
  716.                     // we put it again in the pending queue
  717.                     pending.add(provider);
  718.                     if (++yieldCount >= pending.size()) {
  719.                         // all pending providers yielded!, they probably need data not yet initialized
  720.                         // we let the propagation proceed, if these data are really needed right now
  721.                         // an appropriate exception will be triggered when caller tries to access them
  722.                         break;
  723.                     }
  724.                 } else {
  725.                     // we can use these equations right now
  726.                     final String              name           = provider.getName();
  727.                     final int                 offset         = secondaryOffsets.get(name);
  728.                     final int                 dimension      = provider.getDimension();
  729.                     final CombinedDerivatives derivatives    = provider.combinedDerivatives(updated);
  730.                     final double[]            additionalPart = derivatives.getAdditionalDerivatives();
  731.                     final double[]            mainPart       = derivatives.getMainStateDerivativesIncrements();
  732.                     System.arraycopy(additionalPart, 0, secondaryDot, offset, dimension);
  733.                     updated = updated.addAdditionalStateDerivative(name, additionalPart);
  734.                     if (mainPart != null) {
  735.                         // this equation does change the main state derivatives
  736.                         for (int i = 0; i < mainPart.length; ++i) {
  737.                             primaryDot[i] += mainPart[i];
  738.                         }
  739.                     }
  740.                     yieldCount = 0;
  741.                 }
  742.             }

  743.             return secondaryDot;

  744.         }

  745.         /** Convert mathematical view to space view.
  746.          * @param t current value of the independent <I>time</I> variable
  747.          * @param primary array containing the current value of the primary state vector
  748.          * @param primaryDot array containing the derivative of the primary state vector
  749.          * @param secondary array containing the current value of the secondary state vector
  750.          * @return space view of the state
  751.          */
  752.         private SpacecraftState convert(final double t, final double[] primary,
  753.                                         final double[] primaryDot, final double[] secondary) {

  754.             SpacecraftState initialState = stateMapper.mapArrayToState(t, primary, primaryDot, PropagationType.MEAN);

  755.             for (final AdditionalDerivativesProvider provider : additionalDerivativesProviders) {
  756.                 final String name      = provider.getName();
  757.                 final int    offset    = secondaryOffsets.get(name);
  758.                 final int    dimension = provider.getDimension();
  759.                 initialState = initialState.addAdditionalState(name, Arrays.copyOfRange(secondary, offset, offset + dimension));
  760.             }

  761.             return updateAdditionalStates(initialState);

  762.         }

  763.     }

  764.     /** Adapt an {@link org.orekit.propagation.events.EventDetector}
  765.      * to Hipparchus {@link org.hipparchus.ode.events.ODEEventDetector} interface.
  766.      * @author Fabien Maussion
  767.      */
  768.     private class AdaptedEventDetector implements ODEEventDetector {

  769.         /** Underlying event detector. */
  770.         private final EventDetector detector;

  771.         /** Underlying event handler.
  772.          * @since 12.0
  773.          */
  774.         private final EventHandler handler;

  775.         /** Time of the previous call to g. */
  776.         private double lastT;

  777.         /** Value from the previous call to g. */
  778.         private double lastG;

  779.         /** Build a wrapped event detector.
  780.          * @param detector event detector to wrap
  781.         */
  782.         AdaptedEventDetector(final EventDetector detector) {
  783.             this.detector = detector;
  784.             this.handler  = detector.getHandler();
  785.             this.lastT    = Double.NaN;
  786.             this.lastG    = Double.NaN;
  787.         }

  788.         /** {@inheritDoc} */
  789.         @Override
  790.         public AdaptableInterval getMaxCheckInterval() {
  791.             return s -> detector.getMaxCheckInterval().currentInterval(convert(s));
  792.         }

  793.         /** {@inheritDoc} */
  794.         @Override
  795.         public int getMaxIterationCount() {
  796.             return detector.getMaxIterationCount();
  797.         }

  798.         /** {@inheritDoc} */
  799.         @Override
  800.         public BracketedUnivariateSolver<UnivariateFunction> getSolver() {
  801.             return new BracketingNthOrderBrentSolver(0, detector.getThreshold(), 0, 5);
  802.         }

  803.         /** {@inheritDoc} */
  804.         @Override
  805.         public void init(final ODEStateAndDerivative s0, final double t) {
  806.             detector.init(convert(s0), stateMapper.mapDoubleToDate(t));
  807.             this.lastT = Double.NaN;
  808.             this.lastG = Double.NaN;
  809.         }

  810.         /** {@inheritDoc} */
  811.         public double g(final ODEStateAndDerivative s) {
  812.             if (!Precision.equals(lastT, s.getTime(), 0)) {
  813.                 lastT = s.getTime();
  814.                 lastG = detector.g(convert(s));
  815.             }
  816.             return lastG;
  817.         }

  818.         /** {@inheritDoc} */
  819.         public ODEEventHandler getHandler() {

  820.             return new ODEEventHandler() {

  821.                 /** {@inheritDoc} */
  822.                 public Action eventOccurred(final ODEStateAndDerivative s, final ODEEventDetector d, final boolean increasing) {
  823.                     return handler.eventOccurred(convert(s), detector, increasing);
  824.                 }

  825.                 /** {@inheritDoc} */
  826.                 @Override
  827.                 public ODEState resetState(final ODEEventDetector d, final ODEStateAndDerivative s) {

  828.                     final SpacecraftState oldState = convert(s);
  829.                     final SpacecraftState newState = handler.resetState(detector, oldState);
  830.                     stateChanged(newState);

  831.                     // main part
  832.                     final double[] primary    = new double[s.getPrimaryStateDimension()];
  833.                     stateMapper.mapStateToArray(newState, primary, null);

  834.                     // secondary part
  835.                     final double[][] secondary = new double[1][secondaryOffsets.get(SECONDARY_DIMENSION)];
  836.                     for (final AdditionalDerivativesProvider provider : additionalDerivativesProviders) {
  837.                         final String name      = provider.getName();
  838.                         final int    offset    = secondaryOffsets.get(name);
  839.                         final int    dimension = provider.getDimension();
  840.                         System.arraycopy(newState.getAdditionalState(name), 0, secondary[0], offset, dimension);
  841.                     }

  842.                     return new ODEState(newState.getDate().durationFrom(getStartDate()),
  843.                                         primary, secondary);

  844.                 }

  845.             };
  846.         }

  847.     }

  848.     /** Adapt an {@link org.orekit.propagation.sampling.OrekitStepHandler}
  849.      * to Hipparchus {@link ODEStepHandler} interface.
  850.      * @author Luc Maisonobe
  851.      */
  852.     private class AdaptedStepHandler implements ODEStepHandler {

  853.         /** Underlying handler. */
  854.         private final OrekitStepHandler handler;

  855.         /** Build an instance.
  856.          * @param handler underlying handler to wrap
  857.          */
  858.         AdaptedStepHandler(final OrekitStepHandler handler) {
  859.             this.handler = handler;
  860.         }

  861.         /** {@inheritDoc} */
  862.         @Override
  863.         public void init(final ODEStateAndDerivative s0, final double t) {
  864.             handler.init(convert(s0), stateMapper.mapDoubleToDate(t));
  865.         }

  866.         /** {@inheritDoc} */
  867.         @Override
  868.         public void handleStep(final ODEStateInterpolator interpolator) {
  869.             handler.handleStep(new AdaptedStepInterpolator(interpolator));
  870.         }

  871.         /** {@inheritDoc} */
  872.         @Override
  873.         public void finish(final ODEStateAndDerivative finalState) {
  874.             handler.finish(convert(finalState));
  875.         }

  876.     }

  877.     /** Adapt an Hipparchus {@link ODEStateInterpolator}
  878.      * to an orekit {@link OrekitStepInterpolator} interface.
  879.      * @author Luc Maisonobe
  880.      */
  881.     private class AdaptedStepInterpolator implements OrekitStepInterpolator {

  882.         /** Underlying raw rawInterpolator. */
  883.         private final ODEStateInterpolator mathInterpolator;

  884.         /** Simple constructor.
  885.          * @param mathInterpolator underlying raw interpolator
  886.          */
  887.         AdaptedStepInterpolator(final ODEStateInterpolator mathInterpolator) {
  888.             this.mathInterpolator = mathInterpolator;
  889.         }

  890.         /** {@inheritDoc}} */
  891.         @Override
  892.         public SpacecraftState getPreviousState() {
  893.             return convert(mathInterpolator.getPreviousState());
  894.         }

  895.         /** {@inheritDoc}} */
  896.         @Override
  897.         public boolean isPreviousStateInterpolated() {
  898.             return mathInterpolator.isPreviousStateInterpolated();
  899.         }

  900.         /** {@inheritDoc}} */
  901.         @Override
  902.         public SpacecraftState getCurrentState() {
  903.             return convert(mathInterpolator.getCurrentState());
  904.         }

  905.         /** {@inheritDoc}} */
  906.         @Override
  907.         public boolean isCurrentStateInterpolated() {
  908.             return mathInterpolator.isCurrentStateInterpolated();
  909.         }

  910.         /** {@inheritDoc}} */
  911.         @Override
  912.         public SpacecraftState getInterpolatedState(final AbsoluteDate date) {
  913.             return convert(mathInterpolator.getInterpolatedState(date.durationFrom(stateMapper.getReferenceDate())));
  914.         }

  915.         /** {@inheritDoc}} */
  916.         @Override
  917.         public boolean isForward() {
  918.             return mathInterpolator.isForward();
  919.         }

  920.         /** {@inheritDoc}} */
  921.         @Override
  922.         public AdaptedStepInterpolator restrictStep(final SpacecraftState newPreviousState,
  923.                                                     final SpacecraftState newCurrentState) {
  924.             try {
  925.                 final AbstractODEStateInterpolator aosi = (AbstractODEStateInterpolator) mathInterpolator;
  926.                 return new AdaptedStepInterpolator(aosi.restrictStep(convert(newPreviousState),
  927.                                                                      convert(newCurrentState)));
  928.             } catch (ClassCastException cce) {
  929.                 // this should never happen
  930.                 throw new OrekitInternalError(cce);
  931.             }
  932.         }

  933.     }

  934.     /** Specialized step handler storing interpolators for ephemeris generation.
  935.      * @since 11.0
  936.      */
  937.     private class StoringStepHandler implements ODEStepHandler, EphemerisGenerator {

  938.         /** Underlying raw mathematical model. */
  939.         private DenseOutputModel model;

  940.         /** the user supplied end date. Propagation may not end on this date. */
  941.         private AbsoluteDate endDate;

  942.         /** Generated ephemeris. */
  943.         private BoundedPropagator ephemeris;

  944.         /** Last interpolator handled by the object.*/
  945.         private  ODEStateInterpolator lastInterpolator;

  946.         /** Set the end date.
  947.          * @param endDate end date
  948.          */
  949.         public void setEndDate(final AbsoluteDate endDate) {
  950.             this.endDate = endDate;
  951.         }

  952.         /** {@inheritDoc} */
  953.         @Override
  954.         public void init(final ODEStateAndDerivative s0, final double t) {

  955.             this.model = new DenseOutputModel();
  956.             model.init(s0, t);

  957.             // ephemeris will be generated when last step is processed
  958.             this.ephemeris = null;

  959.             this.lastInterpolator = null;

  960.         }

  961.         /** {@inheritDoc} */
  962.         @Override
  963.         public BoundedPropagator getGeneratedEphemeris() {
  964.             // Each time we try to get the ephemeris, rebuild it using the last data.
  965.             buildEphemeris();
  966.             return ephemeris;
  967.         }

  968.         /** {@inheritDoc} */
  969.         @Override
  970.         public void handleStep(final ODEStateInterpolator interpolator) {
  971.             model.handleStep(interpolator);
  972.             lastInterpolator = interpolator;
  973.         }

  974.         /** {@inheritDoc} */
  975.         @Override
  976.         public void finish(final ODEStateAndDerivative finalState) {
  977.             buildEphemeris();
  978.         }

  979.         /** Method used to produce ephemeris at a given time.
  980.          * Can be used at multiple times, updating the ephemeris to
  981.          * its last state.
  982.          */
  983.         private void buildEphemeris() {
  984.             // buildEphemeris was built in order to allow access to what was previously the finish method.
  985.             // This now allows to call it through getGeneratedEphemeris, therefore through an external call,
  986.             // which was not previously the case.

  987.             // Update the model's finalTime with the last interpolator.
  988.             model.finish(lastInterpolator.getCurrentState());

  989.             // set up the boundary dates
  990.             final double tI = model.getInitialTime();
  991.             final double tF = model.getFinalTime();
  992.             // tI is almost? always zero
  993.             final AbsoluteDate startDate =
  994.                             stateMapper.mapDoubleToDate(tI);
  995.             final AbsoluteDate finalDate =
  996.                             stateMapper.mapDoubleToDate(tF, this.endDate);
  997.             final AbsoluteDate minDate;
  998.             final AbsoluteDate maxDate;
  999.             if (tF < tI) {
  1000.                 minDate = finalDate;
  1001.                 maxDate = startDate;
  1002.             } else {
  1003.                 minDate = startDate;
  1004.                 maxDate = finalDate;
  1005.             }

  1006.             // get the initial additional states that are not managed
  1007.             final DoubleArrayDictionary unmanaged = new DoubleArrayDictionary();
  1008.             for (final DoubleArrayDictionary.Entry initial : getInitialState().getAdditionalStatesValues().getData()) {
  1009.                 if (!isAdditionalStateManaged(initial.getKey())) {
  1010.                     // this additional state was in the initial state, but is unknown to the propagator
  1011.                     // we simply copy its initial value as is
  1012.                     unmanaged.put(initial.getKey(), initial.getValue());
  1013.                 }
  1014.             }

  1015.             // get the names of additional states managed by differential equations
  1016.             final String[] names      = new String[additionalDerivativesProviders.size()];
  1017.             final int[]    dimensions = new int[additionalDerivativesProviders.size()];
  1018.             for (int i = 0; i < names.length; ++i) {
  1019.                 names[i] = additionalDerivativesProviders.get(i).getName();
  1020.                 dimensions[i] = additionalDerivativesProviders.get(i).getDimension();
  1021.             }

  1022.             // create the ephemeris
  1023.             ephemeris = new IntegratedEphemeris(startDate, minDate, maxDate,
  1024.                                                 stateMapper, propagationType, model,
  1025.                                                 unmanaged, getAdditionalStateProviders(),
  1026.                                                 names, dimensions);

  1027.         }

  1028.     }

  1029.     /** Wrapper for resetting an integrator handlers.
  1030.      * <p>
  1031.      * This class is intended to be used in a try-with-resource statement.
  1032.      * If propagator-specific event handlers and step handlers are added to
  1033.      * the integrator in the try block, they will be removed automatically
  1034.      * when leaving the block, so the integrator only keeps its own handlers
  1035.      * between calls to {@link AbstractIntegratedPropagator#propagate(AbsoluteDate, AbsoluteDate).
  1036.      * </p>
  1037.      * @since 11.0
  1038.      */
  1039.     private static class IntegratorResetter implements AutoCloseable {

  1040.         /** Wrapped integrator. */
  1041.         private final ODEIntegrator integrator;

  1042.         /** Initial event detectors list. */
  1043.         private final List<ODEEventDetector> detectors;

  1044.         /** Initial step handlers list. */
  1045.         private final List<ODEStepHandler> stepHandlers;

  1046.         /** Simple constructor.
  1047.          * @param integrator wrapped integrator
  1048.          */
  1049.         IntegratorResetter(final ODEIntegrator integrator) {
  1050.             this.integrator   = integrator;
  1051.             this.detectors    = new ArrayList<>(integrator.getEventDetectors());
  1052.             this.stepHandlers = new ArrayList<>(integrator.getStepHandlers());
  1053.         }

  1054.         /** {@inheritDoc}
  1055.          * <p>
  1056.          * Reset event handlers and step handlers back to the initial list
  1057.          * </p>
  1058.          */
  1059.         @Override
  1060.         public void close() {

  1061.             // reset event handlers
  1062.             integrator.clearEventDetectors();
  1063.             detectors.forEach(integrator::addEventDetector);

  1064.             // reset step handlers
  1065.             integrator.clearStepHandlers();
  1066.             stepHandlers.forEach(integrator::addStepHandler);

  1067.         }

  1068.     }

  1069. }