1   /* Contributed in the public domain.
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.ode.events.Action;
20  import org.hipparchus.util.Binary64;
21  import org.hipparchus.util.Binary64Field;
22  import org.junit.jupiter.api.Assertions;
23  import org.junit.jupiter.api.Test;
24  import org.orekit.frames.Frame;
25  import org.orekit.frames.FramesFactory;
26  import org.orekit.orbits.FieldKeplerianOrbit;
27  import org.orekit.orbits.FieldOrbit;
28  import org.orekit.orbits.PositionAngleType;
29  import org.orekit.propagation.FieldSpacecraftState;
30  import org.orekit.propagation.events.FieldDateDetector;
31  import org.orekit.propagation.events.handlers.FieldRecordAndContinue.Event;
32  import org.orekit.time.AbsoluteDate;
33  import org.orekit.time.FieldAbsoluteDate;
34  import org.orekit.utils.Constants;
35  
36  import java.util.List;
37  
38  /**
39   * Unit tests for {@link FieldRecordAndContinue}.
40   *
41   * @author Evan Ward
42   */
43  public class FieldRecordAndContinueTest {
44  
45      /** Field. */
46      private static final Binary64Field field = Binary64Field.getInstance();
47  
48      /** check add and clear behavior. */
49      @Test
50      public void testGetEvents() {
51          // setup
52          FieldRecordAndContinue<Binary64> handler = new FieldRecordAndContinue<>();
53          FieldAbsoluteDate<Binary64> date =
54                  new FieldAbsoluteDate<>(field, AbsoluteDate.J2000_EPOCH);
55          Binary64 zero = date.getField().getZero();
56          FieldDateDetector<Binary64> detector = new FieldDateDetector<>(field, date);
57          Frame eci = FramesFactory.getGCRF();
58          FieldOrbit<Binary64> orbit = new FieldKeplerianOrbit<>(
59                  v(6378137 + 500e3), v(0), v(0), v(0), v(0), v(0),
60                  PositionAngleType.TRUE, eci, date, zero.add(Constants.EIGEN5C_EARTH_MU));
61          FieldSpacecraftState<Binary64> s1 = new FieldSpacecraftState<>(orbit);
62          FieldSpacecraftState<Binary64> s2 = s1.shiftedBy(-10);
63          FieldSpacecraftState<Binary64> s3 = s2.shiftedBy(1);
64          FieldSpacecraftState<Binary64> s4 = s3.shiftedBy(1);
65  
66          // actions
67          Assertions.assertEquals(Action.CONTINUE, handler.eventOccurred(s1, detector, true));
68          Assertions.assertEquals(Action.CONTINUE, handler.eventOccurred(s2, detector, true));
69          Assertions.assertEquals(Action.CONTINUE, handler.eventOccurred(s3, detector, false));
70  
71          // verify
72          List<Event<Binary64>> events = handler.getEvents();
73          Assertions.assertEquals(3, events.size());
74          Assertions.assertEquals(s1, events.get(0).getState());
75          Assertions.assertEquals(s2, events.get(1).getState());
76          Assertions.assertEquals(s3, events.get(2).getState());
77          Assertions.assertEquals(true, events.get(0).isIncreasing());
78          Assertions.assertEquals(true, events.get(1).isIncreasing());
79          Assertions.assertEquals(false, events.get(2).isIncreasing());
80          for (Event<Binary64> event : events) {
81              Assertions.assertEquals(detector, event.getDetector());
82          }
83  
84          // action: clear
85          handler.clear();
86  
87          // verify is empty
88          Assertions.assertEquals(0, handler.getEvents().size());
89  
90          // action add more
91          Assertions.assertEquals(Action.CONTINUE, handler.eventOccurred(s4, detector, false));
92  
93          // verify new events
94          events = handler.getEvents();
95          Assertions.assertEquals(1, events.size());
96          Assertions.assertEquals(s4, events.get(0).getState());
97          Assertions.assertEquals(false, events.get(0).isIncreasing());
98          Assertions.assertEquals(detector, events.get(0).getDetector());
99      }
100 
101     /**
102      * Box a double value.
103      *
104      * @param value to copy.
105      * @return boxed {@code value}.
106      */
107     private Binary64 v(double value) {
108         return new Binary64(value);
109     }
110 
111 }