1 /* Copyright 2022-2026 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
19 import org.hipparchus.CalculusFieldElement;
20 import org.hipparchus.Field;
21 import org.orekit.propagation.events.intervals.AdaptableInterval;
22 import org.orekit.propagation.events.intervals.FieldAdaptableInterval;
23
24 /**
25 * Class containing parameters for event detection.
26 *
27 * @param <T> type of the field elements
28 * @author Romain Serra.
29 * @since 12.2
30 * @see EventDetectionSettings
31 * @see FieldEventDetector
32 */
33 public class FieldEventDetectionSettings <T extends CalculusFieldElement<T>> {
34
35 /** Default maximum checking interval (s). */
36 public static final double DEFAULT_MAX_CHECK = EventDetectionSettings.DEFAULT_MAX_CHECK;
37
38 /** Default convergence threshold (s). */
39 public static final double DEFAULT_THRESHOLD = EventDetectionSettings.DEFAULT_THRESHOLD;
40
41 /** Default maximum number of iterations in the event time search. */
42 public static final int DEFAULT_MAX_ITER = EventDetectionSettings.DEFAULT_MAX_ITER;
43
44 /** Adaptable interval for maximum time without event evaluation. */
45 private final FieldAdaptableInterval<T> maxCheckInterval;
46
47 /** Detection threshold (s). */
48 private final T threshold;
49
50 /** Maximum iteration number when detecting event. */
51 private final int maxIterationCount;
52
53 /**
54 * Constructor.
55 *
56 * @param maxCheckInterval adaptable interval
57 * @param threshold detection threshold on time
58 * @param maxIterationCount maximum iteration number
59 */
60 public FieldEventDetectionSettings(final FieldAdaptableInterval<T> maxCheckInterval, final T threshold,
61 final int maxIterationCount) {
62 this.maxCheckInterval = maxCheckInterval;
63 this.maxIterationCount = maxIterationCount;
64 this.threshold = threshold;
65 }
66
67 /**
68 * Constructor with maximum check as double.
69 *
70 * @param maxCheck constant maximum check for adaptable interval
71 * @param threshold detection threshold on time
72 * @param maxIterationCount maximum iteration number
73 */
74 public FieldEventDetectionSettings(final double maxCheck, final T threshold, final int maxIterationCount) {
75 this(FieldAdaptableInterval.of(maxCheck), threshold, maxIterationCount);
76 }
77
78 /**
79 * Constructor from non-Field settings.
80 *
81 * @param field field
82 * @param eventDetectionSettings non-Field detection settings
83 */
84 public FieldEventDetectionSettings(final Field<T> field, final EventDetectionSettings eventDetectionSettings) {
85 this(FieldAdaptableInterval.of(eventDetectionSettings.getMaxCheckInterval()),
86 field.getZero().newInstance(eventDetectionSettings.getThreshold()), eventDetectionSettings.getMaxIterationCount());
87 }
88
89 /**
90 * Getter for adaptable interval.
91 * @return adaptable interval
92 */
93 public FieldAdaptableInterval<T> getMaxCheckInterval() {
94 return maxCheckInterval;
95 }
96
97 /**
98 * Getter for threshold.
99 * @return threshold
100 */
101 public T getThreshold() {
102 return threshold;
103 }
104
105 /**
106 * Getter for max iter.
107 * @return max iter
108 */
109 public int getMaxIterationCount() {
110 return maxIterationCount;
111 }
112
113 /**
114 * Builds a new instance with a new max. check interval.
115 * @param newMaxCheckInterval new max. check.
116 * @return new object
117 * @since 13.0
118 */
119 public FieldEventDetectionSettings<T> withMaxCheckInterval(final FieldAdaptableInterval<T> newMaxCheckInterval) {
120 return new FieldEventDetectionSettings<>(newMaxCheckInterval, threshold, maxIterationCount);
121 }
122
123 /**
124 * Builds a new instance with a new threshold value.
125 * @param newThreshold detection threshold in seconds
126 * @return new object
127 * @since 13.0
128 */
129 public FieldEventDetectionSettings<T> withThreshold(final T newThreshold) {
130 return new FieldEventDetectionSettings<>(maxCheckInterval, newThreshold, maxIterationCount);
131 }
132
133 /**
134 * Builds a new instance with a new max. iteration count.
135 * @param newMaxIterationCount new max iteration count.
136 * @return new object
137 * @since 13.0
138 */
139 public FieldEventDetectionSettings<T> withMaxIter(final int newMaxIterationCount) {
140 return new FieldEventDetectionSettings<>(maxCheckInterval, threshold, newMaxIterationCount);
141 }
142
143 /**
144 * Returns default settings for event detections.
145 * @param <T> field type
146 * @param field field
147 * @return default settings
148 * @since 13.0
149 */
150 public static <T extends CalculusFieldElement<T>> FieldEventDetectionSettings<T> getDefaultEventDetectionSettings(final Field<T> field) {
151 return new FieldEventDetectionSettings<>(field, EventDetectionSettings.getDefaultEventDetectionSettings());
152 }
153
154 /**
155 * Create a non-Field equivalent object.
156 * @return event detection settings
157 */
158 public EventDetectionSettings toEventDetectionSettings() {
159 return new EventDetectionSettings(AdaptableInterval.of(getThreshold().getField(), getMaxCheckInterval()),
160 getThreshold().getReal(), getMaxIterationCount());
161 }
162 }