EclipseDetector.java

  1. /* Copyright 2002-2024 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.ode.events.Action;
  19. import org.orekit.bodies.OneAxisEllipsoid;
  20. import org.orekit.propagation.SpacecraftState;
  21. import org.orekit.propagation.events.handlers.EventHandler;
  22. import org.orekit.propagation.events.handlers.StopOnIncreasing;
  23. import org.orekit.utils.ExtendedPVCoordinatesProvider;
  24. import org.orekit.utils.OccultationEngine;
  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 occulted body is given through a {@link PVCoordinatesProvider} and its radius in meters. It is modeled as a sphere.
  30.  * </p>
  31.  * <p>Since v10.0 the occulting body is a {@link OneAxisEllipsoid}, before it was modeled as a  sphere.
  32.  * <br>It was changed to precisely model Solar eclipses by the Earth, especially for Low Earth Orbits.
  33.  * <br>If you want eclipses by a spherical occulting body, set its flattening to 0. when defining its OneAxisEllipsoid model..
  34.  * </p>
  35.  * <p>The {@link #withUmbra} or {@link #withPenumbra} methods will tell you if the event is triggered when complete umbra/lighting
  36.  * is achieved or when entering/living the penumbra zone.
  37.  * <br>The default behavior is detecting complete umbra/lighting events.
  38.  * <br>If you want to have both, you'll need to set up two distinct detectors.
  39.  * </p>
  40.  * <p>The default implementation behavior is to {@link Action#CONTINUE continue}
  41.  * propagation when entering the eclipse and to {@link Action#STOP stop} propagation
  42.  * when exiting the eclipse.
  43.  * <br>This can be changed by calling {@link #withHandler(EventHandler)} after construction.
  44.  * </p>
  45.  * @see org.orekit.propagation.Propagator#addEventDetector(EventDetector)
  46.  * @author Pascal Parraud
  47.  * @author Luc Maisonobe
  48.  */
  49. public class EclipseDetector extends AbstractDetector<EclipseDetector> {

  50.     /** Occultation engine.
  51.      * @since 12.0
  52.      */
  53.     private final OccultationEngine occultationEngine;

  54.     /** Umbra, if true, or penumbra, if false, detection flag. */
  55.     private final boolean totalEclipse;

  56.     /** Margin to apply to eclipse angle. */
  57.     private final double margin;

  58.     /** Build a new eclipse detector.
  59.      * <p>The new instance is a total eclipse (umbra) detector with default
  60.      * values for maximal checking interval ({@link #DEFAULT_MAXCHECK})
  61.      * and convergence threshold ({@link #DEFAULT_THRESHOLD}).</p>
  62.      * @param occulted the body to be occulted
  63.      * @param occultedRadius the radius of the body to be occulted (m)
  64.      * @param occulting the occulting body
  65.      * @since 12.0
  66.      */
  67.     public EclipseDetector(final ExtendedPVCoordinatesProvider occulted,  final double occultedRadius,
  68.                            final OneAxisEllipsoid occulting) {
  69.         this(new OccultationEngine(occulted, occultedRadius, occulting));
  70.     }

  71.     /** Build a new eclipse detector.
  72.      * <p>The new instance is a total eclipse (umbra) detector with default
  73.      * values for maximal checking interval ({@link #DEFAULT_MAXCHECK})
  74.      * and convergence threshold ({@link #DEFAULT_THRESHOLD}).</p>
  75.      * @param occultationEngine occultation engine
  76.      * @since 12.0
  77.      */
  78.     public EclipseDetector(final OccultationEngine occultationEngine) {
  79.         this(s -> DEFAULT_MAXCHECK, DEFAULT_THRESHOLD, DEFAULT_MAX_ITER,
  80.              new StopOnIncreasing(),
  81.              occultationEngine, 0.0, true);
  82.     }

  83.     /** Protected constructor with full parameters.
  84.      * <p>
  85.      * This constructor is not public as users are expected to use the builder
  86.      * API with the various {@code withXxx()} methods to set up the instance
  87.      * in a readable manner without using a huge amount of parameters.
  88.      * </p>
  89.      * @param maxCheck maximum checking interval
  90.      * @param threshold convergence threshold (s)
  91.      * @param maxIter maximum number of iterations in the event time search
  92.      * @param handler event handler to call at event occurrences
  93.      * @param occultationEngine occultation engine
  94.      * @param margin to apply to eclipse angle (rad)
  95.      * @param totalEclipse umbra (true) or penumbra (false) detection flag
  96.      * @since 12.0
  97.      */
  98.     protected EclipseDetector(final AdaptableInterval maxCheck, final double threshold,
  99.                               final int maxIter, final EventHandler handler,
  100.                               final OccultationEngine occultationEngine, final double margin, final boolean totalEclipse) {
  101.         super(maxCheck, threshold, maxIter, handler);
  102.         this.occultationEngine = occultationEngine;
  103.         this.margin            = margin;
  104.         this.totalEclipse      = totalEclipse;
  105.     }

  106.     /** {@inheritDoc} */
  107.     @Override
  108.     protected EclipseDetector create(final AdaptableInterval newMaxCheck, final double newThreshold,
  109.                                      final int nawMaxIter, final EventHandler newHandler) {
  110.         return new EclipseDetector(newMaxCheck, newThreshold, nawMaxIter, newHandler,
  111.                                    occultationEngine, margin, totalEclipse);
  112.     }

  113.     /**
  114.      * Setup the detector to full umbra detection.
  115.      * <p>
  116.      * This will override a penumbra/umbra flag if it has been configured previously.
  117.      * </p>
  118.      * @return a new detector with updated configuration (the instance is not changed)
  119.      * @see #withPenumbra()
  120.      * @since 6.1
  121.      */
  122.     public EclipseDetector withUmbra() {
  123.         return new EclipseDetector(getMaxCheckInterval(), getThreshold(), getMaxIterationCount(), getHandler(),
  124.                                    occultationEngine, margin, true);
  125.     }

  126.     /**
  127.      * Setup the detector to penumbra detection.
  128.      * <p>
  129.      * This will override a penumbra/umbra flag if it has been configured previously.
  130.      * </p>
  131.      * @return a new detector with updated configuration (the instance is not changed)
  132.      * @see #withUmbra()
  133.      * @since 6.1
  134.      */
  135.     public EclipseDetector withPenumbra() {
  136.         return new EclipseDetector(getMaxCheckInterval(), getThreshold(), getMaxIterationCount(), getHandler(),
  137.                                    occultationEngine, margin, false);
  138.     }

  139.     /**
  140.      * Setup a margin to angle detection.
  141.      * <p>
  142.      * A positive margin implies eclipses are "larger" hence entry occurs earlier and exit occurs later
  143.      * than a detector with 0 margin.
  144.      * </p>
  145.      * @param newMargin angular margin to apply to eclipse detection (rad)
  146.      * @return a new detector with updated configuration (the instance is not changed)
  147.      * @since 12.0
  148.      */
  149.     public EclipseDetector withMargin(final double newMargin) {
  150.         return new EclipseDetector(getMaxCheckInterval(), getThreshold(), getMaxIterationCount(), getHandler(),
  151.                                    occultationEngine, newMargin, totalEclipse);
  152.     }

  153.     /** Get the angular margin used for eclipse detection.
  154.      * @return angular margin used for eclipse detection (rad)
  155.      * @since 12.0
  156.      */
  157.     public double getMargin() {
  158.         return margin;
  159.     }

  160.     /** Get the occultation engine.
  161.      * @return occultation engine
  162.      * @since 12.0
  163.      */
  164.     public OccultationEngine getOccultationEngine() {
  165.         return occultationEngine;
  166.     }

  167.     /** Get the total eclipse detection flag.
  168.      * @return the total eclipse detection flag (true for umbra events detection,
  169.      * false for penumbra events detection)
  170.      */
  171.     public boolean getTotalEclipse() {
  172.         return totalEclipse;
  173.     }

  174.     /** Compute the value of the switching function.
  175.      * This function becomes negative when entering the region of shadow
  176.      * and positive when exiting.
  177.      * @param s the current state information: date, kinematics, attitude
  178.      * @return value of the switching function
  179.      */
  180.     public double g(final SpacecraftState s) {
  181.         final OccultationEngine.OccultationAngles angles = occultationEngine.angles(s);
  182.         return totalEclipse ?
  183.                (angles.getSeparation() - angles.getLimbRadius() + angles.getOccultedApparentRadius() + margin) :
  184.                (angles.getSeparation() - angles.getLimbRadius() - angles.getOccultedApparentRadius() + margin);
  185.     }

  186. }