1   /* Copyright 2002-2025 CS GROUP
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.geometry.euclidean.threed.Vector3D;
20  import org.hipparchus.util.FastMath;
21  import org.junit.jupiter.api.Assertions;
22  import org.junit.jupiter.api.BeforeEach;
23  import org.junit.jupiter.api.Test;
24  import org.orekit.Utils;
25  import org.orekit.bodies.GeodeticPoint;
26  import org.orekit.bodies.OneAxisEllipsoid;
27  import org.orekit.frames.FramesFactory;
28  import org.orekit.frames.TopocentricFrame;
29  import org.orekit.orbits.EquinoctialOrbit;
30  import org.orekit.orbits.Orbit;
31  import org.orekit.propagation.Propagator;
32  import org.orekit.propagation.analytical.EcksteinHechlerPropagator;
33  import org.orekit.propagation.events.EventsLogger.LoggedEvent;
34  import org.orekit.propagation.events.handlers.ContinueOnEvent;
35  import org.orekit.time.AbsoluteDate;
36  import org.orekit.time.TimeScale;
37  import org.orekit.time.TimeScalesFactory;
38  import org.orekit.utils.Constants;
39  import org.orekit.utils.IERSConventions;
40  import org.orekit.utils.PVCoordinates;
41  
42  public class ElevationExtremumDetectorTest {
43  
44      @Test
45      public void testLEO() {
46  
47          final OneAxisEllipsoid earth = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS,
48                                                              Constants.WGS84_EARTH_FLATTENING,
49                                                              FramesFactory.getITRF(IERSConventions.IERS_2010, true));
50  
51          final GeodeticPoint gp = new GeodeticPoint(FastMath.toRadians(51.0), FastMath.toRadians(66.6), 300.0);
52          final ElevationExtremumDetector raw =
53                  new ElevationExtremumDetector(new TopocentricFrame(earth, gp, "test")).
54                  withMaxCheck(60).
55                  withThreshold(1.e-6).
56                  withHandler(new ContinueOnEvent());
57          final EventSlopeFilter<ElevationExtremumDetector> maxElevationDetector =
58                  new EventSlopeFilter<>(raw, FilterType.TRIGGER_ONLY_DECREASING_EVENTS);
59  
60          Assertions.assertEquals(60.0, raw.getMaxCheckInterval().currentInterval(null, true), 1.0e-15);
61          Assertions.assertEquals(1.0e-6, raw.getThreshold(), 1.0e-15);
62          Assertions.assertEquals(AbstractDetector.DEFAULT_MAX_ITER, raw.getMaxIterationCount());
63          Assertions.assertEquals("test", raw.getTopocentricFrame().getName());
64  
65          final TimeScale utc = TimeScalesFactory.getUTC();
66          final Vector3D position = new Vector3D(-6142438.668, 3492467.56, -25767.257);
67          final Vector3D velocity = new Vector3D(505.848, 942.781, 7435.922);
68          final AbsoluteDate date = new AbsoluteDate(2003, 9, 16, utc);
69          final Orbit orbit = new EquinoctialOrbit(new PVCoordinates(position,  velocity),
70                                                   FramesFactory.getEME2000(), date,
71                                                   Constants.EIGEN5C_EARTH_MU);
72  
73          Propagator propagator =
74              new EcksteinHechlerPropagator(orbit,
75                                            Constants.EIGEN5C_EARTH_EQUATORIAL_RADIUS,
76                                            Constants.EIGEN5C_EARTH_MU,
77                                            Constants.EIGEN5C_EARTH_C20,
78                                            Constants.EIGEN5C_EARTH_C30,
79                                            Constants.EIGEN5C_EARTH_C40,
80                                            Constants.EIGEN5C_EARTH_C50,
81                                            Constants.EIGEN5C_EARTH_C60);
82  
83          EventsLogger logger = new EventsLogger();
84          propagator.addEventDetector(logger.monitorDetector(maxElevationDetector));
85  
86          propagator.propagate(date.shiftedBy(Constants.JULIAN_DAY));
87          int visibleEvents = 0;
88          for (LoggedEvent e : logger.getLoggedEvents()) {
89              final double eMinus = raw.getElevation(e.getState().shiftedBy(-10.0));
90              final double e0     = raw.getElevation(e.getState());
91              final double ePlus  = raw.getElevation(e.getState().shiftedBy(+10.0));
92              if (e0 > FastMath.toRadians(5.0)) {
93                  ++visibleEvents;
94              }
95              Assertions.assertTrue(e0 > eMinus);
96              Assertions.assertTrue(e0 > ePlus);
97          }
98          Assertions.assertEquals(15, logger.getLoggedEvents().size());
99          Assertions.assertEquals( 6, visibleEvents);
100 
101     }
102 
103     @BeforeEach
104     public void setUp() {
105         Utils.setDataRoot("regular-data");
106     }
107 
108 }