FieldEventDetectionSettings.java

  1. /* Copyright 2022-2024 Romain Serra
  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.Field;
  20. import org.orekit.propagation.FieldSpacecraftState;

  21. /**
  22.  * Class containing parameters for event detection.
  23.  *
  24.  * @author Romain Serra.
  25.  * @since 12.2
  26.  * @see EventDetectionSettings
  27.  * @see FieldEventDetector
  28.  */
  29. public class FieldEventDetectionSettings <T extends CalculusFieldElement<T>> {

  30.     /** Default maximum checking interval (s). */
  31.     public static final double DEFAULT_MAXCHECK = 600;

  32.     /** Default convergence threshold (s). */
  33.     public static final double DEFAULT_THRESHOLD = 1.e-6;

  34.     /** Default maximum number of iterations in the event time search. */
  35.     public static final int DEFAULT_MAX_ITER = 100;

  36.     /** Adaptable interval for maximum time without event evaluation. */
  37.     private final FieldAdaptableInterval<T> maxCheckInterval;

  38.     /** Detection threshold (s). */
  39.     private final T threshold;

  40.     /** Maximum iteration number when detecting event. */
  41.     private final int maxIterationCount;

  42.     /**
  43.      * Constructor.
  44.      *
  45.      * @param maxCheckInterval  adaptable interval
  46.      * @param threshold         detection threshold on time
  47.      * @param maxIterationCount maximum iteration number
  48.      */
  49.     public FieldEventDetectionSettings(final FieldAdaptableInterval<T> maxCheckInterval, final T threshold,
  50.                                        final int maxIterationCount) {
  51.         this.maxCheckInterval = maxCheckInterval;
  52.         this.maxIterationCount = maxIterationCount;
  53.         this.threshold = threshold;
  54.     }

  55.     /**
  56.      * Constructor with maximum check as double.
  57.      *
  58.      * @param maxCheck          constant maximum check for adaptable interval
  59.      * @param threshold         detection threshold on time
  60.      * @param maxIterationCount maximum iteration number
  61.      */
  62.     public FieldEventDetectionSettings(final double maxCheck, final T threshold, final int maxIterationCount) {
  63.         this(FieldAdaptableInterval.of(maxCheck), threshold, maxIterationCount);
  64.     }

  65.     /**
  66.      * Constructor from non-Field settings.
  67.      *
  68.      * @param field field
  69.      * @param eventDetectionSettings non-Field detection settings
  70.      */
  71.     public FieldEventDetectionSettings(final Field<T> field, final EventDetectionSettings eventDetectionSettings) {
  72.         this(state -> eventDetectionSettings.getMaxCheckInterval().currentInterval(state.toSpacecraftState()),
  73.             field.getZero().newInstance(eventDetectionSettings.getThreshold()), eventDetectionSettings.getMaxIterationCount());
  74.     }

  75.     /**
  76.      * Getter for adaptable interval.
  77.      * @return adaptable interval
  78.      */
  79.     public FieldAdaptableInterval<T> getMaxCheckInterval() {
  80.         return maxCheckInterval;
  81.     }

  82.     /**
  83.      * Getter for threshold.
  84.      * @return threshold
  85.      */
  86.     public T getThreshold() {
  87.         return threshold;
  88.     }

  89.     /**
  90.      * Getter for max iter.
  91.      * @return max iter
  92.      */
  93.     public int getMaxIterationCount() {
  94.         return maxIterationCount;
  95.     }

  96.     /**
  97.      * Create a non-Field equivalent object.
  98.      * @return event detection settings
  99.      */
  100.     public EventDetectionSettings toEventDetectionSettings() {
  101.         return new EventDetectionSettings(state -> getMaxCheckInterval().currentInterval(new FieldSpacecraftState<>(getThreshold().getField(), state)),
  102.                 getThreshold().getReal(), getMaxIterationCount());
  103.     }
  104. }