FieldEventDetectionSettings.java

  1. /* Copyright 2022-2025 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. import org.orekit.propagation.events.intervals.FieldAdaptableInterval;

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

  31.     /** Default maximum checking interval (s). */
  32.     public static final double DEFAULT_MAX_CHECK = EventDetectionSettings.DEFAULT_MAX_CHECK;

  33.     /** Default convergence threshold (s). */
  34.     public static final double DEFAULT_THRESHOLD = EventDetectionSettings.DEFAULT_THRESHOLD;

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

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

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

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

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

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

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

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

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

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

  97.     /**
  98.      * Builds a new instance with a new max. check interval.
  99.      * @param newMaxCheckInterval new max. check.
  100.      * @return new object
  101.      * @since 13.0
  102.      */
  103.     public FieldEventDetectionSettings<T> withMaxCheckInterval(final FieldAdaptableInterval<T> newMaxCheckInterval) {
  104.         return new FieldEventDetectionSettings<>(newMaxCheckInterval, threshold, maxIterationCount);
  105.     }

  106.     /**
  107.      * Builds a new instance with a new threshold value.
  108.      * @param newThreshold detection threshold in seconds
  109.      * @return new object
  110.      * @since 13.0
  111.      */
  112.     public FieldEventDetectionSettings<T> withThreshold(final T newThreshold) {
  113.         return new FieldEventDetectionSettings<>(maxCheckInterval, newThreshold, maxIterationCount);
  114.     }

  115.     /**
  116.      * Builds a new instance with a new max. iteration count.
  117.      * @param newMaxIterationCount new max iteration count.
  118.      * @return new object
  119.      * @since 13.0
  120.      */
  121.     public FieldEventDetectionSettings<T> withMaxIter(final int newMaxIterationCount) {
  122.         return new FieldEventDetectionSettings<>(maxCheckInterval, threshold, newMaxIterationCount);
  123.     }

  124.     /**
  125.      * Returns default settings for event detections.
  126.      * @param <T> field type
  127.      * @param field field
  128.      * @return default settings
  129.      * @since 13.0
  130.      */
  131.     public static <T extends CalculusFieldElement<T>> FieldEventDetectionSettings<T> getDefaultEventDetectionSettings(final Field<T> field) {
  132.         return new FieldEventDetectionSettings<>(FieldAdaptableInterval.of(DEFAULT_MAX_CHECK),
  133.                 field.getZero().newInstance(DEFAULT_THRESHOLD), DEFAULT_MAX_ITER);
  134.     }

  135.     /**
  136.      * Create a non-Field equivalent object.
  137.      * @return event detection settings
  138.      */
  139.     public EventDetectionSettings toEventDetectionSettings() {
  140.         return new EventDetectionSettings((state, isForward) -> getMaxCheckInterval().currentInterval(new FieldSpacecraftState<>(getThreshold().getField(), state), isForward),
  141.                 getThreshold().getReal(), getMaxIterationCount());
  142.     }
  143. }