FieldGroundAtNightDetector.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.geometry.euclidean.threed.FieldVector3D;
  20. import org.orekit.frames.Frame;
  21. import org.orekit.frames.TopocentricFrame;
  22. import org.orekit.models.AtmosphericRefractionModel;
  23. import org.orekit.propagation.FieldSpacecraftState;
  24. import org.orekit.propagation.events.handlers.FieldContinueOnEvent;
  25. import org.orekit.propagation.events.handlers.FieldEventHandler;
  26. import org.orekit.time.FieldAbsoluteDate;
  27. import org.orekit.utils.ExtendedPositionProvider;


  28. /** Detector for ground location being at night.
  29.  * <p>
  30.  * This detector is mainly useful for scheduling optical measurements
  31.  * (either passive telescope observation of satellites against the stars background
  32.  *  or active satellite laser ranging).
  33.  * </p>
  34.  * <p>
  35.  * The {@code g} function of this detector is positive when ground is at night
  36.  * (i.e. Sun is below dawn/dusk elevation angle).
  37.  * </p>
  38.  * @author Luc Maisonobe
  39.  * @author Romain Serra
  40.  * @see GroundAtNightDetector
  41.  * @since 13.1
  42.  */
  43. public class FieldGroundAtNightDetector<T extends CalculusFieldElement<T>>
  44.         extends FieldAbstractTopocentricDetector<FieldGroundAtNightDetector<T>, T> {

  45.     /** Provider for Sun position. */
  46.     private final ExtendedPositionProvider sun;

  47.     /** Sun elevation below which we consider night is dark enough. */
  48.     private final T dawnDuskElevation;

  49.     /** Atmospheric Model used for calculations, if defined. */
  50.     private final AtmosphericRefractionModel refractionModel;

  51.     /** Simple constructor.
  52.      * @param topocentricFrame ground location to check
  53.      * @param sun provider for Sun position
  54.      * @param dawnDuskElevation Sun elevation below which we consider night is dark enough (rad)
  55.      * @param refractionModel reference to refraction model (null if refraction should be ignored)
  56.      */
  57.     public FieldGroundAtNightDetector(final TopocentricFrame topocentricFrame, final ExtendedPositionProvider sun,
  58.                                       final T dawnDuskElevation,
  59.                                       final AtmosphericRefractionModel refractionModel) {
  60.         this(topocentricFrame, sun, dawnDuskElevation, refractionModel, new FieldEventDetectionSettings<>(dawnDuskElevation.getField(),
  61.                 EventDetectionSettings.getDefaultEventDetectionSettings()), new FieldContinueOnEvent<>());
  62.     }

  63.     /** Private constructor.
  64.      * @param topocentricFrame ground location from which measurement is performed
  65.      * @param sun provider for Sun position
  66.      * @param dawnDuskElevation Sun elevation below which we consider night is dark enough (rad)
  67.      * @param refractionModel reference to refraction model (null if refraction should be ignored),
  68.      * @param detectionSettings event detection settings
  69.      * @param handler   event handler to call at event occurrences
  70.      */
  71.     protected FieldGroundAtNightDetector(final TopocentricFrame topocentricFrame, final ExtendedPositionProvider sun,
  72.                                          final T dawnDuskElevation,
  73.                                          final AtmosphericRefractionModel refractionModel,
  74.                                          final FieldEventDetectionSettings<T> detectionSettings,
  75.                                          final FieldEventHandler<T> handler) {
  76.         super(detectionSettings, handler, topocentricFrame);
  77.         this.sun               = sun;
  78.         this.dawnDuskElevation = dawnDuskElevation;
  79.         this.refractionModel   = refractionModel;
  80.     }

  81.     /** {@inheritDoc} */
  82.     @Override
  83.     protected FieldGroundAtNightDetector<T> create(final FieldEventDetectionSettings<T> detectionSettings,
  84.                                                    final FieldEventHandler<T> newHandler) {
  85.         return new FieldGroundAtNightDetector<>(getTopocentricFrame(), sun, dawnDuskElevation, refractionModel,
  86.                 detectionSettings, newHandler);
  87.     }

  88.     @Override
  89.     public boolean dependsOnTimeOnly() {
  90.         return true;
  91.     }

  92.     /** {@inheritDoc}
  93.      * <p>
  94.      * The {@code g} function of this detector is positive when ground is at night
  95.      * (i.e. Sun is below dawn/dusk elevation angle).
  96.      * </p>
  97.      * <p>
  98.      * This function only depends on date, not on the actual position of the spacecraft.
  99.      * </p>
  100.      */
  101.     @Override
  102.     public T g(final FieldSpacecraftState<T> state) {

  103.         final FieldAbsoluteDate<T> date     = state.getDate();
  104.         final Frame         frame    = state.getFrame();
  105.         final FieldVector3D<T> position = sun.getPosition(date, frame);
  106.         final T trueElevation   = getTopocentricFrame().getElevation(position, frame, date);

  107.         final T calculatedElevation;
  108.         if (refractionModel != null) {
  109.             calculatedElevation = trueElevation.add(refractionModel.getRefraction(trueElevation.getReal()));
  110.         } else {
  111.             calculatedElevation = trueElevation;
  112.         }

  113.         return dawnDuskElevation.subtract(calculatedElevation);

  114.     }

  115. }