NodeDetector.java

  1. /* Copyright 2002-2013 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.orekit.errors.OrekitException;
  19. import org.orekit.frames.Frame;
  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. /** Finder for node crossing events.
  25.  * <p>This class finds equator crossing events (i.e. ascending
  26.  * or descending node crossing).</p>
  27.  * <p>The default implementation behavior is to {@link
  28.  * org.orekit.propagation.events.handlers.EventHandler.Action#CONTINUE continue}
  29.  * propagation at descending node crossing and to {@link
  30.  * org.orekit.propagation.events.handlers.EventHandler.Action#STOP stop} propagation
  31.  * at ascending node crossing. This can be changed by calling
  32.  * {@link #withHandler(EventHandler)} after construction.</p>
  33.  * <p>Beware that node detection will fail for almost equatorial orbits. If
  34.  * for example a node detector is used to trigger an {@link
  35.  * org.orekit.forces.maneuvers.ImpulseManeuver ImpulseManeuver} and the maneuver
  36.  * turn the orbit plane to equator, then the detector may completely fail just
  37.  * after the maneuver has been performed! This is a real case that has been
  38.  * encountered during validation ...</p>
  39.  * @see org.orekit.propagation.Propagator#addEventDetector(EventDetector)
  40.  * @author Luc Maisonobe
  41.  */
  42. public class NodeDetector extends AbstractReconfigurableDetector<NodeDetector> {

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

  45.     /** Frame in which the equator is defined. */
  46.     private final Frame frame;

  47.     /** Build a new instance.
  48.      * <p>The orbit is used only to set an upper bound for the max check interval
  49.      * to period/3 and to set the convergence threshold according to orbit size.</p>
  50.      * @param orbit initial orbit
  51.      * @param frame frame in which the equator is defined (typical
  52.      * values are {@link org.orekit.frames.FramesFactory#getEME2000() J<sub>2000</sub>} or
  53.      * {@link org.orekit.frames.FramesFactory#getITRF2005() ITRF 2005})
  54.      */
  55.     public NodeDetector(final Orbit orbit, final Frame frame) {
  56.         this(1.0e-13 * orbit.getKeplerianPeriod(), orbit, frame);
  57.     }

  58.     /** Build a new instance.
  59.      * <p>The orbit is used only to set an upper bound for the max check interval
  60.      * to period/3.</p>
  61.      * @param threshold convergence threshold (s)
  62.      * @param orbit initial orbit
  63.      * @param frame frame in which the equator is defined (typical
  64.      * values are {@link org.orekit.frames.FramesFactory#getEME2000() J<sub>2000</sub>} or
  65.      * {@link org.orekit.frames.FramesFactory#getITRF2005() ITRF 2005})
  66.      */
  67.     public NodeDetector(final double threshold, final Orbit orbit, final Frame frame) {
  68.         this(orbit.getKeplerianPeriod() / 3, threshold,
  69.              DEFAULT_MAX_ITER, new StopOnIncreasing<NodeDetector>(),
  70.              frame);
  71.     }

  72.     /** Private constructor with full parameters.
  73.      * <p>
  74.      * This constructor is private as users are expected to use the builder
  75.      * API with the various {@code withXxx()} methods to set up the instance
  76.      * in a readable manner without using a huge amount of parameters.
  77.      * </p>
  78.      * @param maxCheck maximum checking interval (s)
  79.      * @param threshold convergence threshold (s)
  80.      * @param maxIter maximum number of iterations in the event time search
  81.      * @param handler event handler to call at event occurrences
  82.      * @param frame frame in which the equator is defined (typical
  83.      * values are {@link org.orekit.frames.FramesFactory#getEME2000() J<sub>2000</sub>} or
  84.      * {@link org.orekit.frames.FramesFactory#getITRF2005() ITRF 2005})
  85.      * @since 6.1
  86.      */
  87.     private NodeDetector(final double maxCheck, final double threshold,
  88.                          final int maxIter, final EventHandler<NodeDetector> handler,
  89.                          final Frame frame) {
  90.         super(maxCheck, threshold, maxIter, handler);
  91.         this.frame = frame;
  92.     }

  93.     /** {@inheritDoc} */
  94.     @Override
  95.     protected NodeDetector create(final double newMaxCheck, final double newThreshold,
  96.                                   final int newMaxIter, final EventHandler<NodeDetector> newHandler) {
  97.         return new NodeDetector(newMaxCheck, newThreshold, newMaxIter, newHandler, frame);
  98.     }

  99.     /** Get the frame in which the equator is defined.
  100.      * @return the frame in which the equator is defined
  101.      */
  102.     public Frame getFrame() {
  103.         return frame;
  104.     }

  105.     /** Compute the value of the switching function.
  106.      * This function computes the Z position in the defined frame.
  107.      * @param s the current state information: date, kinematics, attitude
  108.      * @return value of the switching function
  109.      * @exception OrekitException if some specific error occurs
  110.      */
  111.     public double g(final SpacecraftState s) throws OrekitException {
  112.         return s.getPVCoordinates(frame).getPosition().getZ();
  113.     }

  114. }