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