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 FieldStopOnIncreasingTest {
33  
34      @Test
35      public void testNoReset() {
36          doTestNoReset(Binary64Field.getInstance());
37      }
38  
39      @Test
40      public void testIbcreasing() {
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), zero.add(0.7311),
53                                                                                           zero.add(0.122138),   zero.add(3.10686),
54                                                                                           zero.add(1.00681), zero.add(0.048363),
55                                                                                           PositionAngleType.MEAN,
56                                                                                           FramesFactory.getEME2000(),
57                                                                                           date,
58                                                                                           zero.add(Constants.EIGEN5C_EARTH_MU)));
59          Assertions.assertSame(s, new FieldStopOnIncreasing<T>().resetState(null, s));
60      }
61  
62      private <T extends CalculusFieldElement<T>> void doTestIncreasing(Field<T> field) {
63          T zero = field.getZero();
64          FieldAbsoluteDate<T> date = new FieldAbsoluteDate<>(field);
65          FieldSpacecraftState<T> s = new FieldSpacecraftState<>(new FieldKeplerianOrbit<>(zero.add(24464560.0), zero.add(0.7311),
66                                                                                           zero.add(0.122138),   zero.add(3.10686),
67                                                                                           zero.add(1.00681), zero.add(0.048363),
68                                                                                           PositionAngleType.MEAN,
69                                                                                           FramesFactory.getEME2000(),
70                                                                                           date,
71                                                                                           zero.add(Constants.EIGEN5C_EARTH_MU)));
72          Assertions.assertSame(Action.STOP, new FieldStopOnIncreasing<T>().eventOccurred(s, null, true));
73      }
74  
75      private <T extends CalculusFieldElement<T>> void doTestDecreasing(Field<T> field) {
76          T zero = field.getZero();
77          FieldAbsoluteDate<T> date = new FieldAbsoluteDate<>(field);
78          FieldSpacecraftState<T> s = new FieldSpacecraftState<>(new FieldKeplerianOrbit<>(zero.add(24464560.0), zero.add(0.7311),
79                                                                                           zero.add(0.122138),   zero.add(3.10686),
80                                                                                           zero.add(1.00681), zero.add(0.048363),
81                                                                                           PositionAngleType.MEAN,
82                                                                                           FramesFactory.getEME2000(),
83                                                                                           date,
84                                                                                           zero.add(Constants.EIGEN5C_EARTH_MU)));
85          Assertions.assertSame(Action.CONTINUE, new FieldStopOnIncreasing<T>().eventOccurred(s, null, false));
86  
87      }
88  
89  }
90