FieldApsideDetector.java

  1. /* Copyright 2002-2023 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 orbit is used only to set an upper bound for the
  44.      * max check interval to period/3 and to set the convergence
  45.      * threshold according to orbit size</p>
  46.      * @param orbit initial orbit
  47.      */
  48.     public FieldApsideDetector(final FieldOrbit<T> orbit) {
  49.         this(orbit.getKeplerianPeriod().multiply(1.0e-13), orbit);
  50.     }

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

  61.     /** Protected constructor with full parameters.
  62.      * <p>
  63.      * This constructor is not public as users are expected to use the builder
  64.      * API with the various {@code withXxx()} methods to set up the instance
  65.      * in a readable manner without using a huge amount of parameters.
  66.      * </p>
  67.      * @param maxCheck maximum checking interval
  68.      * @param threshold convergence threshold (s)
  69.      * @param maxIter maximum number of iterations in the event time search
  70.      * @param handler event handler to call at event occurrences
  71.      */
  72.     protected FieldApsideDetector(final FieldAdaptableInterval<T> maxCheck, final T threshold,
  73.                                   final int maxIter, final FieldEventHandler<T> handler) {
  74.         super(maxCheck, threshold, maxIter, handler);
  75.     }

  76.     /** {@inheritDoc} */
  77.     @Override
  78.     protected FieldApsideDetector<T> create(final FieldAdaptableInterval<T> newMaxCheck, final T newThreshold,
  79.                                             final int newMaxIter,
  80.                                             final FieldEventHandler<T> newHandler) {
  81.         return new FieldApsideDetector<>(newMaxCheck, newThreshold, newMaxIter, newHandler);
  82.     }

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

  92. }