FieldAltitudeDetector.java

  1. /* Copyright 2002-2022 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. import org.orekit.utils.FieldPVCoordinates;

  27. /** Finder for satellite altitude crossing events.
  28.  * <p>This class finds altitude events (i.e. satellite crossing
  29.  * a predefined altitude level above ground).</p>
  30.  * <p>The default implementation behavior is to {@link Action#CONTINUE
  31.  * continue} propagation when ascending and to {@link Action#STOP stop}
  32.  * propagation when descending. This can be changed by calling
  33.  * {@link #withHandler(FieldEventHandler)} after construction.</p>
  34.  * @see org.orekit.propagation.FieldPropagator#addEventDetector(FieldEventDetector)
  35.  * @author Luc Maisonobe
  36.  * @since 9.0
  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_MAXCHECK}) 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().add(DEFAULT_MAXCHECK),
  52.              altitude.getField().getZero().add(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().add(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(maxCheck, threshold, DEFAULT_MAX_ITER, new FieldStopOnDecreasing<FieldAltitudeDetector<T>, T>(),
  87.              altitude, bodyShape);
  88.     }

  89.     /** Private constructor with full parameters.
  90.      * <p>
  91.      * This constructor is private 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 maxCheck maximum checking interval (s)
  96.      * @param threshold convergence threshold (s)
  97.      * @param maxIter maximum number of iterations in the event time search
  98.      * @param handler event handler to call at event occurrences
  99.      * @param altitude threshold altitude value (m)
  100.      * @param bodyShape body shape with respect to which altitude should be evaluated
  101.      * @since 6.1
  102.      */
  103.     private FieldAltitudeDetector(final T maxCheck, final T threshold,
  104.                                   final int maxIter, final FieldEventHandler<? super FieldAltitudeDetector<T>, T> handler,
  105.                                   final T altitude,
  106.                                   final BodyShape bodyShape) {
  107.         super(maxCheck, threshold, maxIter, handler);
  108.         this.altitude  = altitude;
  109.         this.bodyShape = bodyShape;
  110.     }

  111.     /** {@inheritDoc} */
  112.     @Override
  113.     protected FieldAltitudeDetector<T> create(final T newMaxCheck, final T newThreshold,
  114.                                               final int newMaxIter,
  115.                                               final FieldEventHandler<? super FieldAltitudeDetector<T>, T> newHandler) {
  116.         return new FieldAltitudeDetector<>(newMaxCheck, newThreshold, newMaxIter, newHandler,
  117.                                            altitude, bodyShape);
  118.     }

  119.     /** Get the threshold altitude value.
  120.      * @return the threshold altitude value (m)
  121.      */
  122.     public T getAltitude() {
  123.         return altitude;
  124.     }

  125.     /** Get the body shape.
  126.      * @return the body shape
  127.      */
  128.     public BodyShape getBodyShape() {
  129.         return bodyShape;
  130.     }

  131.     /** Compute the value of the switching function.
  132.      * This function measures the difference between the current altitude
  133.      * and the threshold altitude.
  134.      * @param s the current state information: date, kinematics, attitude
  135.      * @return value of the switching function
  136.      */
  137.     public T g(final FieldSpacecraftState<T> s) {
  138.         final Frame bodyFrame              = bodyShape.getBodyFrame();
  139.         final FieldPVCoordinates<T> pvBody = s.getPVCoordinates(bodyFrame);
  140.         final FieldGeodeticPoint<T> point  = bodyShape.transform(pvBody.getPosition(),
  141.                                                                  bodyFrame, s.getDate());
  142.         return point.getAltitude().subtract(altitude);
  143.     }

  144. }