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.ode.nonstiff.AdaptiveStepsizeIntegrator;
21  import org.hipparchus.ode.nonstiff.DormandPrince853Integrator;
22  import org.hipparchus.util.FastMath;
23  import org.junit.jupiter.api.AfterEach;
24  import org.junit.jupiter.api.Assertions;
25  import org.junit.jupiter.api.BeforeEach;
26  import org.junit.jupiter.api.Test;
27  import org.orekit.Utils;
28  import org.orekit.bodies.CelestialBodyFactory;
29  import org.orekit.errors.OrekitException;
30  import org.orekit.frames.FramesFactory;
31  import org.orekit.orbits.EquinoctialOrbit;
32  import org.orekit.orbits.Orbit;
33  import org.orekit.propagation.SpacecraftState;
34  import org.orekit.propagation.numerical.NumericalPropagator;
35  import org.orekit.time.AbsoluteDate;
36  import org.orekit.time.TimeScalesFactory;
37  import org.orekit.utils.PVCoordinates;
38  import org.orekit.utils.PVCoordinatesProvider;
39  
40  public class AlignmentDetectorTest {
41  
42      private AbsoluteDate         iniDate;
43      private SpacecraftState      initialState;
44      private NumericalPropagator  propagator;
45  
46      @Test
47      public void testAlignment() {
48  
49          double alignAngle = FastMath.toRadians(0.0);
50          PVCoordinatesProvider sun = CelestialBodyFactory.getSun();
51          AlignmentDetector alignDetector =
52              new AlignmentDetector(initialState.getOrbit(), sun, alignAngle).
53              withMaxCheck(60.0);
54          Assertions.assertEquals(alignAngle, alignDetector.getAlignAngle(), 1.0e-15);
55          Assertions.assertSame(sun, alignDetector.getPVCoordinatesProvider());
56          Assertions.assertEquals(60.0, alignDetector.getMaxCheckInterval().currentInterval(null, true), 1.0e-15);
57          propagator.addEventDetector(alignDetector);
58          final SpacecraftState finalState = propagator.propagate(iniDate.shiftedBy(6000));
59          Assertions.assertEquals(383.3662, finalState.getDate().durationFrom(iniDate), 1.0e-3);
60  
61      }
62  
63      @BeforeEach
64      public void setUp() {
65          try {
66              Utils.setDataRoot("regular-data");
67              double mu = 3.9860047e14;
68              final Vector3D position  = new Vector3D(-6142438.668, 3492467.560, -25767.25680);
69              final Vector3D velocity  = new Vector3D(505.8479685, 942.7809215, 7435.922231);
70              iniDate = new AbsoluteDate(1969, 7, 28, 4, 0, 0.0, TimeScalesFactory.getTT());
71              final Orbit orbit = new EquinoctialOrbit(new PVCoordinates(position,  velocity),
72                                                       FramesFactory.getEME2000(), iniDate, mu);
73              initialState = new SpacecraftState(orbit);
74              double[] absTolerance = {
75                  0.001, 1.0e-9, 1.0e-9, 1.0e-6, 1.0e-6, 1.0e-6, 0.001
76              };
77              double[] relTolerance = {
78                  1.0e-7, 1.0e-4, 1.0e-4, 1.0e-7, 1.0e-7, 1.0e-7, 1.0e-7
79              };
80              AdaptiveStepsizeIntegrator integrator =
81                  new DormandPrince853Integrator(0.001, 1000, absTolerance, relTolerance);
82              integrator.setInitialStepSize(60);
83              propagator = new NumericalPropagator(integrator);
84              propagator.setInitialState(initialState);
85          } catch (OrekitException oe) {
86              Assertions.fail(oe.getLocalizedMessage());
87          }
88      }
89  
90      @AfterEach
91      public void tearDown() {
92          iniDate = null;
93          initialState = null;
94          propagator = null;
95      }
96  
97  }
98