1   /* Copyright 2002-2022 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.hipparchus.util.MathUtils;
22  import org.junit.Assert;
23  import org.junit.Before;
24  import org.junit.Test;
25  import org.orekit.Utils;
26  import org.orekit.frames.FramesFactory;
27  import org.orekit.orbits.CartesianOrbit;
28  import org.orekit.orbits.KeplerianOrbit;
29  import org.orekit.orbits.Orbit;
30  import org.orekit.orbits.OrbitType;
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.PVCoordinates;
40  
41  public class ApsideDetectorTest {
42  
43      private Propagator propagator;
44  
45      @Test
46      public void testSimple() {
47          EventDetector detector = new ApsideDetector(propagator.getInitialState().getOrbit()).
48                                   withMaxCheck(600.0).
49                                   withThreshold(1.0e-12).
50                                   withHandler(new ContinueOnEvent<ApsideDetector>());
51  
52          Assert.assertEquals(600.0, detector.getMaxCheckInterval(), 1.0e-15);
53          Assert.assertEquals(1.0e-12, detector.getThreshold(), 1.0e-15);
54          Assert.assertEquals(AbstractDetector.DEFAULT_MAX_ITER, detector.getMaxIterationCount());
55  
56  
57          EventsLogger logger = new EventsLogger();
58          propagator.addEventDetector(logger.monitorDetector(detector));
59  
60          propagator.propagate(propagator.getInitialState().getOrbit().getDate().shiftedBy(Constants.JULIAN_DAY));
61  
62          Assert.assertEquals(30, logger.getLoggedEvents().size());
63          for (LoggedEvent e : logger.getLoggedEvents()) {
64              KeplerianOrbit o = (KeplerianOrbit) OrbitType.KEPLERIAN.convertType(e.getState().getOrbit());
65              double expected = e.isIncreasing() ? 0.0 : FastMath.PI;
66              Assert.assertEquals(expected, MathUtils.normalizeAngle(o.getMeanAnomaly(), expected), 4.0e-14);
67          }
68  
69      }
70  
71      @Before
72      public void setUp() {
73          Utils.setDataRoot("regular-data");
74          final TimeScale utc = TimeScalesFactory.getUTC();
75          final Vector3D position = new Vector3D(-6142438.668, 3492467.56, -25767.257);
76          final Vector3D velocity = new Vector3D(506.0, 943.0, 7450);
77          final AbsoluteDate date = new AbsoluteDate(2003, 9, 16, utc);
78          final Orbit orbit = new CartesianOrbit(new PVCoordinates(position,  velocity),
79                                                 FramesFactory.getEME2000(), date,
80                                                 Constants.EIGEN5C_EARTH_MU);
81  
82          propagator =
83              new EcksteinHechlerPropagator(orbit,
84                                            Constants.EIGEN5C_EARTH_EQUATORIAL_RADIUS,
85                                            Constants.EIGEN5C_EARTH_MU,
86                                            Constants.EIGEN5C_EARTH_C20,
87                                            Constants.EIGEN5C_EARTH_C30,
88                                            Constants.EIGEN5C_EARTH_C40,
89                                            Constants.EIGEN5C_EARTH_C50,
90                                            Constants.EIGEN5C_EARTH_C60);
91      }
92  
93  }
94