FieldElevationDetector.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.Field;
  19. import org.hipparchus.CalculusFieldElement;
  20. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  21. import org.hipparchus.ode.events.Action;
  22. import org.hipparchus.util.FastMath;
  23. import org.orekit.frames.FieldStaticTransform;
  24. import org.orekit.frames.TopocentricFrame;
  25. import org.orekit.models.AtmosphericRefractionModel;
  26. import org.orekit.propagation.FieldSpacecraftState;
  27. import org.orekit.propagation.events.handlers.FieldEventHandler;
  28. import org.orekit.propagation.events.handlers.FieldStopOnDecreasing;
  29. import org.orekit.utils.ElevationMask;


  30. /**
  31.  * Finder for satellite raising/setting events that allows for the
  32.  * setting of azimuth and/or elevation bounds or a ground azimuth/elevation
  33.  * mask input. Each calculation be configured to use atmospheric refraction
  34.  * as well.
  35.  * <p>The default implementation behavior is to {@link Action#CONTINUE continue}
  36.  * propagation at raising and to {@link Action#STOP stop} propagation
  37.  * at setting. This can be changed by calling
  38.  * {@link #withHandler(FieldEventHandler)} after construction.</p>
  39.  * @author Hank Grabowski
  40.  * @param <T> type of the field elements
  41.  */
  42. public class FieldElevationDetector<T extends CalculusFieldElement<T>>
  43.         extends FieldAbstractTopocentricDetector<FieldElevationDetector<T>, T> {

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

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

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

  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_MAX_CHECK})
  55.      * and convergence threshold ({@link #DEFAULT_THRESHOLD}).</p>
  56.      * @param field type of the elements
  57.      * @param topo reference to a topocentric model
  58.      * @see #withConstantElevation(double)
  59.      * @see #withElevationMask(ElevationMask)
  60.      * @see #withRefraction(AtmosphericRefractionModel)
  61.      */
  62.     public FieldElevationDetector(final Field<T> field, final TopocentricFrame topo) {
  63.         this(new FieldEventDetectionSettings<>(field, EventDetectionSettings.getDefaultEventDetectionSettings()),
  64.              new FieldStopOnDecreasing<>(),
  65.              0.0, null, null, topo);
  66.     }

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

  81.     /** Protected constructor with full parameters.
  82.      * <p>
  83.      * This constructor is not public as users are expected to use the builder
  84.      * API with the various {@code withXxx()} methods to set up the instance
  85.      * in a readable manner without using a huge amount of parameters.
  86.      * </p>
  87.      * @param detectionSettings detection settings
  88.      * @param handler event handler to call at event occurrences
  89.      * @param minElevation minimum elevation in radians (rad)
  90.      * @param mask reference to elevation mask
  91.      * @param refractionModel reference to refraction model
  92.      * @param topo reference to a topocentric model
  93.      * @since 12.2
  94.      */
  95.     protected FieldElevationDetector(final FieldEventDetectionSettings<T> detectionSettings, final FieldEventHandler<T> handler,
  96.                                      final double minElevation, final ElevationMask mask,
  97.                                      final AtmosphericRefractionModel refractionModel,
  98.                                      final TopocentricFrame topo) {
  99.         super(detectionSettings, handler, topo);
  100.         this.minElevation    = minElevation;
  101.         this.elevationMask   = mask;
  102.         this.refractionModel = refractionModel;
  103.     }

  104.     /** {@inheritDoc} */
  105.     @Override
  106.     protected FieldElevationDetector<T> create(final FieldEventDetectionSettings<T> detectionSettings,
  107.                                                final FieldEventHandler<T> newHandler) {
  108.         return new FieldElevationDetector<>(detectionSettings, newHandler,
  109.                                             minElevation, elevationMask, refractionModel, getTopocentricFrame());
  110.     }

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

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

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

  137.     /** Compute the value of the switching function.
  138.      * This function measures the difference between the current elevation
  139.      * (and azimuth if necessary) and the reference mask or minimum value.
  140.      * @param s the current state information: date, kinematics, attitude
  141.      * @return value of the switching function
  142.      */
  143.     @Override
  144.     public T g(final FieldSpacecraftState<T> s) {

  145.         final FieldStaticTransform<T> t = s.getFrame().getStaticTransformTo(getTopocentricFrame(), s.getDate());
  146.         final FieldVector3D<T> extPointTopo = t.transformPosition(s.getPosition());
  147.         final T trueElevation = extPointTopo.getDelta();

  148.         final T calculatedElevation;
  149.         if (refractionModel != null) {
  150.             calculatedElevation = trueElevation.add(refractionModel.getRefraction(trueElevation.getReal()));
  151.         } else {
  152.             calculatedElevation = trueElevation;
  153.         }

  154.         if (elevationMask != null) {
  155.             final double azimuth = FastMath.atan2(extPointTopo.getY().getReal(), extPointTopo.getX().getReal());
  156.             return calculatedElevation.subtract(elevationMask.getElevation(azimuth));
  157.         } else {
  158.             return calculatedElevation.subtract(minElevation);
  159.         }

  160.     }

  161.     /**
  162.      * Setup the minimum elevation for detection.
  163.      * <p>
  164.      * This will override an elevation mask if it has been configured as such previously.
  165.      * </p>
  166.      * @param newMinElevation minimum elevation for visibility in radians (rad)
  167.      * @return a new detector with updated configuration (the instance is not changed)
  168.      * @see #getMinElevation()
  169.      * @since 6.1
  170.      */
  171.     public FieldElevationDetector<T> withConstantElevation(final double newMinElevation) {
  172.         return new FieldElevationDetector<>(getDetectionSettings(), getHandler(),
  173.                                             newMinElevation, null, refractionModel, getTopocentricFrame());
  174.     }

  175.     /**
  176.      * Setup the elevation mask for detection using the passed in mask object.
  177.      * @param newElevationMask elevation mask to use for the computation
  178.      * @return a new detector with updated configuration (the instance is not changed)
  179.      * @since 6.1
  180.      * @see #getElevationMask()
  181.      */
  182.     public FieldElevationDetector<T> withElevationMask(final ElevationMask newElevationMask) {
  183.         return new FieldElevationDetector<>(getDetectionSettings(), getHandler(),
  184.                                             Double.NaN, newElevationMask, refractionModel, getTopocentricFrame());
  185.     }

  186.     /**
  187.      * Setup the elevation detector to use an atmospheric refraction model in its
  188.      * calculations.
  189.      * <p>
  190.      * To disable the refraction when copying an existing elevation
  191.      * detector, call this method with a null argument.
  192.      * </p>
  193.      * @param newRefractionModel refraction model to use for the computation
  194.      * @return a new detector with updated configuration (the instance is not changed)
  195.      * @since 6.1
  196.      * @see #getRefractionModel()
  197.      */
  198.     public FieldElevationDetector<T> withRefraction(final AtmosphericRefractionModel newRefractionModel) {
  199.         return new FieldElevationDetector<>(getDetectionSettings(), getHandler(),
  200.                                             minElevation, elevationMask, newRefractionModel, getTopocentricFrame());
  201.     }

  202. }