EclipseDetector.java

  1. /* Copyright 2002-2025 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.ExtendedPositionProvider;
  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_MAX_CHECK})
  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 ExtendedPositionProvider 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_MAX_CHECK})
  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(EventDetectionSettings.getDefaultEventDetectionSettings(), new StopOnIncreasing(),
  80.              occultationEngine, 0.0, true);
  81.     }

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

  102.     /** {@inheritDoc} */
  103.     @Override
  104.     protected EclipseDetector create(final EventDetectionSettings detectionSettings, final EventHandler newHandler) {
  105.         return new EclipseDetector(detectionSettings, newHandler, occultationEngine, margin, totalEclipse);
  106.     }

  107.     /**
  108.      * Setup the detector to full umbra detection.
  109.      * <p>
  110.      * This will override a penumbra/umbra flag if it has been configured previously.
  111.      * </p>
  112.      * @return a new detector with updated configuration (the instance is not changed)
  113.      * @see #withPenumbra()
  114.      * @since 6.1
  115.      */
  116.     public EclipseDetector withUmbra() {
  117.         return new EclipseDetector(getDetectionSettings(), getHandler(), occultationEngine, margin, true);
  118.     }

  119.     /**
  120.      * Setup the detector to penumbra detection.
  121.      * <p>
  122.      * This will override a penumbra/umbra flag if it has been configured previously.
  123.      * </p>
  124.      * @return a new detector with updated configuration (the instance is not changed)
  125.      * @see #withUmbra()
  126.      * @since 6.1
  127.      */
  128.     public EclipseDetector withPenumbra() {
  129.         return new EclipseDetector(getDetectionSettings(), getHandler(), occultationEngine, margin, false);
  130.     }

  131.     /**
  132.      * Setup a margin to angle detection.
  133.      * <p>
  134.      * A positive margin implies eclipses are "larger" hence entry occurs earlier and exit occurs later
  135.      * than a detector with 0 margin.
  136.      * </p>
  137.      * @param newMargin angular margin to apply to eclipse detection (rad)
  138.      * @return a new detector with updated configuration (the instance is not changed)
  139.      * @since 12.0
  140.      */
  141.     public EclipseDetector withMargin(final double newMargin) {
  142.         return new EclipseDetector(getDetectionSettings(), getHandler(), occultationEngine, newMargin, totalEclipse);
  143.     }

  144.     /** Get the angular margin used for eclipse detection.
  145.      * @return angular margin used for eclipse detection (rad)
  146.      * @since 12.0
  147.      */
  148.     public double getMargin() {
  149.         return margin;
  150.     }

  151.     /** Get the occultation engine.
  152.      * @return occultation engine
  153.      * @since 12.0
  154.      */
  155.     public OccultationEngine getOccultationEngine() {
  156.         return occultationEngine;
  157.     }

  158.     /** Get the total eclipse detection flag.
  159.      * @return the total eclipse detection flag (true for umbra events detection,
  160.      * false for penumbra events detection)
  161.      */
  162.     public boolean getTotalEclipse() {
  163.         return totalEclipse;
  164.     }

  165.     /** Compute the value of the switching function.
  166.      * This function becomes negative when entering the region of shadow
  167.      * and positive when exiting.
  168.      * @param s the current state information: date, kinematics, attitude
  169.      * @return value of the switching function
  170.      */
  171.     public double g(final SpacecraftState s) {
  172.         final OccultationEngine.OccultationAngles angles = occultationEngine.angles(s);
  173.         return totalEclipse ?
  174.                (angles.getSeparation() - angles.getLimbRadius() + angles.getOccultedApparentRadius() + margin) :
  175.                (angles.getSeparation() - angles.getLimbRadius() - angles.getOccultedApparentRadius() + margin);
  176.     }

  177. }