FieldEclipseDetector.java

  1. /* Copyright 2002-2019 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.propagation.FieldSpacecraftState;
  23. import org.orekit.propagation.events.handlers.FieldEventHandler;
  24. import org.orekit.propagation.events.handlers.FieldStopOnIncreasing;
  25. import org.orekit.utils.PVCoordinatesProvider;

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  219. }