FieldEclipseDetector.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.CalculusFieldElement;
  19. import org.hipparchus.Field;
  20. import org.hipparchus.ode.events.Action;
  21. import org.orekit.bodies.OneAxisEllipsoid;
  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.ExtendedPositionProvider;
  26. import org.orekit.utils.OccultationEngine;

  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.  * @param <T> the type of the field elements
  35.  * @see org.orekit.propagation.FieldPropagator#addEventDetector(FieldEventDetector)
  36.  * @author Pascal Parraud
  37.  */
  38. public class FieldEclipseDetector<T extends CalculusFieldElement<T>> extends FieldAbstractDetector<FieldEclipseDetector<T>, T> {

  39.     /** Occultation engine.
  40.      * @since 12.0
  41.      */
  42.     private final OccultationEngine occultationEngine;

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

  45.     /** Margin to apply to eclipse angle. */
  46.     private final T margin;

  47.     /** Build a new eclipse detector.
  48.      * <p>The new instance is a total eclipse (umbra) detector with default
  49.      * values for maximal checking interval ({@link #DEFAULT_MAX_CHECK})
  50.      * and convergence threshold ({@link #DEFAULT_THRESHOLD}).</p>
  51.      * @param field field used by default
  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.      * @since 12.0
  56.      */
  57.     public FieldEclipseDetector(final Field<T> field,
  58.                                 final ExtendedPositionProvider occulted, final double occultedRadius,
  59.                                 final OneAxisEllipsoid occulting) {
  60.         this(field, new OccultationEngine(occulted, occultedRadius, occulting));
  61.     }

  62.     /** Build a new eclipse detector.
  63.      * <p>The new instance is a total eclipse (umbra) detector with default
  64.      * values for maximal checking interval ({@link #DEFAULT_MAX_CHECK})
  65.      * and convergence threshold ({@link #DEFAULT_THRESHOLD}).</p>
  66.      * @param field field used by default
  67.      * @param occultationEngine occultation engine
  68.      * @since 12.0
  69.      */
  70.     public FieldEclipseDetector(final Field<T> field, final OccultationEngine occultationEngine) {
  71.         this(new FieldEventDetectionSettings<>(field, EventDetectionSettings.getDefaultEventDetectionSettings()),
  72.                 new FieldStopOnIncreasing<>(), occultationEngine, field.getZero(), true);
  73.     }

  74.     /** Protected constructor with full parameters.
  75.      * <p>
  76.      * This constructor is not public as users are expected to use the builder
  77.      * API with the various {@code withXxx()} methods to set up the instance
  78.      * in a readable manner without using a huge amount of parameters.
  79.      * </p>
  80.      * @param detectionSettings event detection settings
  81.      * @param handler event handler to call at event occurrences
  82.      * @param occultationEngine occultation engine
  83.      * @param margin to apply to eclipse angle (rad)
  84.      * @param totalEclipse umbra (true) or penumbra (false) detection flag
  85.      * @since 13.0
  86.      */
  87.     protected FieldEclipseDetector(final FieldEventDetectionSettings<T> detectionSettings, final FieldEventHandler<T> handler,
  88.                                    final OccultationEngine occultationEngine, final T margin, final boolean totalEclipse) {
  89.         super(detectionSettings, handler);
  90.         this.occultationEngine = occultationEngine;
  91.         this.margin            = margin;
  92.         this.totalEclipse      = totalEclipse;
  93.     }

  94.     /** {@inheritDoc} */
  95.     @Override
  96.     protected FieldEclipseDetector<T> create(final FieldEventDetectionSettings<T> detectionSettings,
  97.                                              final FieldEventHandler<T> newHandler) {
  98.         return new FieldEclipseDetector<>(detectionSettings, newHandler, occultationEngine, margin, totalEclipse);
  99.     }

  100.     /**
  101.      * Setup the detector to full umbra detection.
  102.      * <p>
  103.      * This will override a penumbra/umbra flag if it has been configured previously.
  104.      * </p>
  105.      * @return a new detector with updated configuration (the instance is not changed)
  106.      * @see #withPenumbra()
  107.      * @since 6.1
  108.      */
  109.     public FieldEclipseDetector<T> withUmbra() {
  110.         return new FieldEclipseDetector<>(getDetectionSettings(), getHandler(),
  111.                                           occultationEngine, margin, true);
  112.     }

  113.     /**
  114.      * Setup the detector to penumbra 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 #withUmbra()
  120.      * @since 6.1
  121.      */
  122.     public FieldEclipseDetector<T> withPenumbra() {
  123.         return new FieldEclipseDetector<>(getDetectionSettings(), getHandler(),
  124.                                           occultationEngine, margin, false);
  125.     }

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

  140.     /** Get the angular margin used for eclipse detection.
  141.      * @return angular margin used for eclipse detection (rad)
  142.      * @since 12.0
  143.      */
  144.     public T getMargin() {
  145.         return margin;
  146.     }

  147.     /** Get the occultation engine.
  148.      * @return occultation engine
  149.      * @since 12.0
  150.      */
  151.     public OccultationEngine getOccultationEngine() {
  152.         return occultationEngine;
  153.     }

  154.     /** Get the total eclipse detection flag.
  155.      * @return the total eclipse detection flag (true for umbra events detection,
  156.      * false for penumbra events detection)
  157.      */
  158.     public boolean getTotalEclipse() {
  159.         return totalEclipse;
  160.     }

  161.     /** Compute the value of the switching function.
  162.      * This function becomes negative when entering the region of shadow
  163.      * and positive when exiting.
  164.      * @param s the current state information: date, kinematics, attitude
  165.      * @return value of the switching function
  166.      */
  167.     public T g(final FieldSpacecraftState<T> s) {
  168.         final OccultationEngine.FieldOccultationAngles<T> angles = occultationEngine.angles(s);
  169.         return totalEclipse ?
  170.                angles.getSeparation().subtract(angles.getLimbRadius()).add(angles.getOccultedApparentRadius().add(margin)) :
  171.                angles.getSeparation().subtract(angles.getLimbRadius()).subtract(angles.getOccultedApparentRadius().add(margin));
  172.     }

  173. }