ElevationDetector.java

  1. /* Copyright 2002-2025 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.propagation.events.intervals.AdaptableInterval;
  25. import org.orekit.utils.ElevationMask;
  26. import org.orekit.utils.TrackingCoordinates;


  27. /**
  28.  * Finder for satellite raising/setting events that allows for the
  29.  * setting of azimuth and/or elevation bounds or a ground azimuth/elevation
  30.  * mask input. Each calculation be configured to use atmospheric refraction
  31.  * as well.
  32.  * <p>The default implementation behavior is to {@link Action#CONTINUE continue}
  33.  * propagation at raising and to {@link 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.     /** Elevation mask used for calculations, if defined. */
  41.     private final ElevationMask elevationMask;

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

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

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

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

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

  76.     /**
  77.      * Creates an instance of Elevation detector based on passed in topocentric frame
  78.      * and overrides of default maximal checking interval and convergence threshold values.
  79.      * @param maxCheck maximum checking adaptable interval
  80.      * @param threshold maximum convergence threshold (s)
  81.      * @param topo reference to a topocentric model
  82.      * @see org.orekit.propagation.events.intervals.ElevationDetectionAdaptableIntervalFactory
  83.      * @see #withConstantElevation(double)
  84.      * @see #withElevationMask(ElevationMask)
  85.      * @see #withRefraction(AtmosphericRefractionModel)
  86.      * @since 12.1
  87.      */
  88.     public ElevationDetector(final AdaptableInterval maxCheck, final double threshold,
  89.                              final TopocentricFrame topo) {
  90.         this(new EventDetectionSettings(maxCheck, threshold, DEFAULT_MAX_ITER), 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 detectionSettings event detection settings
  100.      * @param handler event handler to call at event occurrences
  101.      * @param minElevation minimum elevation in radians (rad)
  102.      * @param mask reference to elevation mask
  103.      * @param refractionModel reference to refraction model
  104.      * @param topo reference to a topocentric model
  105.      * @since 13.0
  106.      */
  107.     protected ElevationDetector(final EventDetectionSettings detectionSettings, final EventHandler handler,
  108.                                 final double minElevation, final ElevationMask mask,
  109.                                 final AtmosphericRefractionModel refractionModel,
  110.                                 final TopocentricFrame topo) {
  111.         super(detectionSettings, handler);
  112.         this.minElevation    = minElevation;
  113.         this.elevationMask   = mask;
  114.         this.refractionModel = refractionModel;
  115.         this.topo            = topo;
  116.     }

  117.     /** {@inheritDoc} */
  118.     @Override
  119.     protected ElevationDetector create(final EventDetectionSettings detectionSettings, final EventHandler newHandler) {
  120.         return new ElevationDetector(detectionSettings, newHandler,
  121.                                      minElevation, elevationMask, refractionModel, topo);
  122.     }

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

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

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

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

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

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

  165.         final double calculatedElevation;
  166.         if (refractionModel != null) {
  167.             calculatedElevation = tc.getElevation() + refractionModel.getRefraction(tc.getElevation());
  168.         } else {
  169.             calculatedElevation = tc.getElevation();
  170.         }

  171.         if (elevationMask != null) {
  172.             return calculatedElevation - elevationMask.getElevation(tc.getAzimuth());
  173.         } else {
  174.             return calculatedElevation - minElevation;
  175.         }

  176.     }

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

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

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

  218. }