FieldEventHandler.java

  1. /* Copyright 2013 Applied Defense Solutions, Inc.
  2.  * Licensed to CS Communication & Systèmes (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.handlers;

  18. import org.hipparchus.RealFieldElement;
  19. import org.orekit.errors.OrekitException;
  20. import org.orekit.propagation.FieldSpacecraftState;
  21. import org.orekit.propagation.events.EventDetector;
  22. import org.orekit.propagation.events.FieldEventDetector;
  23. import org.orekit.time.FieldAbsoluteDate;


  24. /**
  25.  * An interface defining how to override event handling behavior in the standard
  26.  * propagator eventing classes without requiring subclassing.  In cases where
  27.  * one wishes to use anonymous classes rather than explicit subclassing this
  28.  * allows for a more direct way to override the behavior.  Event classes have to
  29.  * specifically support this capability.
  30.  *
  31.  * @author Hank Grabowski
  32.  *
  33.  * @param <KK> object type that the handler is called from
  34.  * @since 6.1
  35.  */
  36. public interface FieldEventHandler<KK extends FieldEventDetector<T>, T extends RealFieldElement<T>> {

  37.     /** Enumerate for actions to be performed when an event occurs. */
  38.     enum Action {

  39.         /** Stop indicator.
  40.          * <p>This value should be used as the return value of the {@link
  41.          * #eventOccurred eventOccurred} method when the propagation should be
  42.          * stopped after the event ending the current step.</p>
  43.          */
  44.         STOP,

  45.         /** Reset state indicator.
  46.          * <p>This value should be used as the return value of the {@link
  47.          * #eventOccurred eventOccurred} method when the propagation should
  48.          * go on after the event ending the current step, with a new state
  49.          * (which will be retrieved thanks to the {@link #resetState
  50.          * resetState} method).</p>
  51.          */
  52.         RESET_STATE,

  53.         /** Reset derivatives indicator.
  54.          * <p>This value should be used as the return value of the {@link
  55.          * #eventOccurred eventOccurred} method when the propagation should
  56.          * go on after the event ending the current step, with recomputed
  57.          * derivatives vector.</p>
  58.          */
  59.         RESET_DERIVATIVES,

  60.         /** Continue indicator.
  61.          * <p>This value should be used as the return value of the {@link
  62.          * #eventOccurred eventOccurred} method when the propagation should go
  63.          * on after the event ending the current step.</p>
  64.          */
  65.         CONTINUE;

  66.     }

  67.     /** Initialize event handler at the start of a propagation.
  68.      * <p>
  69.      * This method is called once at the start of the propagation. It
  70.      * may be used by the event handler to initialize some internal data
  71.      * if needed.
  72.      * </p>
  73.      * <p>
  74.      * The default implementation does nothing
  75.      * </p>
  76.      * @param initialState initial state
  77.      * @param target target date for the propagation
  78.      *
  79.      * @throws  OrekitException if some specific error occurs
  80.      */
  81.     default void init(FieldSpacecraftState<T> initialState,
  82.                       FieldAbsoluteDate<T> target) throws OrekitException {
  83.         // nothing by default
  84.     }

  85.     /**
  86.      * eventOccurred method mirrors the same interface method as in {@link EventDetector}
  87.      * and its subclasses, but with an additional parameter that allows the calling
  88.      * method to pass in an object from the detector which would have potential
  89.      * additional data to allow the implementing class to determine the correct
  90.      * return state.
  91.      *
  92.      * @param s SpaceCraft state to be used in the evaluation
  93.      * @param detector object with appropriate type that can be used in determining correct return state
  94.      * @param increasing with the event occurred in an "increasing" or "decreasing" slope direction
  95.      * @return the Action that the calling detector should pass back to the evaluation system
  96.      *
  97.      * @exception OrekitException if some specific error occurs
  98.      */
  99.     Action eventOccurred(FieldSpacecraftState<T> s, KK detector, boolean increasing) throws OrekitException;

  100.     /** Reset the state prior to continue propagation.
  101.      * <p>This method is called after the step handler has returned and
  102.      * before the next step is started, but only when {@link
  103.      * #eventOccurred} has itself returned the {@link Action#RESET_STATE}
  104.      * indicator. It allows the user to reset the state for the next step,
  105.      * without perturbing the step handler of the finishing step. If the
  106.      * {@link #eventOccurred} never returns the {@link Action#RESET_STATE}
  107.      * indicator, this function will never be called, and it is safe to simply return null.</p>
  108.      * <p>
  109.      * The default implementation simply return its argument.
  110.      * </p>
  111.      * @param detector object with appropriate type that can be used in determining correct return state
  112.      * @param oldState old state
  113.      * @return new state
  114.      * @exception OrekitException if the state cannot be reseted
  115.      */
  116.     default FieldSpacecraftState<T> resetState(KK detector, FieldSpacecraftState<T> oldState)
  117.         throws OrekitException {
  118.         return oldState;
  119.     }
  120. }