1 /* Copyright 2022-2025 Luc Maisonobe
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
18 package org.orekit.propagation.events.intervals;
19
20 import org.hipparchus.CalculusFieldElement;
21 import org.hipparchus.Field;
22 import org.hipparchus.util.FastMath;
23 import org.orekit.propagation.FieldSpacecraftState;
24 import org.orekit.propagation.SpacecraftState;
25 import org.orekit.propagation.events.EventDetector;
26
27 /** This interface represents an event checking interval that depends on state.
28 *
29 * @see EventDetector
30 * @author Luc Maisonobe
31 * @since 12.0
32 *
33 */
34 @FunctionalInterface
35 public interface AdaptableInterval {
36
37 /**
38 * Get the current value of maximal time interval between events handler checks.
39 *
40 * @param state current state
41 * @param isForward direction of propagation
42 * @return current value of maximal time interval between events handler checks
43 */
44 double currentInterval(SpacecraftState state, boolean isForward);
45
46 /**
47 * Method creating an interval taking the minimum value of all candidates.
48 * @param defaultMaxCheck default value if no intervals is given as input
49 * @param adaptableIntervals intervals
50 * @return adaptable interval ready to be added to an event detector
51 * @since 13.0
52 */
53 static AdaptableInterval of(final double defaultMaxCheck, final AdaptableInterval... adaptableIntervals) {
54 return (state, isForward) -> {
55 double maxCheck = defaultMaxCheck;
56 for (final AdaptableInterval interval : adaptableIntervals) {
57 maxCheck = FastMath.min(maxCheck, interval.currentInterval(state, isForward));
58 }
59 return maxCheck;
60 };
61 }
62
63 /**
64 * Method creating an interval taking the minimum value of all candidates.
65 * @param field field
66 * @param fieldAdaptableInterval field interval
67 * @param <T> field type
68 * @return adaptable interval ready to be added to an event detector
69 * @since 14.0
70 */
71 static <T extends CalculusFieldElement<T>> AdaptableInterval of(final Field<T> field,
72 final FieldAdaptableInterval<T> fieldAdaptableInterval) {
73 return (state, isForward) -> fieldAdaptableInterval.currentInterval(new FieldSpacecraftState<>(field, state), isForward);
74 }
75 }