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 java.util.function.DoubleFunction;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  102.     }

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

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

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

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

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

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


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

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

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

  200.         }

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

  205.     }

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

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

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

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

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

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

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

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

  368.             return true;
  369.         }

  370.     }

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

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

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

  407.         final boolean meFirst;

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

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

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

  431.         return meFirst;
  432.     }

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

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

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

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

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

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

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

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

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

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

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

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

  583.     }

  584. }