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