FieldNegateDetector.java

  1. /* Contributed in the public domain.
  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.orekit.propagation.FieldSpacecraftState;
  20. import org.orekit.propagation.events.handlers.FieldContinueOnEvent;
  21. import org.orekit.propagation.events.handlers.FieldEventHandler;
  22. import org.orekit.time.FieldAbsoluteDate;

  23. /**
  24.  * An event detector that negates the sign on another event detector's {@link
  25.  * FieldEventDetector#g(FieldSpacecraftState) g} function.
  26.  *
  27.  * @since 12.0
  28.  * @param <T> type of the field element
  29.  * @author Evan Ward
  30.  * @author Luc Maisonobe
  31.  */
  32. public class FieldNegateDetector<T extends CalculusFieldElement<T>>  extends FieldAbstractDetector<FieldNegateDetector<T>, T> {

  33.     /** the delegate event detector. */
  34.     private final FieldEventDetector<T> original;

  35.     /**
  36.      * Create a new event detector that negates an existing event detector.
  37.      *
  38.      * <p> This detector will be initialized with the same {@link
  39.      * FieldEventDetector#getMaxCheckInterval()}, {@link FieldEventDetector#getThreshold()}, and
  40.      * {@link FieldEventDetector#getMaxIterationCount()} as {@code original}. Initially this
  41.      * detector will use the {@link FieldContinueOnEvent} event handler.
  42.      *
  43.      * @param original detector.
  44.      */
  45.     public FieldNegateDetector(final FieldEventDetector<T> original) {
  46.         this(original.getMaxCheckInterval(),
  47.              original.getThreshold(),
  48.              original.getMaxIterationCount(),
  49.              new FieldContinueOnEvent<>(),
  50.              original);
  51.     }

  52.     /**
  53.      * Private constructor.
  54.      *
  55.      * @param newMaxCheck  max check interval.
  56.      * @param newThreshold convergence threshold in seconds.
  57.      * @param newMaxIter   max iterations.
  58.      * @param newHandler   event handler.
  59.      * @param original     event detector.
  60.      */
  61.     protected FieldNegateDetector(final FieldAdaptableInterval<T> newMaxCheck,
  62.                                   final T newThreshold,
  63.                                   final int newMaxIter,
  64.                                   final FieldEventHandler<T> newHandler,
  65.                                   final FieldEventDetector<T> original) {
  66.         super(newMaxCheck, newThreshold, newMaxIter, newHandler);
  67.         this.original = original;
  68.     }

  69.     /**
  70.      * Get the delegate event detector.
  71.      * @return the delegate event detector
  72.      */
  73.     public FieldEventDetector<T> getOriginal() {
  74.         return original;
  75.     }

  76.     @Override
  77.     public void init(final FieldSpacecraftState<T> s0,
  78.                      final FieldAbsoluteDate<T> t) {
  79.         super.init(s0, t);
  80.         original.init(s0, t);
  81.     }

  82.     @Override
  83.     public T g(final FieldSpacecraftState<T> s) {
  84.         return original.g(s).negate();
  85.     }

  86.     @Override
  87.     protected FieldNegateDetector<T> create(final FieldAdaptableInterval<T> newMaxCheck,
  88.                                             final T newThreshold,
  89.                                             final int newMaxIter,
  90.                                             final FieldEventHandler<T> newHandler) {
  91.         return new FieldNegateDetector<>(newMaxCheck, newThreshold, newMaxIter, newHandler,
  92.                                          original);
  93.     }

  94. }