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.maneuvers;
18  
19  import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
20  import org.hipparchus.geometry.euclidean.threed.Vector3D;
21  import org.hipparchus.util.Binary64;
22  import org.hipparchus.util.Binary64Field;
23  import org.junit.jupiter.api.Assertions;
24  import org.junit.jupiter.api.Test;
25  import org.junit.jupiter.params.ParameterizedTest;
26  import org.junit.jupiter.params.provider.ValueSource;
27  import org.orekit.TestUtils;
28  import org.orekit.frames.FramesFactory;
29  import org.orekit.orbits.CartesianOrbit;
30  import org.orekit.orbits.FieldCartesianOrbit;
31  import org.orekit.orbits.Orbit;
32  import org.orekit.propagation.FieldSpacecraftState;
33  import org.orekit.propagation.SpacecraftState;
34  import org.orekit.time.AbsoluteDate;
35  import org.orekit.utils.PVCoordinates;
36  
37  class FieldImpulseProviderTest {
38  
39      @Test
40      void testOfVector3D() {
41          // GIVEN
42          final Vector3D forwardImpulse = new Vector3D(1, 2, 3);
43          final Binary64Field field = Binary64Field.getInstance();
44          final FieldImpulseProvider<Binary64> provider = FieldImpulseProvider.of(field, forwardImpulse);
45          // WHEN
46          final Vector3D vector3D = provider.getImpulse(null, true).toVector3D();
47          // THEN
48          Assertions.assertEquals(forwardImpulse, vector3D);
49          Assertions.assertEquals(forwardImpulse.negate(), provider.getImpulse(null, false).toVector3D());
50      }
51  
52      @Test
53      void testOfFieldVector3D() {
54          // GIVEN
55          final Vector3D forwardImpulse = new Vector3D(1, 2, 3);
56          final Binary64Field field = Binary64Field.getInstance();
57          final Orbit orbit = TestUtils.getDefaultOrbit(AbsoluteDate.ARBITRARY_EPOCH);
58          final SpacecraftState state = new SpacecraftState(orbit, 100);
59          final FieldSpacecraftState<Binary64> fieldState = new FieldSpacecraftState<>(field, state);
60          // WHEN
61          final FieldImpulseProvider<Binary64> provider = FieldImpulseProvider.of(new FieldVector3D<>(field, forwardImpulse));
62          final Vector3D vector3D = provider.getImpulse(fieldState, true).toVector3D();
63          // THEN
64          Assertions.assertEquals(forwardImpulse, vector3D);
65          Assertions.assertEquals(forwardImpulse.negate(), provider.getImpulse(fieldState, false).toVector3D());
66      }
67  
68      @ParameterizedTest
69      @ValueSource(booleans = {true, false})
70      void testOfImpulseProvider(final boolean isForward) {
71          // GIVEN
72          final Vector3D forwardImpulse = new Vector3D(1, 2, 3);
73          final ImpulseProvider impulseProvider = ImpulseProvider.of(forwardImpulse);
74          final FieldImpulseProvider<Binary64> fieldImpulseProvider = FieldImpulseProvider.of(impulseProvider);
75          final FieldSpacecraftState<Binary64> fieldSpacecraftState = buildFieldState();
76          // WHEN
77          final Vector3D vector3D = fieldImpulseProvider.getImpulse(fieldSpacecraftState, isForward).toVector3D();
78          // THEN
79          Assertions.assertEquals(impulseProvider.getImpulse(fieldSpacecraftState.toSpacecraftState(), isForward), vector3D);
80      }
81  
82      private static FieldSpacecraftState<Binary64> buildFieldState() {
83          return new FieldSpacecraftState<>(new FieldCartesianOrbit<>(Binary64Field.getInstance(),
84                  new CartesianOrbit(new PVCoordinates(Vector3D.MINUS_J, Vector3D.MINUS_K), FramesFactory.getEME2000(), AbsoluteDate.ARBITRARY_EPOCH, 1)));
85      }
86  }
87