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(new EventDetectionSettings(AdaptableInterval.of(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.      * @deprecated as of 12.2
  98.      */
  99.     @Deprecated
  100.     protected EclipseDetector(final AdaptableInterval maxCheck, final double threshold,
  101.                               final int maxIter, final EventHandler handler,
  102.                               final OccultationEngine occultationEngine, final double margin, final boolean totalEclipse) {
  103.         this(new EventDetectionSettings(maxCheck, threshold, maxIter), handler, occultationEngine, margin, totalEclipse);
  104.     }

  105.     /** Protected constructor with full parameters.
  106.      * <p>
  107.      * This constructor is not public as users are expected to use the builder
  108.      * API with the various {@code withXxx()} methods to set up the instance
  109.      * in a readable manner without using a huge amount of parameters.
  110.      * </p>
  111.      * @param detectionSettings detection settings
  112.      * @param handler event handler to call at event occurrences
  113.      * @param occultationEngine occultation engine
  114.      * @param margin to apply to eclipse angle (rad)
  115.      * @param totalEclipse umbra (true) or penumbra (false) detection flag
  116.      * @since 12.2
  117.      */
  118.     protected EclipseDetector(final EventDetectionSettings detectionSettings, final EventHandler handler,
  119.                               final OccultationEngine occultationEngine, final double margin, final boolean totalEclipse) {
  120.         super(detectionSettings, handler);
  121.         this.occultationEngine = occultationEngine;
  122.         this.margin            = margin;
  123.         this.totalEclipse      = totalEclipse;
  124.     }

  125.     /** {@inheritDoc} */
  126.     @Override
  127.     protected EclipseDetector create(final AdaptableInterval newMaxCheck, final double newThreshold,
  128.                                      final int nawMaxIter, final EventHandler newHandler) {
  129.         return new EclipseDetector(newMaxCheck, newThreshold, nawMaxIter, newHandler,
  130.                                    occultationEngine, margin, totalEclipse);
  131.     }

  132.     /**
  133.      * Setup the detector to full umbra detection.
  134.      * <p>
  135.      * This will override a penumbra/umbra flag if it has been configured previously.
  136.      * </p>
  137.      * @return a new detector with updated configuration (the instance is not changed)
  138.      * @see #withPenumbra()
  139.      * @since 6.1
  140.      */
  141.     public EclipseDetector withUmbra() {
  142.         return new EclipseDetector(getDetectionSettings(), getHandler(), occultationEngine, margin, true);
  143.     }

  144.     /**
  145.      * Setup the detector to penumbra detection.
  146.      * <p>
  147.      * This will override a penumbra/umbra flag if it has been configured previously.
  148.      * </p>
  149.      * @return a new detector with updated configuration (the instance is not changed)
  150.      * @see #withUmbra()
  151.      * @since 6.1
  152.      */
  153.     public EclipseDetector withPenumbra() {
  154.         return new EclipseDetector(getDetectionSettings(), getHandler(), occultationEngine, margin, false);
  155.     }

  156.     /**
  157.      * Setup a margin to angle detection.
  158.      * <p>
  159.      * A positive margin implies eclipses are "larger" hence entry occurs earlier and exit occurs later
  160.      * than a detector with 0 margin.
  161.      * </p>
  162.      * @param newMargin angular margin to apply to eclipse detection (rad)
  163.      * @return a new detector with updated configuration (the instance is not changed)
  164.      * @since 12.0
  165.      */
  166.     public EclipseDetector withMargin(final double newMargin) {
  167.         return new EclipseDetector(getDetectionSettings(), getHandler(), occultationEngine, newMargin, totalEclipse);
  168.     }

  169.     /** Get the angular margin used for eclipse detection.
  170.      * @return angular margin used for eclipse detection (rad)
  171.      * @since 12.0
  172.      */
  173.     public double getMargin() {
  174.         return margin;
  175.     }

  176.     /** Get the occultation engine.
  177.      * @return occultation engine
  178.      * @since 12.0
  179.      */
  180.     public OccultationEngine getOccultationEngine() {
  181.         return occultationEngine;
  182.     }

  183.     /** Get the total eclipse detection flag.
  184.      * @return the total eclipse detection flag (true for umbra events detection,
  185.      * false for penumbra events detection)
  186.      */
  187.     public boolean getTotalEclipse() {
  188.         return totalEclipse;
  189.     }

  190.     /** Compute the value of the switching function.
  191.      * This function becomes negative when entering the region of shadow
  192.      * and positive when exiting.
  193.      * @param s the current state information: date, kinematics, attitude
  194.      * @return value of the switching function
  195.      */
  196.     public double g(final SpacecraftState s) {
  197.         final OccultationEngine.OccultationAngles angles = occultationEngine.angles(s);
  198.         return totalEclipse ?
  199.                (angles.getSeparation() - angles.getLimbRadius() + angles.getOccultedApparentRadius() + margin) :
  200.                (angles.getSeparation() - angles.getLimbRadius() - angles.getOccultedApparentRadius() + margin);
  201.     }

  202. }