ElevationDetector.java

  1. /* Copyright 2002-2013 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 AbstractReconfigurableDetector<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 the minimum elevation angle.
  67.      * <p>
  68.      * uses default values for maximal checking interval ({@link #DEFAULT_MAXCHECK})
  69.      * and convergence threshold ({@link #DEFAULT_THRESHOLD}).</p>
  70.      * @param minElevation minimum elevation angle
  71.      * @param topo reference to a topocentric model
  72.      * @deprecated as of 6.1 replace with {@link #ElevationDetector(TopocentricFrame)} followed
  73.      * by a call to {@link #withConstantElevation(double)}
  74.      */
  75.     @Deprecated
  76.     public ElevationDetector(final double minElevation, final TopocentricFrame topo) {
  77.         this(DEFAULT_MAXCHECK, DEFAULT_THRESHOLD, DEFAULT_MAX_ITER,
  78.              new StopOnDecreasing<ElevationDetector>(),
  79.              minElevation, null, null, topo);
  80.     }

  81.     /**
  82.      * Creates an instance of Elevation detector based on passed in topocentric frame
  83.      * and overrides of default maximal checking interval and convergence threshold values.
  84.      * @param maxCheck maximum checking interval (s)
  85.      * @param threshold maximum divergence threshold (s)
  86.      * @param topo reference to a topocentric model
  87.      * @see #withConstantElevation(double)
  88.      * @see #withElevationMask(ElevationMask)
  89.      * @see #withRefraction(AtmosphericRefractionModel)
  90.      */
  91.     public ElevationDetector(final double maxCheck, final double threshold,
  92.                              final TopocentricFrame topo) {
  93.         this(maxCheck, threshold, DEFAULT_MAX_ITER,
  94.              new StopOnDecreasing<ElevationDetector>(),
  95.              0.0, null, null, topo);
  96.     }

  97.     /** Private constructor with full parameters.
  98.      * <p>
  99.      * This constructor is private as users are expected to use the builder
  100.      * API with the various {@code withXxx()} methods to set up the instance
  101.      * in a readable manner without using a huge amount of parameters.
  102.      * </p>
  103.      * @param maxCheck maximum checking interval (s)
  104.      * @param threshold convergence threshold (s)
  105.      * @param maxIter maximum number of iterations in the event time search
  106.      * @param handler event handler to call at event occurrences
  107.      * @param minElevation minimum elevation in radians (rad)
  108.      * @param mask reference to elevation mask
  109.      * @param refractionModel reference to refraction model
  110.      * @param topo reference to a topocentric model
  111.      */
  112.     private ElevationDetector(final double maxCheck, final double threshold,
  113.                               final int maxIter, final EventHandler<ElevationDetector> handler,
  114.                               final double minElevation, final ElevationMask mask,
  115.                               final AtmosphericRefractionModel refractionModel,
  116.                               final TopocentricFrame topo) {
  117.         super(maxCheck, threshold, maxIter, handler);
  118.         this.minElevation    = minElevation;
  119.         this.elevationMask   = mask;
  120.         this.refractionModel = refractionModel;
  121.         this.topo            = topo;
  122.     }

  123.     /** {@inheritDoc} */
  124.     @Override
  125.     protected ElevationDetector create(final double newMaxCheck, final double newThreshold,
  126.                                        final int newMaxIter, final EventHandler<ElevationDetector> newHandler) {
  127.         return new ElevationDetector(newMaxCheck, newThreshold, newMaxIter, newHandler,
  128.                                      minElevation, elevationMask, refractionModel, topo);
  129.     }

  130.     /**
  131.      * Returns the currently configured elevation mask.
  132.      * @return elevation mask
  133.      * (null if instance has been configured with {@link #withConstantElevation(double)}
  134.      * @see #withElevationMask(ElevationMask)
  135.      */
  136.     public ElevationMask getElevationMask() {
  137.         return this.elevationMask;
  138.     }

  139.     /**
  140.      * Returns the currently configured minimum valid elevation value.
  141.      * @return minimum elevation value
  142.      * ({@code Double.NaN} if instance has been configured with {@link #withElevationMask(ElevationMask)}
  143.      * @see #withConstantElevation(double)
  144.      */
  145.     public double getMinElevation() {
  146.         return this.minElevation;
  147.     }

  148.     /**
  149.      * Returns the currently configured refraction model.
  150.      * @return refraction model
  151.      * @see #withRefraction(AtmosphericRefractionModel)
  152.      */
  153.     public AtmosphericRefractionModel getRefractionModel() {
  154.         return this.refractionModel;
  155.     }

  156.     /**
  157.      * Returns the currently configured topocentric frame definitions.
  158.      * @return topocentric frame definition
  159.      */
  160.     public TopocentricFrame getTopocentricFrame() {
  161.         return this.topo;
  162.     }

  163.     /** Compute the value of the switching function.
  164.      * This function measures the difference between the current elevation
  165.      * (and azimuth if necessary) and the reference mask or minimum value.
  166.      * @param s the current state information: date, kinematics, attitude
  167.      * @return value of the switching function
  168.      * @exception OrekitException if some specific error occurs
  169.      */
  170.     @Override
  171.     public double g(final SpacecraftState s) throws OrekitException {

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

  174.         final double calculatedElevation;
  175.         if (refractionModel != null) {
  176.             calculatedElevation = trueElevation + refractionModel.getRefraction(trueElevation);
  177.         } else {
  178.             calculatedElevation = trueElevation;
  179.         }

  180.         if (elevationMask != null) {
  181.             final double azimuth = topo.getAzimuth(s.getPVCoordinates().getPosition(), s.getFrame(), s.getDate());
  182.             return calculatedElevation - elevationMask.getElevation(azimuth);
  183.         } else {
  184.             return calculatedElevation - minElevation;
  185.         }

  186.     }

  187.     /**
  188.      * Setup the minimum elevation for detection.
  189.      * <p>
  190.      * This will override an elevation mask if it has been configured as such previously.
  191.      * </p>
  192.      * @param newMinElevation minimum elevation for visibility in radians (rad)
  193.      * @return a new detector with updated configuration (the instance is not changed)
  194.      * @see #getMinElevation()
  195.      * @since 6.1
  196.      */
  197.     public ElevationDetector withConstantElevation(final double newMinElevation) {
  198.         return new ElevationDetector(getMaxCheckInterval(), getThreshold(), getMaxIterationCount(), getHandler(),
  199.                                      newMinElevation, null, refractionModel, topo);
  200.     }

  201.     /**
  202.      * Setup the elevation mask for detection using the passed in mask object.
  203.      * @param newElevationMask elevation mask to use for the computation
  204.      * @return a new detector with updated configuration (the instance is not changed)
  205.      * @since 6.1
  206.      * @see #getElevationMask()
  207.      */
  208.     public ElevationDetector withElevationMask(final ElevationMask newElevationMask) {
  209.         return new ElevationDetector(getMaxCheckInterval(), getThreshold(), getMaxIterationCount(), getHandler(),
  210.                                      Double.NaN, newElevationMask, refractionModel, topo);
  211.     }

  212.     /**
  213.      * Setup the elevation detector to use an atmospheric refraction model in its
  214.      * calculations.
  215.      * <p>
  216.      * To disable the refraction when copying an existing elevation
  217.      * detector, call this method with a null argument.
  218.      * </p>
  219.      * @param newRefractionModel refraction model to use for the computation
  220.      * @return a new detector with updated configuration (the instance is not changed)
  221.      * @since 6.1
  222.      * @see #getRefractionModel()
  223.      */
  224.     public ElevationDetector withRefraction(final AtmosphericRefractionModel newRefractionModel) {
  225.         return new ElevationDetector(getMaxCheckInterval(), getThreshold(), getMaxIterationCount(), getHandler(),
  226.                                      minElevation, elevationMask, newRefractionModel, topo);
  227.     }

  228. }