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.util.FastMath;
20  import org.junit.jupiter.api.AfterEach;
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.BodyShape;
26  import org.orekit.bodies.GeodeticPoint;
27  import org.orekit.bodies.OneAxisEllipsoid;
28  import org.orekit.frames.FramesFactory;
29  import org.orekit.frames.TopocentricFrame;
30  import org.orekit.orbits.KeplerianOrbit;
31  import org.orekit.orbits.Orbit;
32  import org.orekit.orbits.PositionAngleType;
33  import org.orekit.propagation.analytical.KeplerianPropagator;
34  import org.orekit.propagation.events.handlers.CountAndContinue;
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  
41  public class BackAndForthDetectorTest {
42  
43      @Test
44      public void testBackAndForth() {
45  
46          final TimeScale utc = TimeScalesFactory.getUTC();
47  
48          final AbsoluteDate date0 = new AbsoluteDate(2006, 12, 27, 12,  0, 0.0, utc);
49          final AbsoluteDate date1 = new AbsoluteDate(2006, 12, 27, 22, 50, 0.0, utc);
50          final AbsoluteDate date2 = new AbsoluteDate(2006, 12, 27, 22, 58, 0.0, utc);
51  
52          // Orbit
53          final double a = 7274000.;
54          final double e = 0.00127;
55          final double i = FastMath.toRadians(90.);
56          final double w = FastMath.toRadians(0.);
57          final double raan = FastMath.toRadians(12.5);
58          final double lM = FastMath.toRadians(60.);
59          Orbit iniOrb = new KeplerianOrbit(a, e, i, w, raan, lM,
60                                            PositionAngleType.MEAN, FramesFactory.getEME2000(), date0,
61                                            Constants.WGS84_EARTH_MU);
62  
63          // Propagator
64          KeplerianPropagator propagator = new KeplerianPropagator(iniOrb);
65  
66          // Station
67          final GeodeticPoint stationPosition = new GeodeticPoint(FastMath.toRadians(0.), FastMath.toRadians(100.), 110.);
68          final BodyShape earth = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS,
69                                                       Constants.WGS84_EARTH_FLATTENING,
70                                                       FramesFactory.getITRF(IERSConventions.IERS_2010, true));
71          final TopocentricFrame stationFrame = new TopocentricFrame(earth, stationPosition, "");
72  
73          // Detector
74          final CountAndContinue handler = new CountAndContinue();
75          propagator.addEventDetector(new ElevationDetector(stationFrame).
76                                      withConstantElevation(FastMath.toRadians(10.)).
77                                      withHandler(handler));
78  
79          // Forward propagation (AOS + LOS)
80          propagator.propagate(date1);
81          propagator.propagate(date2);
82          // Backward propagation (AOS + LOS)
83          propagator.propagate(date1);
84          propagator.propagate(date0);
85  
86          Assertions.assertEquals(4, handler.getCount());
87  
88      }
89  
90      @BeforeEach
91      public void setUp() {
92          Utils.setDataRoot("regular-data");
93      }
94  
95      @AfterEach
96      public void tearDown() {
97      }
98  
99  }
100