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 FieldStopOnDecreasingTest {
34
35 @Test
36 public void testNoReset() {
37 doTestNoReset(Decimal64Field.getInstance());
38 }
39
40 @Test
41 public void testIncreasing() {
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),
54 zero.add( 0.7311),
55 zero.add(0.122138),
56 zero.add(3.10686),
57 zero.add(1.00681),
58 zero.add(0.048363),
59 PositionAngle.MEAN,
60 FramesFactory.getEME2000(),
61 date,
62 zero.add(Constants.EIGEN5C_EARTH_MU)));
63 Assert.assertSame(s, new FieldStopOnDecreasing<FieldEventDetector<T>, T>().resetState(null, s));
64 }
65
66 private <T extends CalculusFieldElement<T>> void doTestIncreasing(Field<T> field) {
67 T zero = field.getZero();
68 FieldAbsoluteDate<T> date = new FieldAbsoluteDate<>(field);
69 FieldSpacecraftState<T> s = new FieldSpacecraftState<>(new FieldKeplerianOrbit<>(zero.add(24464560.0),
70 zero.add( 0.7311),
71 zero.add(0.122138),
72 zero.add(3.10686),
73 zero.add(1.00681),
74 zero.add(0.048363),
75 PositionAngle.MEAN,
76 FramesFactory.getEME2000(),
77 date,
78 zero.add(Constants.EIGEN5C_EARTH_MU)));
79
80 Assert.assertSame(Action.CONTINUE, new FieldStopOnDecreasing<FieldEventDetector<T>, T>().eventOccurred(s, null, true));
81 }
82
83 private <T extends CalculusFieldElement<T>> void doTestDecreasing(Field<T> field) {
84 T zero = field.getZero();
85 FieldAbsoluteDate<T> date = new FieldAbsoluteDate<>(field);
86 FieldSpacecraftState<T> s = new FieldSpacecraftState<>(new FieldKeplerianOrbit<>(zero.add(24464560.0),
87 zero.add(0.7311),
88 zero.add(0.122138),
89 zero.add(3.10686),
90 zero.add(1.00681),
91 zero.add(0.048363),
92 PositionAngle.MEAN,
93 FramesFactory.getEME2000(),
94 date,
95 zero.add(Constants.EIGEN5C_EARTH_MU)));
96
97 Assert.assertSame(Action.STOP, new FieldStopOnDecreasing<FieldEventDetector<T>, T>().eventOccurred(s, null, false));
98 }
99
100 }
101