FieldEclipseDetector.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.Vector3D;
  21. import org.hipparchus.util.FastMath;
  22. import org.orekit.errors.OrekitException;
  23. import org.orekit.propagation.FieldSpacecraftState;
  24. import org.orekit.propagation.events.handlers.FieldEventHandler;
  25. import org.orekit.propagation.events.handlers.FieldStopOnIncreasing;
  26. import org.orekit.utils.PVCoordinatesProvider;

  27. /** Finder for satellite eclipse related events.
  28.  * <p>This class finds eclipse events, i.e. satellite within umbra (total
  29.  * eclipse) or penumbra (partial eclipse).</p>
  30.  * <p>The default implementation behavior is to {@link
  31.  * org.orekit.propagation.events.handlers.FieldEventHandler.Action#CONTINUE continue}
  32.  * propagation when entering the eclipse and to {@link
  33.  * org.orekit.propagation.events.handlers.FieldEventHandler.Action#STOP stop} propagation
  34.  * when exiting the eclipse. This can be changed by calling {@link
  35.  * #withHandler(FieldEventHandler)} after construction.</p>
  36.  * @see org.orekit.propagation.FieldPropagator#addEventDetector(FieldEventDetector)
  37.  * @author Pascal Parraud
  38.  */
  39. public class FieldEclipseDetector<T extends RealFieldElement<T>> extends FieldAbstractDetector<FieldEclipseDetector<T>, T> {


  40.     /** Occulting body. */
  41.     private final PVCoordinatesProvider occulting;

  42.     /** Occulting body radius (m). */
  43.     private final double occultingRadius;

  44.     /** Occulted body. */
  45.     private final PVCoordinatesProvider occulted;

  46.     /** Occulted body radius (m). */
  47.     private final double occultedRadius;

  48.     /** Umbra, if true, or penumbra, if false, detection flag. */
  49.     private boolean totalEclipse;

  50.     /** Build a new eclipse detector.
  51.      * <p>The new instance is a total eclipse (umbra) detector with default
  52.      * values for maximal checking interval ({@link #DEFAULT_MAXCHECK})
  53.      * and convergence threshold ({@link #DEFAULT_THRESHOLD}).</p>
  54.      * @param occulted the body to be occulted
  55.      * @param occultedRadius the radius of the body to be occulted (m)
  56.      * @param occulting the occulting body
  57.      * @param occultingRadius the occulting body radius (m)
  58.      * @param field field used by default
  59.      */
  60.     public FieldEclipseDetector(final PVCoordinatesProvider occulted,  final double occultedRadius,
  61.                            final PVCoordinatesProvider occulting, final double occultingRadius, final Field<T> field) {
  62.         this(field.getZero().add(DEFAULT_MAXCHECK), field.getZero().add(DEFAULT_THRESHOLD),
  63.              occulted, occultedRadius, occulting, occultingRadius);
  64.     }

  65.     /** Build a new eclipse detector.
  66.      * <p>The new instance is a total eclipse (umbra) detector with default
  67.      * value for convergence threshold ({@link #DEFAULT_THRESHOLD}).</p>
  68.      * <p>The maximal interval between eclipse checks should be smaller than
  69.      * the half duration of the minimal pass to handle, otherwise some short
  70.      * passes could be missed.</p>
  71.      * @param maxCheck maximal checking interval (s)
  72.      * @param occulted the body to be occulted
  73.      * @param occultedRadius the radius of the body to be occulted in meters
  74.      * @param occulting the occulting body
  75.      * @param occultingRadius the occulting body radius in meters
  76.      */
  77.     public FieldEclipseDetector(final T maxCheck,
  78.                            final PVCoordinatesProvider occulted,  final double occultedRadius,
  79.                            final PVCoordinatesProvider occulting, final double occultingRadius) {
  80.         this(maxCheck, maxCheck.getField().getZero().add(DEFAULT_THRESHOLD),
  81.              occulted, occultedRadius, occulting, occultingRadius);
  82.     }

  83.     /** Build a new eclipse detector.
  84.      * <p>The new instance is a total eclipse (umbra) detector.</p>
  85.      * <p>The maximal interval between eclipse checks should be smaller than
  86.      * the half duration of the minimal pass to handle, otherwise some short
  87.      * passes could be missed.</p>
  88.      * @param maxCheck maximal checking interval (s)
  89.      * @param threshold convergence threshold (s)
  90.      * @param occulted the body to be occulted
  91.      * @param occultedRadius the radius of the body to be occulted in meters
  92.      * @param occulting the occulting body
  93.      * @param occultingRadius the occulting body radius in meters
  94.      */
  95.     public FieldEclipseDetector(final T maxCheck, final T threshold,
  96.                            final PVCoordinatesProvider occulted,  final double occultedRadius,
  97.                            final PVCoordinatesProvider occulting, final double occultingRadius) {
  98.         this(maxCheck, threshold, DEFAULT_MAX_ITER, new FieldStopOnIncreasing<FieldEclipseDetector<T>, T>(),
  99.              occulted, occultedRadius, occulting, occultingRadius, true);
  100.     }

  101.     /** Private constructor with full parameters.
  102.      * <p>
  103.      * This constructor is private as users are expected to use the builder
  104.      * API with the various {@code withXxx()} methods to set up the instance
  105.      * in a readable manner without using a huge amount of parameters.
  106.      * </p>
  107.      * @param maxCheck maximum checking interval (s)
  108.      * @param threshold convergence threshold (s)
  109.      * @param maxIter maximum number of iterations in the event time search
  110.      * @param handler event handler to call at event occurrences
  111.      * @param occulted the body to be occulted
  112.      * @param occultedRadius the radius of the body to be occulted in meters
  113.      * @param occulting the occulting body
  114.      * @param occultingRadius the occulting body radius in meters
  115.      * @param totalEclipse umbra (true) or penumbra (false) detection flag
  116.      * @since 6.1
  117.      */
  118.     private FieldEclipseDetector(final T maxCheck, final T threshold,
  119.                             final int maxIter, final FieldEventHandler<? super FieldEclipseDetector<T>, T> handler,
  120.                             final PVCoordinatesProvider occulted,  final double occultedRadius,
  121.                             final PVCoordinatesProvider occulting, final double occultingRadius,
  122.                             final boolean totalEclipse) {
  123.         super(maxCheck, threshold, maxIter, handler);
  124.         this.occulted        = occulted;
  125.         this.occultedRadius  = FastMath.abs(occultedRadius);
  126.         this.occulting       = occulting;
  127.         this.occultingRadius = FastMath.abs(occultingRadius);
  128.         this.totalEclipse    = totalEclipse;
  129.     }

  130.     /** {@inheritDoc} */
  131.     @Override
  132.     protected FieldEclipseDetector<T> create(final T newMaxCheck, final T newThreshold,
  133.                                      final int nawMaxIter, final FieldEventHandler<? super FieldEclipseDetector<T>, T> newHandler) {
  134.         return new FieldEclipseDetector<>(newMaxCheck, newThreshold, nawMaxIter, newHandler,
  135.                                           occulted, occultedRadius, occulting, occultingRadius, totalEclipse);
  136.     }

  137.     /**
  138.      * Setup the detector to full umbra detection.
  139.      * <p>
  140.      * This will override a penumbra/umbra flag if it has been configured previously.
  141.      * </p>
  142.      * @return a new detector with updated configuration (the instance is not changed)
  143.      * @see #withPenumbra()
  144.      * @since 6.1
  145.      */
  146.     public FieldEclipseDetector<T> withUmbra() {
  147.         return new FieldEclipseDetector<>(getMaxCheckInterval(), getThreshold(), getMaxIterationCount(), getHandler(),
  148.                                           occulted, occultedRadius, occulting, occultingRadius,
  149.                                           true);
  150.     }

  151.     /**
  152.      * Setup the detector to penumbra detection.
  153.      * <p>
  154.      * This will override a penumbra/umbra flag if it has been configured previously.
  155.      * </p>
  156.      * @return a new detector with updated configuration (the instance is not changed)
  157.      * @see #withUmbra()
  158.      * @since 6.1
  159.      */
  160.     public FieldEclipseDetector<T> withPenumbra() {
  161.         return new FieldEclipseDetector<>(getMaxCheckInterval(), getThreshold(), getMaxIterationCount(), getHandler(),
  162.                                           occulted, occultedRadius, occulting, occultingRadius,
  163.                                           false);
  164.     }

  165.     /** Get the occulting body.
  166.      * @return the occulting body
  167.      */
  168.     public PVCoordinatesProvider getOcculting() {
  169.         return occulting;
  170.     }

  171.     /** Get the occulting body radius (m).
  172.      * @return the occulting body radius
  173.      */
  174.     public double getOccultingRadius() {
  175.         return occultingRadius;
  176.     }

  177.     /** Get the occulted body.
  178.      * @return the occulted body
  179.      */
  180.     public PVCoordinatesProvider getOcculted() {
  181.         return occulted;
  182.     }

  183.     /** Get the occulted body radius (m).
  184.      * @return the occulted body radius
  185.      */
  186.     public double getOccultedRadius() {
  187.         return occultedRadius;
  188.     }

  189.     /** Get the total eclipse detection flag.
  190.      * @return the total eclipse detection flag (true for umbra events detection,
  191.      * false for penumbra events detection)
  192.      */
  193.     public boolean getTotalEclipse() {
  194.         return totalEclipse;
  195.     }

  196.     /** Compute the value of the switching function.
  197.      * This function becomes negative when entering the region of shadow
  198.      * and positive when exiting.
  199.      * @param s the current state information: date, kinematics, attitude
  200.      * @return value of the switching function
  201.      * @exception OrekitException if some specific error occurs
  202.      */
  203.     public T g(final FieldSpacecraftState<T> s) throws OrekitException {
  204.         final Vector3D pted = occulted.getPVCoordinates(s.getDate().toAbsoluteDate(), s.getFrame()).getPosition();
  205.         final Vector3D ping = occulting.getPVCoordinates(s.getDate().toAbsoluteDate(), s.getFrame()).getPosition();
  206.         final Vector3D psat = s.toSpacecraftState().getPVCoordinates().getPosition();
  207.         final Vector3D ps   = pted.subtract(psat);
  208.         final Vector3D po   = ping.subtract(psat);
  209.         final double angle  = Vector3D.angle(ps, po);
  210.         final double rs     = FastMath.asin(occultedRadius / ps.getNorm());
  211.         if (Double.isNaN(rs)) {
  212.             return s.getOrbit().getA().getField().getZero().add(FastMath.PI);
  213.         }
  214.         final double ro     = FastMath.asin(occultingRadius / po.getNorm());
  215.         if (Double.isNaN(ro)) {
  216.             return s.getOrbit().getA().getField().getZero().add(-FastMath.PI);
  217.         }
  218.         return totalEclipse ? (s.getOrbit().getA().getField().getZero().add(angle - ro + rs)) :
  219.                               (s.getOrbit().getA().getField().getZero().add(angle - ro - rs));
  220.     }

  221. }