FieldEventState.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF 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.events;

  18. import org.hipparchus.Field;
  19. import org.hipparchus.RealFieldElement;
  20. import org.hipparchus.analysis.UnivariateFunction;
  21. import org.hipparchus.analysis.solvers.BracketedUnivariateSolver;
  22. import org.hipparchus.analysis.solvers.BracketedUnivariateSolver.Interval;
  23. import org.hipparchus.analysis.solvers.BracketingNthOrderBrentSolver;
  24. import org.hipparchus.exception.MathRuntimeException;
  25. import org.hipparchus.util.FastMath;
  26. import org.hipparchus.util.Precision;
  27. import org.orekit.errors.OrekitException;
  28. import org.orekit.errors.OrekitExceptionWrapper;
  29. import org.orekit.errors.OrekitInternalError;
  30. import org.orekit.propagation.FieldSpacecraftState;
  31. import org.orekit.propagation.events.handlers.FieldEventHandler;
  32. import org.orekit.propagation.events.handlers.FieldEventHandler.Action;
  33. import org.orekit.propagation.sampling.FieldOrekitStepInterpolator;
  34. import org.orekit.time.FieldAbsoluteDate;

  35. /** This class handles the state for one {@link FieldEventDetector
  36.  * event detector} during integration steps.
  37.  *
  38.  * <p>This class is heavily based on the class with the same name from the
  39.  * Hipparchus library. The changes performed consist in replacing
  40.  * raw types (double and double arrays) with space dynamics types
  41.  * ({@link FieldAbsoluteDate}, {@link FieldSpacecraftState}).</p>
  42.  * <p>Each time the propagator proposes a step, the event detector
  43.  * should be checked. This class handles the state of one detector
  44.  * during one propagation step, with references to the state at the
  45.  * end of the preceding step. This information is used to determine if
  46.  * the detector should trigger an event or not during the proposed
  47.  * step (and hence the step should be reduced to ensure the event
  48.  * occurs at a bound rather than inside the step).</p>
  49.  * @author Luc Maisonobe
  50.  * @param <D> class type for the generic version
  51.  */
  52. public class FieldEventState<D extends FieldEventDetector<T>, T extends RealFieldElement<T>> {

  53.     /** Event detector. */
  54.     private D detector;

  55.     /** Time of the previous call to g. */
  56.     private FieldAbsoluteDate<T> lastT;

  57.     /** Value from the previous call to g. */
  58.     private T lastG;

  59.     /** Time at the beginning of the step. */
  60.     private FieldAbsoluteDate<T> t0;

  61.     /** Value of the event detector at the beginning of the step. */
  62.     private T g0;

  63.     /** Simulated sign of g0 (we cheat when crossing events). */
  64.     private boolean g0Positive;

  65.     /** Indicator of event expected during the step. */
  66.     private boolean pendingEvent;

  67.     /** Occurrence time of the pending event. */
  68.     private FieldAbsoluteDate<T> pendingEventTime;

  69.     /**
  70.      * Time to stop propagation if the event is a stop event. Used to enable stopping at
  71.      * an event and then restarting after that event.
  72.      */
  73.     private FieldAbsoluteDate<T> stopTime;

  74.     /** Time after the current event. */
  75.     private FieldAbsoluteDate<T> afterEvent;

  76.     /** Value of the g function after the current event. */
  77.     private T afterG;

  78.     /** The earliest time considered for events. */
  79.     private FieldAbsoluteDate<T> earliestTimeConsidered;

  80.     /** Integration direction. */
  81.     private boolean forward;

  82.     /** Variation direction around pending event.
  83.      *  (this is considered with respect to the integration direction)
  84.      */
  85.     private boolean increasing;

  86.     /** Simple constructor.
  87.      * @param detector monitored event detector
  88.      */
  89.     public FieldEventState(final D detector) {

  90.         this.detector = detector;

  91.         // some dummy values ...
  92.         final Field<T> field   = detector.getMaxCheckInterval().getField();
  93.         final T nan            = field.getZero().add(Double.NaN);
  94.         lastT                  = FieldAbsoluteDate.getPastInfinity(field);
  95.         lastG                  = nan;
  96.         t0                     = null;
  97.         g0                     = nan;
  98.         g0Positive             = true;
  99.         pendingEvent           = false;
  100.         pendingEventTime       = null;
  101.         stopTime               = null;
  102.         increasing             = true;
  103.         earliestTimeConsidered = null;
  104.         afterEvent             = null;
  105.         afterG                 = nan;

  106.     }

  107.     /** Get the underlying event detector.
  108.      * @return underlying event detector
  109.      */
  110.     public D getEventDetector() {
  111.         return detector;
  112.     }

  113.     /** Initialize event handler at the start of a propagation.
  114.      * <p>
  115.      * This method is called once at the start of the propagation. It
  116.      * may be used by the event handler to initialize some internal data
  117.      * if needed.
  118.      * </p>
  119.      * @param s0 initial state
  120.      * @param t target time for the integration
  121.      *
  122.      * @throws  OrekitException if some specific error occurs
  123.      */
  124.     public void init(final FieldSpacecraftState<T> s0,
  125.                      final FieldAbsoluteDate<T> t) throws OrekitException {
  126.         detector.init(s0, t);
  127.         final Field<T> field = detector.getMaxCheckInterval().getField();
  128.         lastT = FieldAbsoluteDate.getPastInfinity(field);
  129.         lastG = field.getZero().add(Double.NaN);
  130.     }

  131.     /** Compute the value of the switching function.
  132.      * This function must be continuous (at least in its roots neighborhood),
  133.      * as the integrator will need to find its roots to locate the events.
  134.      * @param s the current state information: date, kinematics, attitude
  135.      * @return value of the switching function
  136.      * @exception OrekitException if some specific error occurs
  137.      */
  138.     private T g(final FieldSpacecraftState<T> s) throws OrekitException {
  139.         if (!s.getDate().equals(lastT)) {
  140.             lastT = s.getDate();
  141.             lastG = detector.g(s);
  142.         }
  143.         return lastG;
  144.     }

  145.     /** Reinitialize the beginning of the step.
  146.      * @param interpolator interpolator valid for the current step
  147.      * @exception OrekitException if the event detector
  148.      * value cannot be evaluated at the beginning of the step
  149.      */
  150.     public void reinitializeBegin(final FieldOrekitStepInterpolator<T> interpolator)
  151.         throws OrekitException {
  152.         forward = interpolator.isForward();
  153.         final FieldSpacecraftState<T> s0 = interpolator.getPreviousState();
  154.         this.t0 = s0.getDate();
  155.         g0 = g(s0);
  156.         while (g0.getReal() == 0) {
  157.             // extremely rare case: there is a zero EXACTLY at interval start
  158.             // we will use the sign slightly after step beginning to force ignoring this zero
  159.             // try moving forward by half a convergence interval
  160.             final T dt = detector.getThreshold().multiply(forward ? 0.5 : -0.5);
  161.             FieldAbsoluteDate<T> startDate = t0.shiftedBy(dt);
  162.             // if convergence is too small move an ulp
  163.             if (t0.equals(startDate)) {
  164.                 startDate = nextAfter(startDate);
  165.             }
  166.             t0 = startDate;
  167.             g0 = g(interpolator.getInterpolatedState(t0));
  168.         }
  169.         g0Positive = g0.getReal() > 0;
  170.         // "last" event was increasing
  171.         increasing = g0Positive;
  172.     }

  173.     /** Evaluate the impact of the proposed step on the event detector.
  174.      * @param interpolator step interpolator for the proposed step
  175.      * @return true if the event detector triggers an event before
  176.      * the end of the proposed step (this implies the step should be
  177.      * rejected)
  178.      * @exception OrekitException if the switching function
  179.      * cannot be evaluated
  180.      * @exception MathRuntimeException if an event cannot be located
  181.      */
  182.     public boolean evaluateStep(final FieldOrekitStepInterpolator<T> interpolator)
  183.         throws OrekitException, MathRuntimeException {
  184.         forward = interpolator.isForward();
  185.         final FieldSpacecraftState<T> s1 = interpolator.getCurrentState();
  186.         final FieldAbsoluteDate<T> t1 = s1.getDate();
  187.         final T dt = t1.durationFrom(t0);
  188.         if (FastMath.abs(dt.getReal()) < detector.getThreshold().getReal()) {
  189.             // we cannot do anything on such a small step, don't trigger any events
  190.             return false;
  191.         }
  192.         // number of points to check in the current step
  193.         final int n = FastMath.max(1, (int) FastMath.ceil(FastMath.abs(dt.getReal()) / detector.getMaxCheckInterval().getReal()));
  194.         final T h = dt.divide(n);


  195.         FieldAbsoluteDate<T> ta = t0;
  196.         T ga = g0;
  197.         for (int i = 0; i < n; ++i) {

  198.             // evaluate handler value at the end of the substep
  199.             final FieldAbsoluteDate<T> tb = (i == n - 1) ? t1 : t0.shiftedBy(h.multiply(i + 1));
  200.             final T gb = g(interpolator.getInterpolatedState(tb));

  201.             // check events occurrence
  202.             if (gb.getReal() == 0.0 || (g0Positive ^ (gb.getReal() > 0))) {
  203.                 // there is a sign change: an event is expected during this step
  204.                 if (findRoot(interpolator, ta, ga, tb, gb)) {
  205.                     return true;
  206.                 }
  207.             } else {
  208.                 // no sign change: there is no event for now
  209.                 ta = tb;
  210.                 ga = gb;
  211.             }
  212.         }

  213.         // no event during the whole step
  214.         pendingEvent     = false;
  215.         pendingEventTime = null;
  216.         return false;

  217.     }

  218.     /**
  219.      * Find a root in a bracketing interval.
  220.      *
  221.      * <p> When calling this method one of the following must be true. Either ga == 0, gb
  222.      * == 0, (ga < 0  and gb > 0), or (ga > 0 and gb < 0).
  223.      *
  224.      * @param interpolator that covers the interval.
  225.      * @param ta           earliest possible time for root.
  226.      * @param ga           g(ta).
  227.      * @param tb           latest possible time for root.
  228.      * @param gb           g(tb).
  229.      * @return if a zero crossing was found.
  230.      * @throws OrekitException if the event detector throws one
  231.      */


  232.     private boolean findRoot(final FieldOrekitStepInterpolator<T> interpolator,
  233.                              final FieldAbsoluteDate<T> ta, final T ga,
  234.                              final FieldAbsoluteDate<T> tb, final T gb)
  235.         throws OrekitException {

  236.         final T zero = ga.getField().getZero();

  237.         // check there appears to be a root in [ta, tb]
  238.         check(ga.getReal() == 0.0 || gb.getReal() == 0.0 || (ga.getReal() > 0.0 && gb.getReal() < 0.0) || (ga.getReal() < 0.0 && gb.getReal() > 0.0));
  239.         final T convergence = detector.getThreshold();
  240.         final int maxIterationCount = detector.getMaxIterationCount();
  241.         final BracketedUnivariateSolver<UnivariateFunction> solver =
  242.                 new BracketingNthOrderBrentSolver(0, convergence.getReal(), 0, 5);

  243.         // event time, just at or before the actual root.
  244.         FieldAbsoluteDate<T> beforeRootT = null;
  245.         T beforeRootG = zero.add(Double.NaN);
  246.         // time on the other side of the root.
  247.         // Initialized the the loop below executes once.
  248.         FieldAbsoluteDate<T> afterRootT = ta;
  249.         T afterRootG = zero;

  250.         // check for some conditions that the root finders don't like
  251.         // these conditions cannot not happen in the loop below
  252.         // the ga == 0.0 case is handled by the loop below
  253.         if (ta.equals(tb)) {
  254.             // both non-zero but times are the same. Probably due to reset state
  255.             beforeRootT = ta;
  256.             beforeRootG = ga;
  257.             afterRootT = shiftedBy(beforeRootT, convergence);
  258.             afterRootG = g(interpolator.getInterpolatedState(afterRootT));
  259.         } else if (ga.getReal() != 0.0 && gb.getReal() == 0.0) {
  260.             // hard: ga != 0.0 and gb == 0.0
  261.             // look past gb by up to convergence to find next sign
  262.             // throw an exception if g(t) = 0.0 in [tb, tb + convergence]
  263.             beforeRootT = tb;
  264.             beforeRootG = gb;
  265.             afterRootT = shiftedBy(beforeRootT, convergence);
  266.             afterRootG = g(interpolator.getInterpolatedState(afterRootT));
  267.         } else if (ga.getReal() != 0.0) {
  268.             final T newGa = g(interpolator.getInterpolatedState(ta));
  269.             if (ga.getReal() > 0 != newGa.getReal() > 0) {
  270.                 // both non-zero, step sign change at ta, possibly due to reset state
  271.                 beforeRootT = ta;
  272.                 beforeRootG = newGa;
  273.                 afterRootT = minTime(shiftedBy(beforeRootT, convergence), tb);
  274.                 afterRootG = g(interpolator.getInterpolatedState(afterRootT));
  275.             }
  276.         }
  277.         // loop to skip through "fake" roots, i.e. where g(t) = g'(t) = 0.0
  278.         // executed once if we didn't hit a special case above
  279.         FieldAbsoluteDate<T> loopT = ta;
  280.         T loopG = ga;
  281.         while ((afterRootG.getReal() == 0.0 || afterRootG.getReal() > 0.0 == g0Positive) &&
  282.                 strictlyAfter(afterRootT, tb)) {
  283.             if (loopG.getReal() == 0.0) {
  284.                 // ga == 0.0 and gb may or may not be 0.0
  285.                 // handle the root at ta first
  286.                 beforeRootT = loopT;
  287.                 beforeRootG = loopG;
  288.                 afterRootT = minTime(shiftedBy(beforeRootT, convergence), tb);
  289.                 afterRootG = g(interpolator.getInterpolatedState(afterRootT));
  290.             } else {
  291.                 // both non-zero, the usual case, use a root finder.
  292.                 try {
  293.                     // time zero for evaluating the function f. Needs to be final
  294.                     final FieldAbsoluteDate<T> fT0 = loopT;
  295.                     final UnivariateFunction f = dt -> {
  296.                         try {
  297.                             return g(interpolator.getInterpolatedState(fT0.shiftedBy(dt))).getReal();
  298.                         } catch (OrekitException oe) {
  299.                             throw new OrekitExceptionWrapper(oe);
  300.                         }
  301.                     };
  302.                     // tb as a double for use in f
  303.                     final T tbDouble = tb.durationFrom(fT0);
  304.                     if (forward) {
  305.                         final Interval interval =
  306.                                 solver.solveInterval(maxIterationCount, f, 0, tbDouble.getReal());
  307.                         beforeRootT = fT0.shiftedBy(interval.getLeftAbscissa());
  308.                         beforeRootG = zero.add(interval.getLeftValue());
  309.                         afterRootT = fT0.shiftedBy(interval.getRightAbscissa());
  310.                         afterRootG = zero.add(interval.getRightValue());
  311.                     } else {
  312.                         final Interval interval =
  313.                                 solver.solveInterval(maxIterationCount, f, tbDouble.getReal(), 0);
  314.                         beforeRootT = fT0.shiftedBy(interval.getRightAbscissa());
  315.                         beforeRootG = zero.add(interval.getRightValue());
  316.                         afterRootT = fT0.shiftedBy(interval.getLeftAbscissa());
  317.                         afterRootG = zero.add(interval.getLeftValue());
  318.                     }
  319.                 } catch (OrekitExceptionWrapper oew) {
  320.                     throw oew.getException();
  321.                 }
  322.             }
  323.             // tolerance is set to less than 1 ulp
  324.             // assume tolerance is 1 ulp
  325.             if (beforeRootT.equals(afterRootT)) {
  326.                 afterRootT = nextAfter(afterRootT);
  327.                 afterRootG = g(interpolator.getInterpolatedState(afterRootT));
  328.             }
  329.             // check loop is making some progress
  330.             check((forward && afterRootT.compareTo(beforeRootT) > 0) ||
  331.                   (!forward && afterRootT.compareTo(beforeRootT) < 0));
  332.             // setup next iteration
  333.             loopT = afterRootT;
  334.             loopG = afterRootG;
  335.         }

  336.         // figure out the result of root finding, and return accordingly
  337.         if (afterRootG.getReal() == 0.0 || afterRootG.getReal() > 0.0 == g0Positive) {
  338.             // loop gave up and didn't find any crossing within this step
  339.             return false;
  340.         } else {
  341.             // real crossing
  342.             check(beforeRootT != null && !Double.isNaN(beforeRootG.getReal()));
  343.             // variation direction, with respect to the integration direction
  344.             increasing = !g0Positive;
  345.             pendingEventTime = beforeRootT;
  346.             stopTime = beforeRootG.getReal() == 0.0 ? beforeRootT : afterRootT;
  347.             pendingEvent = true;
  348.             afterEvent = afterRootT;
  349.             afterG = afterRootG;

  350.             // check increasing set correctly
  351.             check(afterG.getReal() > 0 == increasing);
  352.             check(increasing == gb.getReal() >= ga.getReal());

  353.             return true;
  354.         }

  355.     }

  356.     /**
  357.      * Get the next number after the given number in the current propagation direction.
  358.      *
  359.      * @param t input time
  360.      * @return t +/- 1 ulp depending on the direction.
  361.      */
  362.     private FieldAbsoluteDate<T> nextAfter(final FieldAbsoluteDate<T> t) {
  363.         return t.shiftedBy(forward ? +Precision.EPSILON : -Precision.EPSILON);
  364.     }


  365.     /** Get the occurrence time of the event triggered in the current
  366.      * step.
  367.      * @return occurrence time of the event triggered in the current
  368.      * step.
  369.      */
  370.     public FieldAbsoluteDate<T> getEventDate() {
  371.         return pendingEventTime;
  372.     }

  373.     /**
  374.      * Try to accept the current history up to the given time.
  375.      *
  376.      * <p> It is not necessary to call this method before calling {@link
  377.      * #doEvent(FieldSpacecraftState)} with the same state. It is necessary to call this
  378.      * method before you call {@link #doEvent(FieldSpacecraftState)} on some other event
  379.      * detector.
  380.      *
  381.      * @param state        to try to accept.
  382.      * @param interpolator to use to find the new root, if any.
  383.      * @return if the event detector has an event it has not detected before that is on or
  384.      * before the same time as {@code state}. In other words {@code false} means continue
  385.      * on while {@code true} means stop and handle my event first.
  386.      * @exception OrekitException if the g function throws one
  387.      */
  388.     public boolean tryAdvance(final FieldSpacecraftState<T> state,
  389.                               final FieldOrekitStepInterpolator<T> interpolator)
  390.         throws OrekitException {
  391.         // check this is only called before a pending event.

  392.         check(!(pendingEvent && strictlyAfter(pendingEventTime, state.getDate())));
  393.         final FieldAbsoluteDate<T> t = state.getDate();

  394.         // just found an event and we know the next time we want to search again
  395.         if (strictlyAfter(t, earliestTimeConsidered)) {
  396.             return false;
  397.         }

  398.         final T g = g(state);
  399.         final boolean positive = g.getReal() > 0;

  400.         // check for new root, pendingEventTime may be null if there is not pending event
  401.         if ((g.getReal() == 0.0 && t.equals(pendingEventTime)) || positive == g0Positive) {
  402.             // at a root we already found, or g function has expected sign
  403.             t0 = t;
  404.             g0 = g; // g0Positive is the same
  405.             return false;
  406.         } else {

  407.             // found a root we didn't expect -> find precise location
  408.             return findRoot(interpolator, t0, g0, t, g);
  409.         }
  410.     }

  411.     /**
  412.      * Notify the user's listener of the event. The event occurs wholly within this method
  413.      * call including a call to {@link FieldEventDetector#resetState(FieldSpacecraftState)}
  414.      * if necessary.
  415.      *
  416.      * @param state the state at the time of the event. This must be at the same time as
  417.      *              the current value of {@link #getEventDate()}.
  418.      * @return the user's requested action and the new state if the action is {@link
  419.      * org.orekit.propagation.events.handlers.FieldEventHandler.Action#RESET_STATE}. Otherwise
  420.      * the new state is {@code state}. The stop time indicates what time propagation should
  421.      * stop if the action is {@link org.orekit.propagation.events.handlers.FieldEventHandler.Action#STOP}.
  422.      * This guarantees the integration will stop on or after the root, so that integration
  423.      * may be restarted safely.
  424.      * @exception OrekitException if the event detector throws one
  425.      */
  426.     public EventOccurrence<T> doEvent(final FieldSpacecraftState<T> state)
  427.         throws OrekitException {
  428.         // check event is pending and is at the same time
  429.         check(pendingEvent);
  430.         check(state.getDate().equals(this.pendingEventTime));

  431.         final FieldEventHandler.Action action = detector.eventOccurred(state, increasing == forward);
  432.         final FieldSpacecraftState<T> newState;
  433.         if (action == FieldEventHandler.Action.RESET_STATE) {
  434.             newState = detector.resetState(state);
  435.         } else {
  436.             newState = state;
  437.         }
  438.         // clear pending event
  439.         pendingEvent     = false;
  440.         pendingEventTime = null;
  441.         // setup for next search
  442.         earliestTimeConsidered = afterEvent;
  443.         t0 = afterEvent;
  444.         g0 = afterG;
  445.         g0Positive = increasing;
  446.         // check g0Positive set correctly
  447.         check(g0.getReal() == 0.0 || g0Positive == (g0.getReal() > 0));
  448.         return new EventOccurrence<T>(action, newState, stopTime);
  449.     }

  450.     /**
  451.      * Shift a time value along the current integration direction: {@link #forward}.
  452.      *
  453.      * @param t     the time to shift.
  454.      * @param delta the amount to shift.
  455.      * @return t + delta if forward, else t - delta. If the result has to be rounded it
  456.      * will be rounded to be before the true value of t + delta.
  457.      */
  458.     private FieldAbsoluteDate<T> shiftedBy(final FieldAbsoluteDate<T> t, final T delta) {
  459.         if (forward) {
  460.             final FieldAbsoluteDate<T> ret = t.shiftedBy(delta);
  461.             if (ret.durationFrom(t).getReal() > delta.getReal()) {
  462.                 return ret.shiftedBy(-Precision.EPSILON);
  463.             } else {
  464.                 return ret;
  465.             }
  466.         } else {
  467.             final FieldAbsoluteDate<T> ret = t.shiftedBy(delta.negate());
  468.             if (t.durationFrom(ret).getReal() > delta.getReal()) {
  469.                 return ret.shiftedBy(+Precision.EPSILON);
  470.             } else {
  471.                 return ret;
  472.             }
  473.         }
  474.     }

  475.     /**
  476.      * Get the time that happens first along the current propagation direction: {@link
  477.      * #forward}.
  478.      *
  479.      * @param a first time
  480.      * @param b second time
  481.      * @return min(a, b) if forward, else max (a, b)
  482.      */
  483.     private FieldAbsoluteDate<T> minTime(final FieldAbsoluteDate<T> a, final FieldAbsoluteDate<T> b) {
  484.         return (forward ^ (a.compareTo(b) > 0)) ? a : b;
  485.     }

  486.     /**
  487.      * Check the ordering of two times.
  488.      *
  489.      * @param t1 the first time.
  490.      * @param t2 the second time.
  491.      * @return true if {@code t2} is strictly after {@code t1} in the propagation
  492.      * direction.
  493.      */
  494.     private boolean strictlyAfter(final FieldAbsoluteDate<T> t1, final FieldAbsoluteDate<T> t2) {
  495.         if (t1 == null || t2 == null) {
  496.             return false;
  497.         } else {
  498.             return forward ? t1.compareTo(t2) < 0 : t2.compareTo(t1) < 0;
  499.         }
  500.     }

  501.     /**
  502.      * Same as keyword assert, but throw a {@link MathRuntimeException}.
  503.      *
  504.      * @param condition to check
  505.      * @throws MathRuntimeException if {@code condition} is false.
  506.      */
  507.     private void check(final boolean condition) throws MathRuntimeException {
  508.         if (!condition) {
  509.             throw new OrekitInternalError(null);
  510.         }
  511.     }

  512.     /**
  513.      * Class to hold the data related to an event occurrence that is needed to decide how
  514.      * to modify integration.
  515.      */
  516.     public static class EventOccurrence<T extends RealFieldElement<T>> {

  517.         /** User requested action. */
  518.         private final FieldEventHandler.Action action;
  519.         /** New state for a reset action. */
  520.         private final FieldSpacecraftState<T> newState;
  521.         /** The time to stop propagation if the action is a stop event. */
  522.         private final FieldAbsoluteDate<T> stopDate;

  523.         /**
  524.          * Create a new occurrence of an event.
  525.          *
  526.          * @param action   the user requested action.
  527.          * @param newState for a reset event. Should be the current state unless the
  528.          *                 action is {@link Action#RESET_STATE}.
  529.          * @param stopDate to stop propagation if the action is {@link Action#STOP}. Used
  530.          *                 to move the stop time to just after the root.
  531.          */
  532.         EventOccurrence(final FieldEventHandler.Action action,
  533.                         final FieldSpacecraftState<T> newState,
  534.                         final FieldAbsoluteDate<T> stopDate) {
  535.             this.action = action;
  536.             this.newState = newState;
  537.             this.stopDate = stopDate;
  538.         }

  539.         /**
  540.          * Get the user requested action.
  541.          *
  542.          * @return the action.
  543.          */
  544.         public FieldEventHandler.Action getAction() {
  545.             return action;
  546.         }

  547.         /**
  548.          * Get the new state for a reset action.
  549.          *
  550.          * @return the new state.
  551.          */
  552.         public FieldSpacecraftState<T> getNewState() {
  553.             return newState;
  554.         }

  555.         /**
  556.          * Get the new time for a stop action.
  557.          *
  558.          * @return when to stop propagation.
  559.          */
  560.         public FieldAbsoluteDate<T> getStopDate() {
  561.             return stopDate;
  562.         }

  563.     }

  564.     /**Get PendingEvent.
  565.      * @return if there is a pending event or not
  566.      * */

  567.     public boolean getPendingEvent() {
  568.         return pendingEvent;
  569.     }

  570. }