EventDetector.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.events;

  18. import org.orekit.propagation.SpacecraftState;
  19. import org.orekit.propagation.events.handlers.EventHandler;
  20. import org.orekit.time.AbsoluteDate;

  21. /** This interface represents space-dynamics aware events detectors.
  22.  *
  23.  * <p>It mirrors the {@link org.hipparchus.ode.events.ODEEventHandler
  24.  * ODEEventHandler} interface from <a href="https://hipparchus.org/">
  25.  * Hipparchus</a> but provides a space-dynamics interface to the
  26.  * methods.</p>
  27.  *
  28.  * <p>Events detectors are a useful solution to meet the requirements
  29.  * of propagators concerning discrete conditions. The state of each
  30.  * event detector is queried by the propagator from time to time, at least
  31.  * once every {@link #getMaxCheckInterval() max check interval} but it may
  32.  * be more frequent. When the sign of the underlying g switching function
  33.  * changes, a root-finding algorithm is run to precisely locate the event,
  34.  * down to a configured {@link #getThreshold() convergence threshold}. The
  35.  * {@link #getMaxCheckInterval() max check interval} is therefore devoted to
  36.  * separate roots and is often much larger than the  {@link #getThreshold()
  37.  * convergence threshold}.</p>
  38.  *
  39.  * <p>The physical meaning of the g switching function is not really used
  40.  * by the event detection algorithms. Its varies from event detector to
  41.  * event detector. One example would be a visibility detector that could use the
  42.  * angular elevation of the satellite above horizon as a g switching function.
  43.  * In this case, the function would switch from negative to positive when the
  44.  * satellite raises above horizon and it would switch from positive to negative
  45.  * when it sets backs below horizon. Another example would be an apside detector
  46.  * that could use the dot product of position and velocity. In this case, the
  47.  * function would switch from negative to positive when the satellite crosses
  48.  * periapsis and it would switch from positive to negative when the satellite
  49.  * crosses apoapsis.</p>
  50.  *
  51.  * <p>When the precise state at which the g switching function changes has been
  52.  * located, the corresponding event is triggered, by calling the {@link
  53.  * EventHandler#eventOccurred(SpacecraftState, EventDetector, boolean) eventOccurred}
  54.  * method from the associated {@link #getHandler() handler}.
  55.  * The method can do whatever it needs with the event (logging it, performing
  56.  * some processing, ignore it ...). The return value of the method will be used by
  57.  * the propagator to stop or resume propagation, possibly changing the state vector.</p>
  58.  *
  59.  * @author Luc Maisonobe
  60.  * @author V&eacute;ronique Pommier-Maurussane
  61.  */
  62. public interface EventDetector {

  63.     /** Initialize event handler at the start of a propagation.
  64.      * <p>
  65.      * This method is called once at the start of the propagation. It
  66.      * may be used by the event handler to initialize some internal data
  67.      * if needed.
  68.      * </p>
  69.      * <p>
  70.      * The default implementation does nothing
  71.      * </p>
  72.      * @param s0 initial state
  73.      * @param t target time for the integration
  74.      *
  75.      */
  76.     default void init(SpacecraftState s0, AbsoluteDate t) {
  77.         // nothing by default
  78.     }

  79.     /** Compute the value of the switching function.
  80.      * This function must be continuous (at least in its roots neighborhood),
  81.      * as the integrator will need to find its roots to locate the events.
  82.      * @param s the current state information: date, kinematics, attitude
  83.      * @return value of the switching function
  84.      */
  85.     double g(SpacecraftState s);

  86.     /** Get the convergence threshold in the event time search.
  87.      * @return convergence threshold (s)
  88.      */
  89.     double getThreshold();

  90.     /** Get maximal time interval between switching function checks.
  91.      * @return maximal time interval (s) between switching function checks
  92.      */
  93.     AdaptableInterval getMaxCheckInterval();

  94.     /** Get maximal number of iterations in the event time search.
  95.      * @return maximal number of iterations in the event time search
  96.      */
  97.     int getMaxIterationCount();

  98.     /** Get the handler.
  99.      * @return event handler to call at event occurrences
  100.      * @since 12.0
  101.      */
  102.     EventHandler getHandler();

  103. }