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>> extends FieldAbstractDetector<FieldElevationDetector<T>, T> {

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

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

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

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

  51.     /**
  52.      * Creates an instance of Elevation detector based on passed in topocentric frame
  53.      * and the minimum elevation angle.
  54.      * <p>
  55.      * uses default values for maximal checking interval ({@link #DEFAULT_MAX_CHECK})
  56.      * and convergence threshold ({@link #DEFAULT_THRESHOLD}).</p>
  57.      * @param field type of the elements
  58.      * @param topo reference to a topocentric model
  59.      * @see #withConstantElevation(double)
  60.      * @see #withElevationMask(ElevationMask)
  61.      * @see #withRefraction(AtmosphericRefractionModel)
  62.      */
  63.     public FieldElevationDetector(final Field<T> field, final TopocentricFrame topo) {
  64.         this(new FieldEventDetectionSettings<>(field, EventDetectionSettings.getDefaultEventDetectionSettings()),
  65.              new FieldStopOnDecreasing<>(),
  66.              0.0, null, null, topo);
  67.     }

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

  82.     /** Protected constructor with full parameters.
  83.      * <p>
  84.      * This constructor is not public as users are expected to use the builder
  85.      * API with the various {@code withXxx()} methods to set up the instance
  86.      * in a readable manner without using a huge amount of parameters.
  87.      * </p>
  88.      * @param detectionSettings detection settings
  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.      * @since 12.2
  95.      */
  96.     protected FieldElevationDetector(final FieldEventDetectionSettings<T> detectionSettings, final FieldEventHandler<T> handler,
  97.                                      final double minElevation, final ElevationMask mask,
  98.                                      final AtmosphericRefractionModel refractionModel,
  99.                                      final TopocentricFrame topo) {
  100.         super(detectionSettings, handler);
  101.         this.minElevation    = minElevation;
  102.         this.elevationMask   = mask;
  103.         this.refractionModel = refractionModel;
  104.         this.topo            = topo;
  105.     }

  106.     /** {@inheritDoc} */
  107.     @Override
  108.     protected FieldElevationDetector<T> create(final FieldEventDetectionSettings<T> detectionSettings,
  109.                                                final FieldEventHandler<T> newHandler) {
  110.         return new FieldElevationDetector<>(detectionSettings, 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.      */
  152.     @Override
  153.     public T g(final FieldSpacecraftState<T> s) {

  154.         final FieldStaticTransform<T> t = s.getFrame().getStaticTransformTo(topo, s.getDate());
  155.         final FieldVector3D<T> extPointTopo = t.transformPosition(s.getPosition());
  156.         final T trueElevation = extPointTopo.getDelta();

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

  163.         if (elevationMask != null) {
  164.             final double azimuth = FastMath.atan2(extPointTopo.getY().getReal(), extPointTopo.getX().getReal());
  165.             return calculatedElevation.subtract(elevationMask.getElevation(azimuth));
  166.         } else {
  167.             return calculatedElevation.subtract(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 FieldElevationDetector<T> withConstantElevation(final double newMinElevation) {
  181.         return new FieldElevationDetector<>(getDetectionSettings(), 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 FieldElevationDetector<T> withElevationMask(final ElevationMask newElevationMask) {
  192.         return new FieldElevationDetector<>(getDetectionSettings(), 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 FieldElevationDetector<T> withRefraction(final AtmosphericRefractionModel newRefractionModel) {
  208.         return new FieldElevationDetector<>(getDetectionSettings(), getHandler(),
  209.                                             minElevation, elevationMask, newRefractionModel, topo);
  210.     }

  211. }