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.handlers;
18  
19  import org.hipparchus.CalculusFieldElement;
20  import org.hipparchus.Field;
21  import org.hipparchus.ode.events.Action;
22  import org.hipparchus.util.Binary64Field;
23  import org.junit.jupiter.api.Assertions;
24  import org.junit.jupiter.api.Test;
25  import org.orekit.frames.FramesFactory;
26  import org.orekit.orbits.FieldKeplerianOrbit;
27  import org.orekit.orbits.PositionAngleType;
28  import org.orekit.propagation.FieldSpacecraftState;
29  import org.orekit.time.FieldAbsoluteDate;
30  import org.orekit.utils.Constants;
31  
32  public class FieldStopOnDecreasingTest {
33  
34      @Test
35      public void testNoReset() {
36          doTestNoReset(Binary64Field.getInstance());
37      }
38  
39      @Test
40      public void testIncreasing() {
41          doTestIncreasing(Binary64Field.getInstance());
42      }
43  
44      @Test
45      public void testDecreasing() {
46          doTestDecreasing(Binary64Field.getInstance());
47      }
48  
49      private <T extends CalculusFieldElement<T>> void doTestNoReset(Field<T> field) {
50          T zero = field.getZero();
51          FieldAbsoluteDate<T> date = new FieldAbsoluteDate<>(field);
52          FieldSpacecraftState<T> s = new FieldSpacecraftState<>(new FieldKeplerianOrbit<>(zero.add(24464560.0),
53                                                                                           zero.add( 0.7311),
54                                                                                           zero.add(0.122138),
55                                                                                           zero.add(3.10686),
56                                                                                           zero.add(1.00681),
57                                                                                           zero.add(0.048363),
58                                                                                           PositionAngleType.MEAN,
59                                                                                           FramesFactory.getEME2000(),
60                                                                                           date,
61                                                                                           zero.add(Constants.EIGEN5C_EARTH_MU)));
62          Assertions.assertSame(s, new FieldStopOnDecreasing<T>().resetState(null, s));
63      }
64  
65      private <T extends CalculusFieldElement<T>> void doTestIncreasing(Field<T> field) {
66          T zero = field.getZero();
67          FieldAbsoluteDate<T> date = new FieldAbsoluteDate<>(field);
68          FieldSpacecraftState<T> s = new FieldSpacecraftState<>(new FieldKeplerianOrbit<>(zero.add(24464560.0),
69                                                                                           zero.add( 0.7311),
70                                                                                           zero.add(0.122138),
71                                                                                           zero.add(3.10686),
72                                                                                           zero.add(1.00681),
73                                                                                           zero.add(0.048363),
74                                                                                           PositionAngleType.MEAN,
75                                                                                           FramesFactory.getEME2000(),
76                                                                                           date,
77                                                                                           zero.add(Constants.EIGEN5C_EARTH_MU)));
78  
79          Assertions.assertSame(Action.CONTINUE, new FieldStopOnDecreasing<T>().eventOccurred(s, null, true));
80      }
81  
82      private <T extends CalculusFieldElement<T>> void doTestDecreasing(Field<T> field) {
83          T zero = field.getZero();
84          FieldAbsoluteDate<T> date = new FieldAbsoluteDate<>(field);
85          FieldSpacecraftState<T> s = new FieldSpacecraftState<>(new FieldKeplerianOrbit<>(zero.add(24464560.0),
86                                                                                           zero.add(0.7311),
87                                                                                           zero.add(0.122138),
88                                                                                           zero.add(3.10686),
89                                                                                           zero.add(1.00681),
90                                                                                           zero.add(0.048363),
91                                                                                           PositionAngleType.MEAN,
92                                                                                           FramesFactory.getEME2000(),
93                                                                                           date,
94                                                                                           zero.add(Constants.EIGEN5C_EARTH_MU)));
95  
96          Assertions.assertSame(Action.STOP, new FieldStopOnDecreasing<T>().eventOccurred(s, null, false));
97      }
98  
99  }
100