FieldAltitudeDetector.java

  1. /* Copyright 2002-2025 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.hipparchus.CalculusFieldElement;
  19. import org.hipparchus.ode.events.Action;
  20. import org.orekit.bodies.BodyShape;
  21. import org.orekit.bodies.FieldGeodeticPoint;
  22. import org.orekit.frames.Frame;
  23. import org.orekit.propagation.FieldSpacecraftState;
  24. import org.orekit.propagation.events.handlers.FieldEventHandler;
  25. import org.orekit.propagation.events.handlers.FieldStopOnDecreasing;

  26. /** Finder for satellite altitude crossing events.
  27.  * <p>This class finds altitude events (i.e. satellite crossing
  28.  * a predefined altitude level above ground).</p>
  29.  * <p>The default implementation behavior is to {@link Action#CONTINUE
  30.  * continue} propagation when ascending and to {@link Action#STOP stop}
  31.  * propagation when descending. This can be changed by calling
  32.  * {@link #withHandler(FieldEventHandler)} after construction.</p>
  33.  * @see org.orekit.propagation.FieldPropagator#addEventDetector(FieldEventDetector)
  34.  * @author Luc Maisonobe
  35.  * @since 9.0
  36.  * @param <T> type of the field elements
  37.  */
  38. public class FieldAltitudeDetector<T extends CalculusFieldElement<T>> extends FieldAbstractDetector<FieldAltitudeDetector<T>, T> {

  39.     /** Threshold altitude value (m). */
  40.     private final T altitude;

  41.     /** Body shape with respect to which altitude should be evaluated. */
  42.     private final BodyShape bodyShape;

  43.     /** Build a new altitude detector.
  44.      * <p>This simple constructor takes default values for maximal checking
  45.      *  interval ({@link #DEFAULT_MAX_CHECK}) and convergence threshold
  46.      * ({@link #DEFAULT_THRESHOLD}).</p>
  47.      * @param altitude threshold altitude value
  48.      * @param bodyShape body shape with respect to which altitude should be evaluated
  49.      */
  50.     public FieldAltitudeDetector(final T altitude, final BodyShape bodyShape) {
  51.         this(altitude.getField().getZero().newInstance(DEFAULT_MAX_CHECK),
  52.              altitude.getField().getZero().newInstance(DEFAULT_THRESHOLD),
  53.              altitude, bodyShape);
  54.     }

  55.     /** Build a new altitude detector.
  56.      * <p>This simple constructor takes default value for convergence threshold
  57.      * ({@link #DEFAULT_THRESHOLD}).</p>
  58.      * <p>The maximal interval between altitude checks should
  59.      * be smaller than the half duration of the minimal pass to handle,
  60.      * otherwise some short passes could be missed.</p>
  61.      * @param maxCheck maximal checking interval (s)
  62.      * @param altitude threshold altitude value (m)
  63.      * @param bodyShape body shape with respect to which altitude should be evaluated
  64.      */
  65.     public FieldAltitudeDetector(final T maxCheck,
  66.                                  final T altitude,
  67.                                  final BodyShape bodyShape) {
  68.         this(maxCheck, altitude.getField().getZero().newInstance(DEFAULT_THRESHOLD), altitude, bodyShape);
  69.     }

  70.     /** Build a new altitude detector.
  71.      * <p>The maximal interval between altitude checks should
  72.      * be smaller than the half duration of the minimal pass to handle,
  73.      * otherwise some short passes could be missed.</p>
  74.      * <p>The maximal interval between altitude checks should
  75.      * be smaller than the half duration of the minimal pass to handle,
  76.      * otherwise some short passes could be missed.</p>
  77.      * @param maxCheck maximal checking interval (s)
  78.      * @param threshold convergence threshold (s)
  79.      * @param altitude threshold altitude value (m)
  80.      * @param bodyShape body shape with respect to which altitude should be evaluated
  81.      */
  82.     public FieldAltitudeDetector(final T maxCheck,
  83.                                  final T threshold,
  84.                                  final T altitude,
  85.                                  final BodyShape bodyShape) {
  86.         this(new FieldEventDetectionSettings<>(maxCheck.getReal(), threshold, DEFAULT_MAX_ITER), new FieldStopOnDecreasing<>(),
  87.              altitude, bodyShape);
  88.     }

  89.     /** Protected constructor with full parameters.
  90.      * <p>
  91.      * This constructor is not public as users are expected to use the builder
  92.      * API with the various {@code withXxx()} methods to set up the instance
  93.      * in a readable manner without using a huge amount of parameters.
  94.      * </p>
  95.      * @param detectionSettings event detection settings
  96.      * @param handler event handler to call at event occurrences
  97.      * @param altitude threshold altitude value (m)
  98.      * @param bodyShape body shape with respect to which altitude should be evaluated
  99.      * @since 13.0
  100.      */
  101.     protected FieldAltitudeDetector(final FieldEventDetectionSettings<T> detectionSettings,
  102.                                     final FieldEventHandler<T> handler, final T altitude, final BodyShape bodyShape) {
  103.         super(detectionSettings, handler);
  104.         this.altitude  = altitude;
  105.         this.bodyShape = bodyShape;
  106.     }

  107.     /** {@inheritDoc} */
  108.     @Override
  109.     protected FieldAltitudeDetector<T> create(final FieldEventDetectionSettings<T> detectionSettings,
  110.                                               final FieldEventHandler<T> newHandler) {
  111.         return new FieldAltitudeDetector<>(detectionSettings, newHandler, altitude, bodyShape);
  112.     }

  113.     /** Get the threshold altitude value.
  114.      * @return the threshold altitude value (m)
  115.      */
  116.     public T getAltitude() {
  117.         return altitude;
  118.     }

  119.     /** Get the body shape.
  120.      * @return the body shape
  121.      */
  122.     public BodyShape getBodyShape() {
  123.         return bodyShape;
  124.     }

  125.     /** Compute the value of the switching function.
  126.      * This function measures the difference between the current altitude
  127.      * and the threshold altitude.
  128.      * @param s the current state information: date, kinematics, attitude
  129.      * @return value of the switching function
  130.      */
  131.     public T g(final FieldSpacecraftState<T> s) {
  132.         final Frame bodyFrame              = bodyShape.getBodyFrame();
  133.         final FieldGeodeticPoint<T> point  = bodyShape.transform(s.getPosition(bodyFrame),
  134.                                                                  bodyFrame, s.getDate());
  135.         return point.getAltitude().subtract(altitude);
  136.     }

  137. }