ApsideDetector.java

  1. /* Copyright 2002-2018 CS Systèmes d'Information
  2.  * Licensed to CS Systèmes d'Information (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.geometry.euclidean.threed.Vector3D;
  19. import org.orekit.errors.OrekitException;
  20. import org.orekit.orbits.Orbit;
  21. import org.orekit.propagation.SpacecraftState;
  22. import org.orekit.propagation.events.handlers.EventHandler;
  23. import org.orekit.propagation.events.handlers.StopOnIncreasing;
  24. import org.orekit.utils.PVCoordinates;

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

  42.     /** Serializable UID. */
  43.     private static final long serialVersionUID = 20131118L;

  44.     /** Build a new instance.
  45.      * <p>The orbit is used only to set an upper bound for the
  46.      * max check interval to period/3 and to set the convergence
  47.      * threshold according to orbit size</p>
  48.      * @param orbit initial orbit
  49.      */
  50.     public ApsideDetector(final Orbit orbit) {
  51.         this(1.0e-13 * orbit.getKeplerianPeriod(), orbit);
  52.     }

  53.     /** Build a new instance.
  54.      * <p>The orbit is used only to set an upper bound for the
  55.      * max check interval to period/3</p>
  56.      * @param threshold convergence threshold (s)
  57.      * @param orbit initial orbit
  58.      */
  59.     public ApsideDetector(final double threshold, final Orbit orbit) {
  60.         super(orbit.getKeplerianPeriod() / 3, threshold,
  61.               DEFAULT_MAX_ITER, new StopOnIncreasing<ApsideDetector>());
  62.     }

  63.     /** Private constructor with full parameters.
  64.      * <p>
  65.      * This constructor is private as users are expected to use the builder
  66.      * API with the various {@code withXxx()} methods to set up the instance
  67.      * in a readable manner without using a huge amount of parameters.
  68.      * </p>
  69.      * @param maxCheck maximum checking interval (s)
  70.      * @param threshold convergence threshold (s)
  71.      * @param maxIter maximum number of iterations in the event time search
  72.      * @param handler event handler to call at event occurrences
  73.      * @since 6.1
  74.      */
  75.     private ApsideDetector(final double maxCheck, final double threshold,
  76.                            final int maxIter, final EventHandler<? super ApsideDetector> handler) {
  77.         super(maxCheck, threshold, maxIter, handler);
  78.     }

  79.     /** {@inheritDoc} */
  80.     @Override
  81.     protected ApsideDetector create(final double newMaxCheck, final double newThreshold,
  82.                                     final int newMaxIter, final EventHandler<? super ApsideDetector> newHandler) {
  83.         return new ApsideDetector(newMaxCheck, newThreshold, newMaxIter, newHandler);
  84.     }

  85.     /** Compute the value of the switching function.
  86.      * This function computes the dot product of the 2 vectors : position.velocity.
  87.      * @param s the current state information: date, kinematics, attitude
  88.      * @return value of the switching function
  89.      * @exception OrekitException if some specific error occurs
  90.      */
  91.     public double g(final SpacecraftState s) throws OrekitException {
  92.         final PVCoordinates pv = s.getPVCoordinates();
  93.         return Vector3D.dotProduct(pv.getPosition(), pv.getVelocity());
  94.     }

  95. }