FieldElevationDetector.java

  1. /* Copyright 2002-2018 CS Systèmes d'Information
  2.  * Licensed to CS Systèmes d'Information (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.util.FastMath;
  22. import org.orekit.errors.OrekitException;
  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
  36.  * org.orekit.propagation.events.handlers.FieldEventHandler.Action#CONTINUE continue}
  37.  * propagation at raising and to {@link
  38.  * org.orekit.propagation.events.handlers.FieldEventHandler.Action#STOP stop} propagation
  39.  * at setting. This can be changed by calling
  40.  * {@link #withHandler(FieldEventHandler)} after construction.</p>
  41.  * @author Hank Grabowski
  42.  */
  43. public class FieldElevationDetector<T extends RealFieldElement<T>> extends FieldAbstractDetector<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.     /** Topocentric frame in which elevation should be evaluated. */
  51.     private final TopocentricFrame topo;

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

  84.     /** Private constructor with full parameters.
  85.      * <p>
  86.      * This constructor is private 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 (s)
  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.     private FieldElevationDetector(final T maxCheck, final T threshold,
  100.                                    final int maxIter, final FieldEventHandler<? super FieldElevationDetector<T>, 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 T newMaxCheck, final T newThreshold,
  113.                                                final int newMaxIter, final FieldEventHandler<? super FieldElevationDetector<T>, 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.      * @exception OrekitException if some specific error occurs
  156.      */
  157.     @Override
  158.     public T g(final FieldSpacecraftState<T> s) throws OrekitException {

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

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

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

  174.     }

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

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

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

  216. }