ElevationDetector.java

  1. /* Copyright 2002-2024 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.ode.events.Action;
  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. import org.orekit.utils.TrackingCoordinates;


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

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

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

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

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

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

  61.     /**
  62.      * Creates an instance of Elevation detector based on passed in topocentric frame
  63.      * and overrides of default maximal checking interval and convergence threshold values.
  64.      * @param maxCheck maximum checking interval (s)
  65.      * @param threshold maximum convergence threshold (s)
  66.      * @param topo reference to a topocentric model
  67.      * @see #withConstantElevation(double)
  68.      * @see #withElevationMask(ElevationMask)
  69.      * @see #withRefraction(AtmosphericRefractionModel)
  70.      */
  71.     public ElevationDetector(final double maxCheck, final double threshold,
  72.                              final TopocentricFrame topo) {
  73.         this(AdaptableInterval.of(maxCheck), threshold, topo);
  74.     }

  75.     /**
  76.      * Creates an instance of Elevation detector based on passed in topocentric frame
  77.      * and overrides of default maximal checking interval and convergence threshold values.
  78.      * @param maxCheck maximum checking adaptable interval
  79.      * @param threshold maximum convergence threshold (s)
  80.      * @param topo reference to a topocentric model
  81.      * @see org.orekit.propagation.events.intervals.ElevationDetectionAdaptableIntervalFactory
  82.      * @see #withConstantElevation(double)
  83.      * @see #withElevationMask(ElevationMask)
  84.      * @see #withRefraction(AtmosphericRefractionModel)
  85.      * @since 12.1
  86.      */
  87.     public ElevationDetector(final AdaptableInterval maxCheck, final double threshold,
  88.                              final TopocentricFrame topo) {
  89.         this(maxCheck, threshold, DEFAULT_MAX_ITER,
  90.              new StopOnDecreasing(),
  91.              0.0, null, null, topo);
  92.     }

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

  119.     /** {@inheritDoc} */
  120.     @Override
  121.     protected ElevationDetector create(final AdaptableInterval newMaxCheck, final double newThreshold,
  122.                                        final int newMaxIter, final EventHandler newHandler) {
  123.         return new ElevationDetector(newMaxCheck, newThreshold, newMaxIter, newHandler,
  124.                                      minElevation, elevationMask, refractionModel, topo);
  125.     }

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

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

  144.     /**
  145.      * Returns the currently configured refraction model.
  146.      * @return refraction model
  147.      * @see #withRefraction(AtmosphericRefractionModel)
  148.      */
  149.     public AtmosphericRefractionModel getRefractionModel() {
  150.         return this.refractionModel;
  151.     }

  152.     /**
  153.      * Returns the currently configured topocentric frame definitions.
  154.      * @return topocentric frame definition
  155.      */
  156.     public TopocentricFrame getTopocentricFrame() {
  157.         return this.topo;
  158.     }

  159.     /** Compute the value of the switching function.
  160.      * This function measures the difference between the current elevation
  161.      * (and azimuth if necessary) and the reference mask or minimum value.
  162.      * @param s the current state information: date, kinematics, attitude
  163.      * @return value of the switching function
  164.      */
  165.     @Override
  166.     public double g(final SpacecraftState s) {

  167.         final TrackingCoordinates tc = topo.getTrackingCoordinates(s.getPosition(), s.getFrame(), s.getDate());

  168.         final double calculatedElevation;
  169.         if (refractionModel != null) {
  170.             calculatedElevation = tc.getElevation() + refractionModel.getRefraction(tc.getElevation());
  171.         } else {
  172.             calculatedElevation = tc.getElevation();
  173.         }

  174.         if (elevationMask != null) {
  175.             return calculatedElevation - elevationMask.getElevation(tc.getAzimuth());
  176.         } else {
  177.             return calculatedElevation - minElevation;
  178.         }

  179.     }

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

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

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

  221. }