FieldRelativeDistanceDetector.java

  1. /* Copyright 2022-2024 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(FieldAdaptableInterval.of(DEFAULT_MAXCHECK), distanceThreshold.getField().getZero().newInstance(DEFAULT_THRESHOLD),
  67.                 DEFAULT_MAX_ITER, 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 maxCheck            Maximum checking interval.
  76.      * @param threshold           Convergence threshold (s).
  77.      * @param maxIter             Maximum number of iterations in the event time search.
  78.      * @param handler             Event handler to call at event occurrences.
  79.      * @param secondaryPVProvider PVCoordinates provider of the other object defining relative distance.
  80.      * @param distanceThreshold Relative distance threshold for event detection
  81.      * @see FieldEventHandler
  82.      */
  83.     protected FieldRelativeDistanceDetector(final FieldAdaptableInterval<T> maxCheck, final T threshold, final int maxIter,
  84.                                             final FieldEventHandler<T> handler, final FieldPVCoordinatesProvider<T> secondaryPVProvider,
  85.                                             final T distanceThreshold) {
  86.         super(maxCheck, threshold, maxIter, handler);
  87.         this.secondaryPVProvider = secondaryPVProvider;
  88.         this.distanceThreshold = distanceThreshold;
  89.     }

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

  103.     /** {@inheritDoc} */
  104.     @Override
  105.     protected FieldRelativeDistanceDetector<T> create(final FieldAdaptableInterval<T> newMaxCheck, final T newThreshold,
  106.                                                       final int newMaxIter, final FieldEventHandler<T> newHandler) {
  107.         return new FieldRelativeDistanceDetector<>(newMaxCheck, newThreshold, newMaxIter, newHandler, secondaryPVProvider,
  108.                 distanceThreshold);
  109.     }

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

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