FieldAltitudeDetector.java

  1. /* Copyright 2002-2018 CS Systèmes d'Information
  2.  * Licensed to CS Systèmes d'Information (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.RealFieldElement;
  19. import org.orekit.bodies.BodyShape;
  20. import org.orekit.bodies.FieldGeodeticPoint;
  21. import org.orekit.errors.OrekitException;
  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
  31.  * org.orekit.propagation.events.handlers.EventHandler.Action#CONTINUE
  32.  * continue} propagation when ascending and to {@link
  33.  * org.orekit.propagation.events.handlers.EventHandler.Action#STOP stop}
  34.  * propagation when descending. This can be changed by calling
  35.  * {@link #withHandler(FieldEventHandler)} after construction.</p>
  36.  * @see org.orekit.propagation.FieldPropagator#addEventDetector(FieldEventDetector)
  37.  * @author Luc Maisonobe
  38.  * @since 9.0
  39.  */
  40. public class FieldAltitudeDetector<T extends RealFieldElement<T>> extends FieldAbstractDetector<FieldAltitudeDetector<T>, T> {

  41.     /** Threshold altitude value (m). */
  42.     private final T altitude;

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

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

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

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

  91.     /** Private constructor with full parameters.
  92.      * <p>
  93.      * This constructor is private as users are expected to use the builder
  94.      * API with the various {@code withXxx()} methods to set up the instance
  95.      * in a readable manner without using a huge amount of parameters.
  96.      * </p>
  97.      * @param maxCheck maximum checking interval (s)
  98.      * @param threshold convergence threshold (s)
  99.      * @param maxIter maximum number of iterations in the event time search
  100.      * @param handler event handler to call at event occurrences
  101.      * @param altitude threshold altitude value (m)
  102.      * @param bodyShape body shape with respect to which altitude should be evaluated
  103.      * @since 6.1
  104.      */
  105.     private FieldAltitudeDetector(final T maxCheck, final T threshold,
  106.                                   final int maxIter, final FieldEventHandler<? super FieldAltitudeDetector<T>, T> handler,
  107.                                   final T altitude,
  108.                                   final BodyShape bodyShape) {
  109.         super(maxCheck, threshold, maxIter, handler);
  110.         this.altitude  = altitude;
  111.         this.bodyShape = bodyShape;
  112.     }

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

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

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

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

  147. }