FieldRelativeDistanceDetector.java

  1. /* Copyright 2022-2025 Romain Serra
  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.hipparchus.ode.events.Action;
  21. import org.orekit.propagation.FieldSpacecraftState;
  22. import org.orekit.propagation.events.handlers.FieldEventHandler;
  23. import org.orekit.propagation.events.handlers.FieldStopOnEvent;
  24. import org.orekit.utils.FieldPVCoordinatesProvider;

  25. /**
  26.  * Detector of specific value for the distance relative to another trajectory (using the Euclidean norm).
  27.  * <p>
  28.  * The default implementation behavior is to {@link Action#STOP stop} propagation.
  29.  * This can be changed by calling {@link #withHandler(org.orekit.propagation.events.handlers.FieldEventHandler)} after construction.
  30.  * </p>
  31.  * <p>
  32.  * As this detector needs two objects (moving relative to each other), it embeds one
  33.  * {@link org.orekit.utils.FieldPVCoordinatesProvider coordinates provider} for the secondary object and is registered as an event detector in
  34.  * the propagator of the primary object. The secondary object {@link org.orekit.utils.FieldPVCoordinatesProvider coordinates provider} will
  35.  * therefore be driven by this detector (and hence by the propagator in which this detector is registered).
  36.  * </p>
  37.  * <p>
  38.  * For efficiency reason during the event search loop, it is recommended to have the secondary provider be an analytical
  39.  * propagator or an ephemeris. A numerical propagator as a secondary propagator works but is expected to be
  40.  * computationally costly.
  41.  * </p>
  42.  *
  43.  * @see org.orekit.propagation.FieldPropagator#addEventDetector(FieldEventDetector)
  44.  * @author Romain Serra
  45.  * @since 12.1
  46.  */
  47. public class FieldRelativeDistanceDetector<T extends CalculusFieldElement<T>>
  48.         extends FieldAbstractDetector<FieldRelativeDistanceDetector<T>, T> {

  49.     /**
  50.      * PVCoordinates provider of the other object used to define relative distance.
  51.      */
  52.     private final FieldPVCoordinatesProvider<T> secondaryPVProvider;

  53.     /** Relative distance value triggering detection. */
  54.     private final T distanceThreshold;

  55.     /**
  56.      * Constructor with default values.
  57.      * <p>
  58.      * By default, the implemented behavior is to {@link Action#STOP stop} propagation at detection.
  59.      * </p>
  60.      *
  61.      * @param secondaryPVProvider PVCoordinates provider of the other object defining relative distance.
  62.      * @param distanceThreshold Relative distance threshold for event detection
  63.      */
  64.     public FieldRelativeDistanceDetector(final FieldPVCoordinatesProvider<T> secondaryPVProvider,
  65.                                          final T distanceThreshold) {
  66.         this(new FieldEventDetectionSettings<>(distanceThreshold.getField(), EventDetectionSettings.getDefaultEventDetectionSettings()),
  67.                 new FieldStopOnEvent<>(), secondaryPVProvider, distanceThreshold);
  68.     }

  69.     /**
  70.      * Constructor.
  71.      * <p>
  72.      * This constructor is to be used if the user wants to change the default behavior of the detector.
  73.      * </p>
  74.      *
  75.      * @param detectionSettings   Detection settings.
  76.      * @param handler             Event handler to call at event occurrences.
  77.      * @param secondaryPVProvider PVCoordinates provider of the other object defining relative distance.
  78.      * @param distanceThreshold Relative distance threshold for event detection
  79.      * @see FieldEventHandler
  80.      * @since 12.2
  81.      */
  82.     protected FieldRelativeDistanceDetector(final FieldEventDetectionSettings<T> detectionSettings,
  83.                                             final FieldEventHandler<T> handler, final FieldPVCoordinatesProvider<T> secondaryPVProvider,
  84.                                             final T distanceThreshold) {
  85.         super(detectionSettings, handler);
  86.         this.secondaryPVProvider = secondaryPVProvider;
  87.         this.distanceThreshold = distanceThreshold;
  88.     }

  89.     /**
  90.      * The {@code g} is positive when the relative distance is larger or equal than the threshold,
  91.      * non-positive otherwise.
  92.      *
  93.      * @param s the current state information: date, kinematics, attitude
  94.      * @return value of the switching function
  95.      */
  96.     @Override
  97.     public T g(final FieldSpacecraftState<T> s) {
  98.         final FieldVector3D<T> secondaryPosition = getSecondaryPVProvider().getPosition(s.getDate(), s.getFrame());
  99.         final T relativeDistance = s.getPosition().subtract(secondaryPosition).getNorm();
  100.         return relativeDistance.subtract(distanceThreshold);
  101.     }

  102.     /** {@inheritDoc} */
  103.     @Override
  104.     protected FieldRelativeDistanceDetector<T> create(final FieldEventDetectionSettings<T> detectionSettings,
  105.                                                       final FieldEventHandler<T> newHandler) {
  106.         return new FieldRelativeDistanceDetector<>(detectionSettings, newHandler, secondaryPVProvider,
  107.                 distanceThreshold);
  108.     }

  109.     /**
  110.      * Get the secondary position-velocity provider stored in this instance.
  111.      *
  112.      * @return the secondary position-velocity provider stored in this instance
  113.      */
  114.     public FieldPVCoordinatesProvider<T> getSecondaryPVProvider() {
  115.         return secondaryPVProvider;
  116.     }

  117.     /**
  118.      * Get the relative distance threshold.
  119.      *
  120.      * @return threshold triggering detection
  121.      */
  122.     public T getDistanceThreshold() {
  123.         return distanceThreshold;
  124.     }
  125. }