FieldElevationDetector.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.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_MAXCHECK})
  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(FieldAdaptableInterval.of(DEFAULT_MAXCHECK),
  65.              field.getZero().newInstance(DEFAULT_THRESHOLD), DEFAULT_MAX_ITER,
  66.              new FieldStopOnDecreasing<>(),
  67.              0.0, null, null, topo);
  68.     }

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

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

  110.     /** {@inheritDoc} */
  111.     @Override
  112.     protected FieldElevationDetector<T> create(final FieldAdaptableInterval<T> newMaxCheck, final T newThreshold,
  113.                                                final int newMaxIter, final FieldEventHandler<T> newHandler) {
  114.         return new FieldElevationDetector<>(newMaxCheck, newThreshold, newMaxIter, newHandler,
  115.                                             minElevation, elevationMask, refractionModel, topo);
  116.     }

  117.     /**
  118.      * Returns the currently configured elevation mask.
  119.      * @return elevation mask
  120.      * (null if instance has been configured with {@link #withConstantElevation(double)}
  121.      * @see #withElevationMask(ElevationMask)
  122.      */
  123.     public ElevationMask getElevationMask() {
  124.         return this.elevationMask;
  125.     }

  126.     /**
  127.      * Returns the currently configured minimum valid elevation value.
  128.      * @return minimum elevation value
  129.      * ({@code Double.NaN} if instance has been configured with {@link #withElevationMask(ElevationMask)}
  130.      * @see #withConstantElevation(double)
  131.      */
  132.     public double getMinElevation() {
  133.         return this.minElevation;
  134.     }

  135.     /**
  136.      * Returns the currently configured refraction model.
  137.      * @return refraction model
  138.      * @see #withRefraction(AtmosphericRefractionModel)
  139.      */
  140.     public AtmosphericRefractionModel getRefractionModel() {
  141.         return this.refractionModel;
  142.     }

  143.     /**
  144.      * Returns the currently configured topocentric frame definitions.
  145.      * @return topocentric frame definition
  146.      */
  147.     public TopocentricFrame getTopocentricFrame() {
  148.         return this.topo;
  149.     }

  150.     /** Compute the value of the switching function.
  151.      * This function measures the difference between the current elevation
  152.      * (and azimuth if necessary) and the reference mask or minimum value.
  153.      * @param s the current state information: date, kinematics, attitude
  154.      * @return value of the switching function
  155.      */
  156.     @Override
  157.     public T g(final FieldSpacecraftState<T> s) {

  158.         final FieldStaticTransform<T> t = s.getFrame().getStaticTransformTo(topo, s.getDate());
  159.         final FieldVector3D<T> extPointTopo = t.transformPosition(s.getPosition());
  160.         final T trueElevation = extPointTopo.getDelta();

  161.         final T calculatedElevation;
  162.         if (refractionModel != null) {
  163.             calculatedElevation = trueElevation.add(refractionModel.getRefraction(trueElevation.getReal()));
  164.         } else {
  165.             calculatedElevation = trueElevation;
  166.         }

  167.         if (elevationMask != null) {
  168.             final double azimuth = FastMath.atan2(extPointTopo.getY().getReal(), extPointTopo.getX().getReal());
  169.             return calculatedElevation.subtract(elevationMask.getElevation(azimuth));
  170.         } else {
  171.             return calculatedElevation.subtract(minElevation);
  172.         }

  173.     }

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

  188.     /**
  189.      * Setup the elevation mask for detection using the passed in mask object.
  190.      * @param newElevationMask elevation mask to use for the computation
  191.      * @return a new detector with updated configuration (the instance is not changed)
  192.      * @since 6.1
  193.      * @see #getElevationMask()
  194.      */
  195.     public FieldElevationDetector<T> withElevationMask(final ElevationMask newElevationMask) {
  196.         return new FieldElevationDetector<>(getMaxCheckInterval(), getThreshold(), getMaxIterationCount(), getHandler(),
  197.                                             Double.NaN, newElevationMask, refractionModel, topo);
  198.     }

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

  215. }