FieldElevationDetector.java

  1. /* Copyright 2002-2020 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.RealFieldElement;
  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.TopocentricFrame;
  24. import org.orekit.frames.Transform;
  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.  */
  41. public class FieldElevationDetector<T extends RealFieldElement<T>> extends FieldAbstractDetector<FieldElevationDetector<T>, T> {

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

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

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

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

  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_MAXCHECK})
  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(field.getZero().add(DEFAULT_MAXCHECK),
  64.              field.getZero().add(DEFAULT_THRESHOLD),
  65.              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(maxCheck, threshold, DEFAULT_MAX_ITER,
  79.              new FieldStopOnDecreasing<FieldElevationDetector<T>, T>(),
  80.              0.0, null, null, topo);
  81.     }

  82.     /** Private constructor with full parameters.
  83.      * <p>
  84.      * This constructor is private 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 maxCheck maximum checking interval (s)
  89.      * @param threshold convergence threshold (s)
  90.      * @param maxIter maximum number of iterations in the event time search
  91.      * @param handler event handler to call at event occurrences
  92.      * @param minElevation minimum elevation in radians (rad)
  93.      * @param mask reference to elevation mask
  94.      * @param refractionModel reference to refraction model
  95.      * @param topo reference to a topocentric model
  96.      */
  97.     private FieldElevationDetector(final T maxCheck, final T threshold,
  98.                                    final int maxIter, final FieldEventHandler<? super FieldElevationDetector<T>, T> handler,
  99.                                    final double minElevation, final ElevationMask mask,
  100.                                    final AtmosphericRefractionModel refractionModel,
  101.                                    final TopocentricFrame topo) {
  102.         super(maxCheck, threshold, maxIter, handler);
  103.         this.minElevation    = minElevation;
  104.         this.elevationMask   = mask;
  105.         this.refractionModel = refractionModel;
  106.         this.topo            = topo;
  107.     }

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

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

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

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

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

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

  156.         final Transform t = s.getFrame().getTransformTo(topo, s.getDate().toAbsoluteDate());
  157.         final FieldVector3D<T> extPointTopo = t.transformPosition(s.getPVCoordinates().getPosition());
  158.         final T trueElevation = extPointTopo.getDelta();

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

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

  171.     }

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

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

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

  213. }