ElevationDetector.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.orekit.errors.OrekitException;
  19. import org.orekit.frames.TopocentricFrame;
  20. import org.orekit.models.AtmosphericRefractionModel;
  21. import org.orekit.propagation.SpacecraftState;
  22. import org.orekit.propagation.events.handlers.EventHandler;
  23. import org.orekit.propagation.events.handlers.StopOnDecreasing;
  24. import org.orekit.utils.ElevationMask;


  25. /**
  26.  * Finder for satellite raising/setting events that allows for the
  27.  * setting of azimuth and/or elevation bounds or a ground azimuth/elevation
  28.  * mask input. Each calculation be configured to use atmospheric refraction
  29.  * as well.
  30.  * <p>The default implementation behavior is to {@link
  31.  * org.orekit.propagation.events.handlers.EventHandler.Action#CONTINUE continue}
  32.  * propagation at raising and to {@link
  33.  * org.orekit.propagation.events.handlers.EventHandler.Action#STOP stop} propagation
  34.  * at setting. This can be changed by calling
  35.  * {@link #withHandler(EventHandler)} after construction.</p>
  36.  * @author Hank Grabowski
  37.  * @since 6.1
  38.  */
  39. public class ElevationDetector extends AbstractDetector<ElevationDetector> {

  40.     /** Serializable UID. */
  41.     private static final long serialVersionUID = 20131118L;

  42.     /** Elevation mask used for calculations, if defined. */
  43.     private final ElevationMask elevationMask;

  44.     /** Minimum elevation value used if mask is not defined. */
  45.     private final double minElevation;

  46.     /** Atmospheric Model used for calculations, if defined. */
  47.     private final AtmosphericRefractionModel refractionModel;

  48.     /** Topocentric frame in which elevation should be evaluated. */
  49.     private final TopocentricFrame topo;

  50.     /**
  51.      * Creates an instance of Elevation detector based on passed in topocentric frame
  52.      * and the minimum elevation angle.
  53.      * <p>
  54.      * uses default values for maximal checking interval ({@link #DEFAULT_MAXCHECK})
  55.      * and convergence threshold ({@link #DEFAULT_THRESHOLD}).</p>
  56.      * @param topo reference to a topocentric model
  57.      * @see #withConstantElevation(double)
  58.      * @see #withElevationMask(ElevationMask)
  59.      * @see #withRefraction(AtmosphericRefractionModel)
  60.      */
  61.     public ElevationDetector(final TopocentricFrame topo) {
  62.         this(DEFAULT_MAXCHECK, DEFAULT_THRESHOLD, topo);
  63.     }

  64.     /**
  65.      * Creates an instance of Elevation detector based on passed in topocentric frame
  66.      * and overrides of default maximal checking interval and convergence threshold values.
  67.      * @param maxCheck maximum checking interval (s)
  68.      * @param threshold maximum divergence threshold (s)
  69.      * @param topo reference to a topocentric model
  70.      * @see #withConstantElevation(double)
  71.      * @see #withElevationMask(ElevationMask)
  72.      * @see #withRefraction(AtmosphericRefractionModel)
  73.      */
  74.     public ElevationDetector(final double maxCheck, final double threshold,
  75.                              final TopocentricFrame topo) {
  76.         this(maxCheck, threshold, DEFAULT_MAX_ITER,
  77.              new StopOnDecreasing<ElevationDetector>(),
  78.              0.0, null, null, topo);
  79.     }

  80.     /** Private constructor with full parameters.
  81.      * <p>
  82.      * This constructor is private as users are expected to use the builder
  83.      * API with the various {@code withXxx()} methods to set up the instance
  84.      * in a readable manner without using a huge amount of parameters.
  85.      * </p>
  86.      * @param maxCheck maximum checking interval (s)
  87.      * @param threshold convergence threshold (s)
  88.      * @param maxIter maximum number of iterations in the event time search
  89.      * @param handler event handler to call at event occurrences
  90.      * @param minElevation minimum elevation in radians (rad)
  91.      * @param mask reference to elevation mask
  92.      * @param refractionModel reference to refraction model
  93.      * @param topo reference to a topocentric model
  94.      */
  95.     private ElevationDetector(final double maxCheck, final double threshold,
  96.                               final int maxIter, final EventHandler<? super ElevationDetector> handler,
  97.                               final double minElevation, final ElevationMask mask,
  98.                               final AtmosphericRefractionModel refractionModel,
  99.                               final TopocentricFrame topo) {
  100.         super(maxCheck, threshold, maxIter, handler);
  101.         this.minElevation    = minElevation;
  102.         this.elevationMask   = mask;
  103.         this.refractionModel = refractionModel;
  104.         this.topo            = topo;
  105.     }

  106.     /** {@inheritDoc} */
  107.     @Override
  108.     protected ElevationDetector create(final double newMaxCheck, final double newThreshold,
  109.                                        final int newMaxIter, final EventHandler<? super ElevationDetector> newHandler) {
  110.         return new ElevationDetector(newMaxCheck, newThreshold, newMaxIter, newHandler,
  111.                                      minElevation, elevationMask, refractionModel, topo);
  112.     }

  113.     /**
  114.      * Returns the currently configured elevation mask.
  115.      * @return elevation mask
  116.      * (null if instance has been configured with {@link #withConstantElevation(double)}
  117.      * @see #withElevationMask(ElevationMask)
  118.      */
  119.     public ElevationMask getElevationMask() {
  120.         return this.elevationMask;
  121.     }

  122.     /**
  123.      * Returns the currently configured minimum valid elevation value.
  124.      * @return minimum elevation value
  125.      * ({@code Double.NaN} if instance has been configured with {@link #withElevationMask(ElevationMask)}
  126.      * @see #withConstantElevation(double)
  127.      */
  128.     public double getMinElevation() {
  129.         return this.minElevation;
  130.     }

  131.     /**
  132.      * Returns the currently configured refraction model.
  133.      * @return refraction model
  134.      * @see #withRefraction(AtmosphericRefractionModel)
  135.      */
  136.     public AtmosphericRefractionModel getRefractionModel() {
  137.         return this.refractionModel;
  138.     }

  139.     /**
  140.      * Returns the currently configured topocentric frame definitions.
  141.      * @return topocentric frame definition
  142.      */
  143.     public TopocentricFrame getTopocentricFrame() {
  144.         return this.topo;
  145.     }

  146.     /** Compute the value of the switching function.
  147.      * This function measures the difference between the current elevation
  148.      * (and azimuth if necessary) and the reference mask or minimum value.
  149.      * @param s the current state information: date, kinematics, attitude
  150.      * @return value of the switching function
  151.      * @exception OrekitException if some specific error occurs
  152.      */
  153.     @Override
  154.     public double g(final SpacecraftState s) throws OrekitException {

  155.         final double trueElevation = topo.getElevation(s.getPVCoordinates().getPosition(),
  156.                                                        s.getFrame(), s.getDate());

  157.         final double calculatedElevation;
  158.         if (refractionModel != null) {
  159.             calculatedElevation = trueElevation + refractionModel.getRefraction(trueElevation);
  160.         } else {
  161.             calculatedElevation = trueElevation;
  162.         }

  163.         if (elevationMask != null) {
  164.             final double azimuth = topo.getAzimuth(s.getPVCoordinates().getPosition(), s.getFrame(), s.getDate());
  165.             return calculatedElevation - elevationMask.getElevation(azimuth);
  166.         } else {
  167.             return calculatedElevation - minElevation;
  168.         }

  169.     }

  170.     /**
  171.      * Setup the minimum elevation for detection.
  172.      * <p>
  173.      * This will override an elevation mask if it has been configured as such previously.
  174.      * </p>
  175.      * @param newMinElevation minimum elevation for visibility in radians (rad)
  176.      * @return a new detector with updated configuration (the instance is not changed)
  177.      * @see #getMinElevation()
  178.      * @since 6.1
  179.      */
  180.     public ElevationDetector withConstantElevation(final double newMinElevation) {
  181.         return new ElevationDetector(getMaxCheckInterval(), getThreshold(), getMaxIterationCount(), getHandler(),
  182.                                      newMinElevation, null, refractionModel, topo);
  183.     }

  184.     /**
  185.      * Setup the elevation mask for detection using the passed in mask object.
  186.      * @param newElevationMask elevation mask to use for the computation
  187.      * @return a new detector with updated configuration (the instance is not changed)
  188.      * @since 6.1
  189.      * @see #getElevationMask()
  190.      */
  191.     public ElevationDetector withElevationMask(final ElevationMask newElevationMask) {
  192.         return new ElevationDetector(getMaxCheckInterval(), getThreshold(), getMaxIterationCount(), getHandler(),
  193.                                      Double.NaN, newElevationMask, refractionModel, topo);
  194.     }

  195.     /**
  196.      * Setup the elevation detector to use an atmospheric refraction model in its
  197.      * calculations.
  198.      * <p>
  199.      * To disable the refraction when copying an existing elevation
  200.      * detector, call this method with a null argument.
  201.      * </p>
  202.      * @param newRefractionModel refraction model to use for the computation
  203.      * @return a new detector with updated configuration (the instance is not changed)
  204.      * @since 6.1
  205.      * @see #getRefractionModel()
  206.      */
  207.     public ElevationDetector withRefraction(final AtmosphericRefractionModel newRefractionModel) {
  208.         return new ElevationDetector(getMaxCheckInterval(), getThreshold(), getMaxIterationCount(), getHandler(),
  209.                                      minElevation, elevationMask, newRefractionModel, topo);
  210.     }

  211. }