1   /* Copyright 2022-2025 Romain Serra
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.forces.empirical;
18  
19  import org.hipparchus.CalculusFieldElement;
20  import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
21  import org.hipparchus.geometry.euclidean.threed.Vector3D;
22  import org.junit.jupiter.api.Assertions;
23  import org.junit.jupiter.api.Test;
24  import org.mockito.Mockito;
25  import org.orekit.attitudes.AttitudeProvider;
26  import org.orekit.attitudes.FrameAlignedProvider;
27  import org.orekit.frames.FramesFactory;
28  import org.orekit.orbits.CartesianOrbit;
29  import org.orekit.propagation.FieldSpacecraftState;
30  import org.orekit.propagation.SpacecraftState;
31  import org.orekit.propagation.events.DateDetector;
32  import org.orekit.propagation.events.EventDetector;
33  import org.orekit.time.AbsoluteDate;
34  import org.orekit.utils.AbsolutePVCoordinates;
35  import org.orekit.utils.PVCoordinates;
36  import org.orekit.utils.ParameterDriver;
37  
38  import java.util.Collections;
39  import java.util.List;
40  import java.util.stream.Stream;
41  
42  class AbstractParametricAccelerationTest {
43  
44      @Test
45      void testGetAccelerationDirectionAbsolutePVCoordinates() {
46          // GIVEN
47          final AbsolutePVCoordinates orbit = new AbsolutePVCoordinates(
48                  FramesFactory.getEME2000(), AbsoluteDate.ARBITRARY_EPOCH, new PVCoordinates(Vector3D.MINUS_J, Vector3D.MINUS_K));
49          final TestAcceleration testAcceleration = new TestAcceleration(Vector3D.PLUS_I, true,
50                  new FrameAlignedProvider(orbit.getFrame()));
51          // WHEN
52          final Vector3D direction = testAcceleration.getAccelerationDirection(new SpacecraftState(orbit));
53          // THEN
54          Assertions.assertEquals(Vector3D.PLUS_I, direction);
55      }
56  
57      @Test
58      void testGetAccelerationDirection() {
59          // GIVEN
60          final CartesianOrbit orbit = new CartesianOrbit(new PVCoordinates(Vector3D.MINUS_J, Vector3D.MINUS_K),
61                  FramesFactory.getEME2000(), AbsoluteDate.ARBITRARY_EPOCH, 1.);
62          final TestAcceleration testAcceleration = new TestAcceleration(Vector3D.PLUS_I, true,
63                  new FrameAlignedProvider(orbit.getFrame()));
64          // WHEN
65          final Vector3D direction = testAcceleration.getAccelerationDirection(new SpacecraftState(orbit));
66          // THEN
67          Assertions.assertEquals(Vector3D.PLUS_I, direction);
68      }
69  
70      @Test
71      void testGetAccelerationDirectionNoOverride() {
72          // GIVEN
73          final CartesianOrbit orbit = new CartesianOrbit(new PVCoordinates(Vector3D.MINUS_J, Vector3D.MINUS_K),
74                  FramesFactory.getEME2000(), AbsoluteDate.ARBITRARY_EPOCH, 1.);
75          final TestAcceleration testAcceleration = new TestAcceleration(Vector3D.PLUS_I, true, null);
76          // WHEN
77          final Vector3D direction = testAcceleration.getAccelerationDirection(new SpacecraftState(orbit));
78          // THEN
79          Assertions.assertEquals(Vector3D.PLUS_I, direction);
80      }
81  
82      @Test
83      void testGetEventDetectorsEmpty() {
84          // GIVEN
85          final TestAcceleration testAcceleration = new TestAcceleration(Vector3D.PLUS_I, true, null);
86          // WHEN
87          final Stream<EventDetector> detectorStream = testAcceleration.getEventDetectors();
88          // THEN
89          Assertions.assertEquals(0, detectorStream.count());
90      }
91  
92      @Test
93      void testGetEventDetectors() {
94          // GIVEN
95          final AttitudeProvider mockedAttitudeProvider = Mockito.mock(AttitudeProvider.class);
96          Mockito.when(mockedAttitudeProvider.getEventDetectors()).thenReturn(Stream.of(new DateDetector()));
97          final TestAcceleration testAcceleration = new TestAcceleration(Vector3D.PLUS_I, true, mockedAttitudeProvider);
98          // WHEN
99          final Stream<EventDetector> detectorStream = testAcceleration.getEventDetectors();
100         // THEN
101         Assertions.assertEquals(1, detectorStream.count());
102     }
103 
104     private static class TestAcceleration extends AbstractParametricAcceleration {
105 
106         protected TestAcceleration(Vector3D direction, boolean isInertial, AttitudeProvider attitudeOverride) {
107             super(direction, isInertial, attitudeOverride);
108         }
109 
110         @Override
111         public Vector3D acceleration(SpacecraftState s, double[] parameters) {
112             return null;
113         }
114 
115         @Override
116         public <T extends CalculusFieldElement<T>> FieldVector3D<T> acceleration(FieldSpacecraftState<T> s, T[] parameters) {
117             return null;
118         }
119 
120         @Override
121         public List<ParameterDriver> getParametersDrivers() {
122             return Collections.emptyList();
123         }
124     }
125 }