EventState.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.analysis.UnivariateFunction;
  19. import org.hipparchus.analysis.solvers.BracketedUnivariateSolver;
  20. import org.hipparchus.analysis.solvers.BracketedUnivariateSolver.Interval;
  21. import org.hipparchus.analysis.solvers.BracketingNthOrderBrentSolver;
  22. import org.hipparchus.exception.MathRuntimeException;
  23. import org.hipparchus.ode.events.Action;
  24. import org.hipparchus.util.FastMath;
  25. import org.hipparchus.util.Precision;
  26. import org.orekit.errors.OrekitException;
  27. import org.orekit.errors.OrekitInternalError;
  28. import org.orekit.errors.OrekitMessages;
  29. import org.orekit.propagation.SpacecraftState;
  30. import org.orekit.propagation.sampling.OrekitStepInterpolator;
  31. import org.orekit.time.AbsoluteDate;

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

  50.     /** Event detector. */
  51.     private T detector;

  52.     /** Time of the previous call to g. */
  53.     private AbsoluteDate lastT;

  54.     /** Value from the previous call to g. */
  55.     private double lastG;

  56.     /** Time at the beginning of the step. */
  57.     private AbsoluteDate t0;

  58.     /** Value of the event detector at the beginning of the step. */
  59.     private double g0;

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

  62.     /** Indicator of event expected during the step. */
  63.     private boolean pendingEvent;

  64.     /** Occurrence time of the pending event. */
  65.     private AbsoluteDate pendingEventTime;

  66.     /**
  67.      * Time to stop propagation if the event is a stop event. Used to enable stopping at
  68.      * an event and then restarting after that event.
  69.      */
  70.     private AbsoluteDate stopTime;

  71.     /** Time after the current event. */
  72.     private AbsoluteDate afterEvent;

  73.     /** Value of the g function after the current event. */
  74.     private double afterG;

  75.     /** The earliest time considered for events. */
  76.     private AbsoluteDate earliestTimeConsidered;

  77.     /** Integration direction. */
  78.     private boolean forward;

  79.     /** Variation direction around pending event.
  80.      *  (this is considered with respect to the integration direction)
  81.      */
  82.     private boolean increasing;

  83.     /** Simple constructor.
  84.      * @param detector monitored event detector
  85.      */
  86.     public EventState(final T detector) {
  87.         this.detector     = detector;

  88.         // some dummy values ...
  89.         lastT                  = AbsoluteDate.PAST_INFINITY;
  90.         lastG                  = Double.NaN;
  91.         t0                     = null;
  92.         g0                     = Double.NaN;
  93.         g0Positive             = true;
  94.         pendingEvent           = false;
  95.         pendingEventTime       = null;
  96.         stopTime               = null;
  97.         increasing             = true;
  98.         earliestTimeConsidered = null;
  99.         afterEvent             = null;
  100.         afterG                 = Double.NaN;

  101.     }

  102.     /** Get the underlying event detector.
  103.      * @return underlying event detector
  104.      */
  105.     public T getEventDetector() {
  106.         return detector;
  107.     }

  108.     /** Initialize event handler at the start of a propagation.
  109.      * <p>
  110.      * This method is called once at the start of the propagation. It
  111.      * may be used by the event handler to initialize some internal data
  112.      * if needed.
  113.      * </p>
  114.      * @param s0 initial state
  115.      * @param t target time for the integration
  116.      *
  117.      */
  118.     public void init(final SpacecraftState s0,
  119.                      final AbsoluteDate t) {
  120.         detector.init(s0, t);
  121.         lastT = AbsoluteDate.PAST_INFINITY;
  122.         lastG = Double.NaN;
  123.     }

  124.     /** Compute the value of the switching function.
  125.      * This function must be continuous (at least in its roots neighborhood),
  126.      * as the integrator will need to find its roots to locate the events.
  127.      * @param s the current state information: date, kinematics, attitude
  128.      * @return value of the switching function
  129.      */
  130.     private double g(final SpacecraftState s) {
  131.         if (!s.getDate().equals(lastT)) {
  132.             lastG = detector.g(s);
  133.             lastT = s.getDate();
  134.         }
  135.         return lastG;
  136.     }

  137.     /** Reinitialize the beginning of the step.
  138.      * @param interpolator interpolator valid for the current step
  139.      */
  140.     public void reinitializeBegin(final OrekitStepInterpolator interpolator) {
  141.         forward = interpolator.isForward();
  142.         final SpacecraftState s0 = interpolator.getPreviousState();
  143.         this.t0 = s0.getDate();
  144.         g0 = g(s0);
  145.         while (g0 == 0) {
  146.             // extremely rare case: there is a zero EXACTLY at interval start
  147.             // we will use the sign slightly after step beginning to force ignoring this zero
  148.             // try moving forward by half a convergence interval
  149.             final double dt = (forward ? 0.5 : -0.5) * detector.getThreshold();
  150.             AbsoluteDate startDate = t0.shiftedBy(dt);
  151.             // if convergence is too small move an ulp
  152.             if (t0.equals(startDate)) {
  153.                 startDate = nextAfter(startDate);
  154.             }
  155.             t0 = startDate;
  156.             g0 = g(interpolator.getInterpolatedState(t0));
  157.         }
  158.         g0Positive = g0 > 0;
  159.         // "last" event was increasing
  160.         increasing = g0Positive;
  161.     }

  162.     /** Evaluate the impact of the proposed step on the event detector.
  163.      * @param interpolator step interpolator for the proposed step
  164.      * @return true if the event detector triggers an event before
  165.      * the end of the proposed step (this implies the step should be
  166.      * rejected)
  167.      * @exception MathRuntimeException if an event cannot be located
  168.      */
  169.     public boolean evaluateStep(final OrekitStepInterpolator interpolator)
  170.         throws MathRuntimeException {

  171.         forward = interpolator.isForward();
  172.         final SpacecraftState s1 = interpolator.getCurrentState();
  173.         final AbsoluteDate t1 = s1.getDate();
  174.         final double dt = t1.durationFrom(t0);
  175.         if (FastMath.abs(dt) < detector.getThreshold()) {
  176.             // we cannot do anything on such a small step, don't trigger any events
  177.             return false;
  178.         }
  179.         // number of points to check in the current step
  180.         final int n = FastMath.max(1, (int) FastMath.ceil(FastMath.abs(dt) / detector.getMaxCheckInterval()));
  181.         final double h = dt / n;


  182.         AbsoluteDate ta = t0;
  183.         double ga = g0;
  184.         for (int i = 0; i < n; ++i) {

  185.             // evaluate handler value at the end of the substep
  186.             final AbsoluteDate tb = (i == n - 1) ? t1 : t0.shiftedBy((i + 1) * h);
  187.             final double gb = g(interpolator.getInterpolatedState(tb));

  188.             // check events occurrence
  189.             if (gb == 0.0 || (g0Positive ^ (gb > 0))) {
  190.                 // there is a sign change: an event is expected during this step
  191.                 if (findRoot(interpolator, ta, ga, tb, gb)) {
  192.                     return true;
  193.                 }
  194.             } else {
  195.                 // no sign change: there is no event for now
  196.                 ta = tb;
  197.                 ga = gb;
  198.             }

  199.         }

  200.         // no event during the whole step
  201.         pendingEvent     = false;
  202.         pendingEventTime = null;
  203.         return false;

  204.     }

  205.     /**
  206.      * Find a root in a bracketing interval.
  207.      *
  208.      * <p> When calling this method one of the following must be true. Either ga == 0, gb
  209.      * == 0, (ga < 0  and gb > 0), or (ga > 0 and gb < 0).
  210.      *
  211.      * @param interpolator that covers the interval.
  212.      * @param ta           earliest possible time for root.
  213.      * @param ga           g(ta).
  214.      * @param tb           latest possible time for root.
  215.      * @param gb           g(tb).
  216.      * @return if a zero crossing was found.
  217.      */
  218.     private boolean findRoot(final OrekitStepInterpolator interpolator,
  219.                              final AbsoluteDate ta, final double ga,
  220.                              final AbsoluteDate tb, final double gb) {
  221.         // check there appears to be a root in [ta, tb]
  222.         check(ga == 0.0 || gb == 0.0 || ga > 0.0 && gb < 0.0 || ga < 0.0 && gb > 0.0);

  223.         final double convergence = detector.getThreshold();
  224.         final int maxIterationCount = detector.getMaxIterationCount();
  225.         final BracketedUnivariateSolver<UnivariateFunction> solver =
  226.                 new BracketingNthOrderBrentSolver(0, convergence, 0, 5);

  227.         // prepare loop below
  228.         AbsoluteDate loopT = ta;
  229.         double loopG = ga;

  230.         // event time, just at or before the actual root.
  231.         AbsoluteDate beforeRootT = null;
  232.         double beforeRootG = Double.NaN;
  233.         // time on the other side of the root.
  234.         // Initialized the the loop below executes once.
  235.         AbsoluteDate afterRootT = ta;
  236.         double afterRootG = 0.0;

  237.         // check for some conditions that the root finders don't like
  238.         // these conditions cannot not happen in the loop below
  239.         // the ga == 0.0 case is handled by the loop below
  240.         if (ta.equals(tb)) {
  241.             // both non-zero but times are the same. Probably due to reset state
  242.             beforeRootT = ta;
  243.             beforeRootG = ga;
  244.             afterRootT = shiftedBy(beforeRootT, convergence);
  245.             afterRootG = g(interpolator.getInterpolatedState(afterRootT));
  246.         } else if (ga != 0.0 && gb == 0.0) {
  247.             // hard: ga != 0.0 and gb == 0.0
  248.             // look past gb by up to convergence to find next sign
  249.             // throw an exception if g(t) = 0.0 in [tb, tb + convergence]
  250.             beforeRootT = tb;
  251.             beforeRootG = gb;
  252.             afterRootT = shiftedBy(beforeRootT, convergence);
  253.             afterRootG = g(interpolator.getInterpolatedState(afterRootT));
  254.         } else if (ga != 0.0) {
  255.             final double newGa = g(interpolator.getInterpolatedState(ta));
  256.             if (ga > 0 != newGa > 0) {
  257.                 // both non-zero, step sign change at ta, possibly due to reset state
  258.                 final AbsoluteDate nextT = minTime(shiftedBy(ta, convergence), tb);
  259.                 final double       nextG = g(interpolator.getInterpolatedState(nextT));
  260.                 if (nextG > 0.0 == g0Positive) {
  261.                     // the sign change between ga and newGa just moved the root less than one convergence
  262.                     // threshold later, we are still in a regular search for another root before tb,
  263.                     // we just need to fix the bracketing interval
  264.                     // (see issue https://github.com/Hipparchus-Math/hipparchus/issues/184)
  265.                     loopT = nextT;
  266.                     loopG = nextG;
  267.                 } else {
  268.                     beforeRootT = ta;
  269.                     beforeRootG = newGa;
  270.                     afterRootT  = nextT;
  271.                     afterRootG  = nextG;
  272.                 }
  273.             }
  274.         }

  275.         // loop to skip through "fake" roots, i.e. where g(t) = g'(t) = 0.0
  276.         // executed once if we didn't hit a special case above
  277.         while ((afterRootG == 0.0 || afterRootG > 0.0 == g0Positive) &&
  278.                 strictlyAfter(afterRootT, tb)) {
  279.             if (loopG == 0.0) {
  280.                 // ga == 0.0 and gb may or may not be 0.0
  281.                 // handle the root at ta first
  282.                 beforeRootT = loopT;
  283.                 beforeRootG = loopG;
  284.                 afterRootT = minTime(shiftedBy(beforeRootT, convergence), tb);
  285.                 afterRootG = g(interpolator.getInterpolatedState(afterRootT));
  286.             } else {
  287.                 // both non-zero, the usual case, use a root finder.
  288.                 // time zero for evaluating the function f. Needs to be final
  289.                 final AbsoluteDate fT0 = loopT;
  290.                 final double tbDouble = tb.durationFrom(fT0);
  291.                 final double middle = 0.5 * tbDouble;
  292.                 final UnivariateFunction f = dt -> {
  293.                     // use either fT0 or tb as the base time for shifts
  294.                     // in order to ensure we reproduce exactly those times
  295.                     // using only one reference time like fT0 would imply
  296.                     // to use ft0.shiftedBy(tbDouble), which may be different
  297.                     // from tb due to numerical noise (see issue 921)
  298.                     final AbsoluteDate t;
  299.                     if (forward == dt <= middle) {
  300.                         // use start of interval as reference
  301.                         t = fT0.shiftedBy(dt);
  302.                     } else {
  303.                         // use end of interval as reference
  304.                         t = tb.shiftedBy(dt - tbDouble);
  305.                     }
  306.                     return g(interpolator.getInterpolatedState(t));
  307.                 };
  308.                 // tb as a double for use in f
  309.                 if (forward) {
  310.                     try {
  311.                         final Interval interval =
  312.                                 solver.solveInterval(maxIterationCount, f, 0, tbDouble);
  313.                         beforeRootT = fT0.shiftedBy(interval.getLeftAbscissa());
  314.                         beforeRootG = interval.getLeftValue();
  315.                         afterRootT = fT0.shiftedBy(interval.getRightAbscissa());
  316.                         afterRootG = interval.getRightValue();
  317.                         // CHECKSTYLE: stop IllegalCatch check
  318.                     } catch (RuntimeException e) {
  319.                         // CHECKSTYLE: resume IllegalCatch check
  320.                         throw new OrekitException(e, OrekitMessages.FIND_ROOT,
  321.                                 detector, loopT, loopG, tb, gb, lastT, lastG);
  322.                     }
  323.                 } else {
  324.                     try {
  325.                         final Interval interval =
  326.                                 solver.solveInterval(maxIterationCount, f, tbDouble, 0);
  327.                         beforeRootT = fT0.shiftedBy(interval.getRightAbscissa());
  328.                         beforeRootG = interval.getRightValue();
  329.                         afterRootT = fT0.shiftedBy(interval.getLeftAbscissa());
  330.                         afterRootG = interval.getLeftValue();
  331.                         // CHECKSTYLE: stop IllegalCatch check
  332.                     } catch (RuntimeException e) {
  333.                         // CHECKSTYLE: resume IllegalCatch check
  334.                         throw new OrekitException(e, OrekitMessages.FIND_ROOT,
  335.                                 detector, tb, gb, loopT, loopG, lastT, lastG);
  336.                     }
  337.                 }
  338.             }
  339.             // tolerance is set to less than 1 ulp
  340.             // assume tolerance is 1 ulp
  341.             if (beforeRootT.equals(afterRootT)) {
  342.                 afterRootT = nextAfter(afterRootT);
  343.                 afterRootG = g(interpolator.getInterpolatedState(afterRootT));
  344.             }
  345.             // check loop is making some progress
  346.             check(forward && afterRootT.compareTo(beforeRootT) > 0 ||
  347.                   !forward && afterRootT.compareTo(beforeRootT) < 0);
  348.             // setup next iteration
  349.             loopT = afterRootT;
  350.             loopG = afterRootG;
  351.         }

  352.         // figure out the result of root finding, and return accordingly
  353.         if (afterRootG == 0.0 || afterRootG > 0.0 == g0Positive) {
  354.             // loop gave up and didn't find any crossing within this step
  355.             return false;
  356.         } else {
  357.             // real crossing
  358.             check(beforeRootT != null && !Double.isNaN(beforeRootG));
  359.             // variation direction, with respect to the integration direction
  360.             increasing = !g0Positive;
  361.             pendingEventTime = beforeRootT;
  362.             stopTime = beforeRootG == 0.0 ? beforeRootT : afterRootT;
  363.             pendingEvent = true;
  364.             afterEvent = afterRootT;
  365.             afterG = afterRootG;

  366.             // check increasing set correctly
  367.             check(afterG > 0 == increasing);
  368.             check(increasing == gb >= ga);

  369.             return true;
  370.         }

  371.     }

  372.     /**
  373.      * Get the next number after the given number in the current propagation direction.
  374.      *
  375.      * @param t input time
  376.      * @return t +/- 1 ulp depending on the direction.
  377.      */
  378.     private AbsoluteDate nextAfter(final AbsoluteDate t) {
  379.         return t.shiftedBy(forward ? +Precision.EPSILON : -Precision.EPSILON);
  380.     }

  381.     /** Get the occurrence time of the event triggered in the current
  382.      * step.
  383.      * @return occurrence time of the event triggered in the current
  384.      * step.
  385.      */
  386.     public AbsoluteDate getEventDate() {
  387.         return pendingEventTime;
  388.     }

  389.     /**
  390.      * Try to accept the current history up to the given time.
  391.      *
  392.      * <p> It is not necessary to call this method before calling {@link
  393.      * #doEvent(SpacecraftState)} with the same state. It is necessary to call this
  394.      * method before you call {@link #doEvent(SpacecraftState)} on some other event
  395.      * detector.
  396.      *
  397.      * @param state        to try to accept.
  398.      * @param interpolator to use to find the new root, if any.
  399.      * @return if the event detector has an event it has not detected before that is on or
  400.      * before the same time as {@code state}. In other words {@code false} means continue
  401.      * on while {@code true} means stop and handle my event first.
  402.      */
  403.     public boolean tryAdvance(final SpacecraftState state,
  404.                               final OrekitStepInterpolator interpolator) {
  405.         final AbsoluteDate t = state.getDate();
  406.         // check this is only called before a pending event.
  407.         check(!pendingEvent || !strictlyAfter(pendingEventTime, t));

  408.         final boolean meFirst;

  409.         if (strictlyAfter(t, earliestTimeConsidered)) {
  410.             // just found an event and we know the next time we want to search again
  411.             meFirst = false;
  412.         } else {
  413.             // check g function to see if there is a new event
  414.             final double g = g(state);
  415.             final boolean positive = g > 0;

  416.             if (positive == g0Positive) {
  417.                 // g function has expected sign
  418.                 g0 = g; // g0Positive is the same
  419.                 meFirst = false;
  420.             } else {
  421.                 // found a root we didn't expect -> find precise location
  422.                 final AbsoluteDate oldPendingEventTime = pendingEventTime;
  423.                 final boolean foundRoot = findRoot(interpolator, t0, g0, t, g);
  424.                 // make sure the new root is not the same as the old root, if one exists
  425.                 meFirst = foundRoot && !pendingEventTime.equals(oldPendingEventTime);
  426.             }
  427.         }

  428.         if (!meFirst) {
  429.             // advance t0 to the current time so we can't find events that occur before t
  430.             t0 = t;
  431.         }

  432.         return meFirst;
  433.     }

  434.     /**
  435.      * Notify the user's listener of the event. The event occurs wholly within this method
  436.      * call including a call to {@link EventDetector#resetState(SpacecraftState)}
  437.      * if necessary.
  438.      *
  439.      * @param state the state at the time of the event. This must be at the same time as
  440.      *              the current value of {@link #getEventDate()}.
  441.      * @return the user's requested action and the new state if the action is {@link
  442.      * Action#RESET_STATE Action.RESET_STATE}.
  443.      * Otherwise the new state is {@code state}. The stop time indicates what time propagation
  444.      * should stop if the action is {@link Action#STOP Action.STOP}.
  445.      * This guarantees the integration will stop on or after the root, so that integration
  446.      * may be restarted safely.
  447.      */
  448.     public EventOccurrence doEvent(final SpacecraftState state) {
  449.         // check event is pending and is at the same time
  450.         check(pendingEvent);
  451.         check(state.getDate().equals(this.pendingEventTime));

  452.         final Action action = detector.eventOccurred(state, increasing == forward);
  453.         final SpacecraftState newState;
  454.         if (action == Action.RESET_STATE) {
  455.             newState = detector.resetState(state);
  456.         } else {
  457.             newState = state;
  458.         }
  459.         // clear pending event
  460.         pendingEvent     = false;
  461.         pendingEventTime = null;
  462.         // setup for next search
  463.         earliestTimeConsidered = afterEvent;
  464.         t0 = afterEvent;
  465.         g0 = afterG;
  466.         g0Positive = increasing;
  467.         // check g0Positive set correctly
  468.         check(g0 == 0.0 || g0Positive == g0 > 0);
  469.         return new EventOccurrence(action, newState, stopTime);
  470.     }

  471.     /**
  472.      * Shift a time value along the current integration direction: {@link #forward}.
  473.      *
  474.      * @param t     the time to shift.
  475.      * @param delta the amount to shift.
  476.      * @return t + delta if forward, else t - delta. If the result has to be rounded it
  477.      * will be rounded to be before the true value of t + delta.
  478.      */
  479.     private AbsoluteDate shiftedBy(final AbsoluteDate t, final double delta) {
  480.         if (forward) {
  481.             final AbsoluteDate ret = t.shiftedBy(delta);
  482.             if (ret.durationFrom(t) > delta) {
  483.                 return ret.shiftedBy(-Precision.EPSILON);
  484.             } else {
  485.                 return ret;
  486.             }
  487.         } else {
  488.             final AbsoluteDate ret = t.shiftedBy(-delta);
  489.             if (t.durationFrom(ret) > delta) {
  490.                 return ret.shiftedBy(+Precision.EPSILON);
  491.             } else {
  492.                 return ret;
  493.             }
  494.         }
  495.     }

  496.     /**
  497.      * Get the time that happens first along the current propagation direction: {@link
  498.      * #forward}.
  499.      *
  500.      * @param a first time
  501.      * @param b second time
  502.      * @return min(a, b) if forward, else max (a, b)
  503.      */
  504.     private AbsoluteDate minTime(final AbsoluteDate a, final AbsoluteDate b) {
  505.         return (forward ^ (a.compareTo(b) > 0)) ? a : b;
  506.     }

  507.     /**
  508.      * Check the ordering of two times.
  509.      *
  510.      * @param t1 the first time.
  511.      * @param t2 the second time.
  512.      * @return true if {@code t2} is strictly after {@code t1} in the propagation
  513.      * direction.
  514.      */
  515.     private boolean strictlyAfter(final AbsoluteDate t1, final AbsoluteDate t2) {
  516.         if (t1 == null || t2 == null) {
  517.             return false;
  518.         } else {
  519.             return forward ? t1.compareTo(t2) < 0 : t2.compareTo(t1) < 0;
  520.         }
  521.     }

  522.     /**
  523.      * Same as keyword assert, but throw a {@link MathRuntimeException}.
  524.      *
  525.      * @param condition to check
  526.      * @throws MathRuntimeException if {@code condition} is false.
  527.      */
  528.     private void check(final boolean condition) throws MathRuntimeException {
  529.         if (!condition) {
  530.             throw new OrekitInternalError(null);
  531.         }
  532.     }

  533.     /**
  534.      * Class to hold the data related to an event occurrence that is needed to decide how
  535.      * to modify integration.
  536.      */
  537.     public static class EventOccurrence {

  538.         /** User requested action. */
  539.         private final Action action;
  540.         /** New state for a reset action. */
  541.         private final SpacecraftState newState;
  542.         /** The time to stop propagation if the action is a stop event. */
  543.         private final AbsoluteDate stopDate;

  544.         /**
  545.          * Create a new occurrence of an event.
  546.          *
  547.          * @param action   the user requested action.
  548.          * @param newState for a reset event. Should be the current state unless the
  549.          *                 action is {@link Action#RESET_STATE}.
  550.          * @param stopDate to stop propagation if the action is {@link Action#STOP}. Used
  551.          *                 to move the stop time to just after the root.
  552.          */
  553.         EventOccurrence(final Action action,
  554.                         final SpacecraftState newState,
  555.                         final AbsoluteDate stopDate) {
  556.             this.action = action;
  557.             this.newState = newState;
  558.             this.stopDate = stopDate;
  559.         }

  560.         /**
  561.          * Get the user requested action.
  562.          *
  563.          * @return the action.
  564.          */
  565.         public Action getAction() {
  566.             return action;
  567.         }

  568.         /**
  569.          * Get the new state for a reset action.
  570.          *
  571.          * @return the new state.
  572.          */
  573.         public SpacecraftState getNewState() {
  574.             return newState;
  575.         }

  576.         /**
  577.          * Get the new time for a stop action.
  578.          *
  579.          * @return when to stop propagation.
  580.          */
  581.         public AbsoluteDate getStopDate() {
  582.             return stopDate;
  583.         }

  584.     }

  585. }