1 /* Copyright 2002-2024 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 package org.orekit.propagation.events;
18
19 import org.hipparchus.CalculusFieldElement;
20 import org.hipparchus.Field;
21 import org.hipparchus.analysis.differentiation.FieldUnivariateDerivative1;
22 import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
23 import org.hipparchus.ode.events.FieldEventSlopeFilter;
24 import org.orekit.frames.FieldKinematicTransform;
25 import org.orekit.frames.TopocentricFrame;
26 import org.orekit.propagation.FieldSpacecraftState;
27 import org.orekit.propagation.events.handlers.FieldEventHandler;
28 import org.orekit.propagation.events.handlers.FieldStopOnIncreasing;
29 import org.orekit.utils.TimeStampedFieldPVCoordinates;
30
31 /** Detector for elevation extremum with respect to a ground point.
32 * <p>This detector identifies when a spacecraft reaches its
33 * extremum elevation with respect to a ground point.</p>
34 * <p>
35 * As in most cases only the elevation maximum is needed and the
36 * minimum is often irrelevant, this detector is often wrapped into
37 * an {@link FieldEventSlopeFilter event slope filter} configured with
38 * {@link FilterType#TRIGGER_ONLY_DECREASING_EVENTS} (i.e. when the
39 * elevation derivative decreases from positive values to negative values,
40 * which correspond to a maximum). Setting up this filter saves some computation
41 * time as the elevation minimum occurrences are not even looked at. It is
42 * however still often necessary to do an additional filtering
43 * </p>
44 * @param <T> type of the field element
45 * @author Luc Maisonobe
46 * @since 12.0
47 */
48 public class FieldElevationExtremumDetector<T extends CalculusFieldElement<T>>
49 extends FieldAbstractDetector<FieldElevationExtremumDetector<T>, T> {
50
51 /** Topocentric frame in which elevation should be evaluated. */
52 private final TopocentricFrame topo;
53
54 /** Build a new detector.
55 * <p>The new instance uses default values for maximal checking interval
56 * ({@link #DEFAULT_MAXCHECK}) and convergence threshold ({@link
57 * #DEFAULT_THRESHOLD}).</p>
58 * @param field field to which elements belong
59 * @param topo topocentric frame centered on ground point
60 */
61 public FieldElevationExtremumDetector(final Field<T> field, final TopocentricFrame topo) {
62 this(field.getZero().newInstance(DEFAULT_MAXCHECK),
63 field.getZero().newInstance(DEFAULT_THRESHOLD),
64 topo);
65 }
66
67 /** Build a detector.
68 * @param maxCheck maximal checking interval (s)
69 * @param threshold convergence threshold (s)
70 * @param topo topocentric frame centered on ground point
71 */
72 public FieldElevationExtremumDetector(final T maxCheck, final T threshold,
73 final TopocentricFrame topo) {
74 this(FieldAdaptableInterval.of(maxCheck.getReal()), threshold, DEFAULT_MAX_ITER, new FieldStopOnIncreasing<>(),
75 topo);
76 }
77
78 /** Protected constructor with full parameters.
79 * <p>
80 * This constructor is not public as users are expected to use the builder
81 * API with the various {@code withXxx()} methods to set up the instance
82 * in a readable manner without using a huge amount of parameters.
83 * </p>
84 * @param maxCheck maximum checking interval
85 * @param threshold convergence threshold (s)
86 * @param maxIter maximum number of iterations in the event time search
87 * @param handler event handler to call at event occurrences
88 * @param topo topocentric frame centered on ground point
89 */
90 protected FieldElevationExtremumDetector(final FieldAdaptableInterval<T> maxCheck, final T threshold,
91 final int maxIter, final FieldEventHandler<T> handler,
92 final TopocentricFrame topo) {
93 super(maxCheck, threshold, maxIter, handler);
94 this.topo = topo;
95 }
96
97 /** {@inheritDoc} */
98 @Override
99 protected FieldElevationExtremumDetector<T> create(final FieldAdaptableInterval<T> newMaxCheck, final T newThreshold,
100 final int newMaxIter,
101 final FieldEventHandler<T> newHandler) {
102 return new FieldElevationExtremumDetector<>(newMaxCheck, newThreshold, newMaxIter, newHandler, topo);
103 }
104
105 /**
106 * Returns the topocentric frame centered on ground point.
107 * @return topocentric frame centered on ground point
108 */
109 public TopocentricFrame getTopocentricFrame() {
110 return this.topo;
111 }
112
113 /** Get the elevation value.
114 * @param s the current state information: date, kinematics, attitude
115 * @return spacecraft elevation
116 */
117 public T getElevation(final FieldSpacecraftState<T> s) {
118 return topo.getElevation(s.getPosition(), s.getFrame(), s.getDate());
119 }
120
121 /** Compute the value of the detection function.
122 * <p>
123 * The value is the spacecraft elevation first time derivative.
124 * </p>
125 * @param s the current state information: date, kinematics, attitude
126 * @return spacecraft elevation first time derivative
127 */
128 public T g(final FieldSpacecraftState<T> s) {
129
130 // get position, velocity acceleration of spacecraft in topocentric frame
131 final FieldKinematicTransform<T> inertToTopo = s.getFrame().getKinematicTransformTo(topo, s.getDate());
132 final TimeStampedFieldPVCoordinates<T> pvTopo = inertToTopo.transformOnlyPV(s.getPVCoordinates());
133
134 // convert the coordinates to UnivariateDerivative1 based vector
135 // instead of having vector position, then vector velocity then vector acceleration
136 // we get one vector and each coordinate is a DerivativeStructure containing
137 // value, first time derivative (we don't need second time derivative here)
138 final FieldVector3D<FieldUnivariateDerivative1<T>> pvDS = pvTopo.toUnivariateDerivative1Vector();
139
140 // compute elevation and its first time derivative
141 final FieldUnivariateDerivative1<T> elevation = pvDS.getZ().divide(pvDS.getNorm()).asin();
142
143 // return elevation first time derivative
144 return elevation.getDerivative(1);
145
146 }
147
148 }