FieldApsideDetector.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.hipparchus.ode.events.Action;
  21. import org.orekit.orbits.FieldOrbit;
  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.FieldPVCoordinates;

  26. /** Finder for apside crossing events.
  27.  * <p>This class finds apside crossing events (i.e. apogee or perigee crossing).</p>
  28.  * <p>The default implementation behavior is to {@link Action#CONTINUE continue}
  29.  * propagation at apogee crossing and to {@link Action#STOP stop} propagation
  30.  * at perigee crossing. This can be changed by calling
  31.  * {@link #withHandler(FieldEventHandler)} after construction.</p>
  32.  * <p>Beware that apside detection will fail for almost circular orbits. If
  33.  * for example an apside detector is used to trigger an {@link
  34.  * org.orekit.forces.maneuvers.ImpulseManeuver ImpulseManeuver} and the maneuver
  35.  * change the orbit shape to circular, then the detector may completely fail just
  36.  * after the maneuver has been performed!</p>
  37.  * @see org.orekit.propagation.FieldPropagator#addEventDetector(FieldEventDetector)
  38.  * @author Luc Maisonobe
  39.  * @param <T> type of the field elements
  40.  */
  41. public class FieldApsideDetector<T extends CalculusFieldElement<T>> extends FieldAbstractDetector<FieldApsideDetector<T>, T> {

  42.     /** Build a new instance.
  43.      * <p>The Keplerian period is used only to set an upper bound for the
  44.      * max check interval to period/3 and to set the convergence threshold.</p>
  45.      * @param keplerianPeriod estimate of the Keplerian period
  46.      * @since 12.1
  47.      */
  48.     public FieldApsideDetector(final T keplerianPeriod) {
  49.         super(new FieldEventDetectionSettings<>(keplerianPeriod.divide(3).getReal(), keplerianPeriod.multiply(1e-13),
  50.             DEFAULT_MAX_ITER), new FieldStopOnIncreasing<>());
  51.     }

  52.     /** Build a new instance.
  53.      * <p>The orbit is used only to set an upper bound for the
  54.      * max check interval to period/3 and to set the convergence
  55.      * threshold according to orbit size</p>
  56.      * @param orbit initial orbit
  57.      */
  58.     public FieldApsideDetector(final FieldOrbit<T> orbit) {
  59.         this(orbit.getKeplerianPeriod());
  60.     }

  61.     /** Build a new instance.
  62.      * <p>The orbit is used only to set an upper bound for the
  63.      * max check interval to period/3</p>
  64.      * @param threshold convergence threshold (s)
  65.      * @param orbit initial orbit
  66.      */
  67.     public FieldApsideDetector(final T threshold, final FieldOrbit<T> orbit) {
  68.         super(new FieldEventDetectionSettings<>(orbit.getKeplerianPeriod().divide(3).getReal(), threshold,
  69.               DEFAULT_MAX_ITER), new FieldStopOnIncreasing<>());
  70.     }

  71.     /** Constructor with full parameters.
  72.      * <p>
  73.      * This constructor is public because otherwise all accessible ones would require an orbit.
  74.      * </p>
  75.      * @param detectionSettings event detection settings
  76.      * @param handler event handler to call at event occurrences
  77.      * @since 13.0
  78.      */
  79.     public FieldApsideDetector(final FieldEventDetectionSettings<T> detectionSettings,
  80.                                final FieldEventHandler<T> handler) {
  81.         super(detectionSettings, handler);
  82.     }

  83.     /** {@inheritDoc} */
  84.     @Override
  85.     protected FieldApsideDetector<T> create(final FieldEventDetectionSettings<T> detectionSettings,
  86.                                             final FieldEventHandler<T> newHandler) {
  87.         return new FieldApsideDetector<>(detectionSettings, newHandler);
  88.     }

  89.     /** Compute the value of the switching function.
  90.      * This function computes the dot product of the 2 vectors : position.velocity.
  91.      * @param s the current state information: date, kinematics, attitude
  92.      * @return value of the switching function
  93.      */
  94.     public T g(final FieldSpacecraftState<T> s) {
  95.         final FieldPVCoordinates<T> pv = s.getPVCoordinates();
  96.         return FieldVector3D.dotProduct(pv.getPosition(), pv.getVelocity());
  97.     }

  98. }