FieldEclipseDetector.java

  1. /* Copyright 2002-2022 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.Vector3D;
  21. import org.hipparchus.ode.events.Action;
  22. import org.hipparchus.util.FastMath;
  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 Action#CONTINUE continue}
  31.  * propagation when entering the eclipse and to {@link Action#STOP stop} propagation
  32.  * when exiting the eclipse. This can be changed by calling {@link
  33.  * #withHandler(FieldEventHandler)} after construction.</p>
  34.  * @see org.orekit.propagation.FieldPropagator#addEventDetector(FieldEventDetector)
  35.  * @author Pascal Parraud
  36.  */
  37. public class FieldEclipseDetector<T extends CalculusFieldElement<T>> extends FieldAbstractDetector<FieldEclipseDetector<T>, T> {


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  194.     /** Compute the value of the switching function.
  195.      * This function becomes negative when entering the region of shadow
  196.      * and positive when exiting.
  197.      * @param s the current state information: date, kinematics, attitude
  198.      * @return value of the switching function
  199.      */
  200.     public T g(final FieldSpacecraftState<T> s) {
  201.         final T        zero = s.getOrbit().getA().getField().getZero();
  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 zero.getPi();
  211.         }
  212.         final double ro     = FastMath.asin(occultingRadius / po.getNorm());
  213.         if (Double.isNaN(ro)) {
  214.             return zero.getPi().negate();
  215.         }
  216.         return totalEclipse ? (zero.add(angle - ro + rs)) : (zero.add(angle - ro - rs));
  217.     }

  218. }