1   package org.orekit.forces.maneuvers.propulsion;
2   
3   import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
4   import org.hipparchus.geometry.euclidean.threed.Vector3D;
5   import org.hipparchus.util.Binary64;
6   import org.hipparchus.util.Binary64Field;
7   import org.hipparchus.util.MathArrays;
8   import org.junit.jupiter.api.Test;
9   import org.orekit.time.AbsoluteDate;
10  import org.orekit.utils.Constants;
11  import org.orekit.utils.ParameterDriver;
12  
13  import java.util.List;
14  
15  import static org.junit.jupiter.api.Assertions.*;
16  
17  class SphericalConstantThrustPropulsionModelTest {
18  
19      @Test
20      void testGetFlowRate() {
21          // GIVEN
22          final double isp = 10.;
23          final Vector3D thrustVector = new Vector3D(1, 2, 3);
24          final SphericalConstantThrustPropulsionModel propulsionModel = new SphericalConstantThrustPropulsionModel(isp,
25                  thrustVector, "");
26          // WHEN
27          final double rate = propulsionModel.getFlowRate();
28          // THEN
29          assertEquals(-thrustVector.getNorm() / (Constants.G0_STANDARD_GRAVITY * isp), rate, 1e-12);
30          assertEquals(propulsionModel.getFlowRate(AbsoluteDate.ARBITRARY_EPOCH), rate);
31      }
32  
33      @Test
34      void testGetThrustVector() {
35          // GIVEN
36          final double isp = 10.;
37          final Vector3D thrustVector = new Vector3D(1, 2, 3);
38          final SphericalConstantThrustPropulsionModel propulsionModel = new SphericalConstantThrustPropulsionModel(isp,
39                  thrustVector, "");
40          // WHEN
41          final Vector3D actualThrustVector = propulsionModel.getThrustVector();
42          // THEN
43          assertArrayEquals(thrustVector.toArray(), actualThrustVector.toArray(), 1e-12);
44          assertEquals(propulsionModel.getThrustVector(AbsoluteDate.ARBITRARY_EPOCH), actualThrustVector);
45          final BasicConstantThrustPropulsionModel basicConstantThrustPropulsionModel = new BasicConstantThrustPropulsionModel(thrustVector.getNorm(),
46                  isp, thrustVector.normalize(), "");
47          assertEquals(basicConstantThrustPropulsionModel.getThrustVector(), thrustVector);
48      }
49  
50      @Test
51      void testGetThrustVectorField() {
52          // GIVEN
53          final double isp = 10.;
54          final double thrustMagnitude = 3;
55          final double thrustAlpha = 2;
56          final double thrustDelta = 1.;
57          final Vector3D thrustVector = new Vector3D(thrustAlpha, thrustDelta).scalarMultiply(thrustMagnitude);
58          final SphericalConstantThrustPropulsionModel propulsionModel = new SphericalConstantThrustPropulsionModel(isp,
59                  thrustVector, "");
60          final Binary64Field field = Binary64Field.getInstance();
61          final Binary64[] parameters = MathArrays.buildArray(field, 3);
62          parameters[0] = new Binary64(thrustMagnitude);
63          parameters[1] = new Binary64(thrustAlpha);
64          parameters[2] = new Binary64(thrustDelta);
65          // WHEN
66          final FieldVector3D<Binary64> actualThrustVector = propulsionModel.getThrustVector(parameters);
67          // THEN
68          assertArrayEquals(propulsionModel.getThrustVector(new double[] {thrustMagnitude, thrustAlpha, thrustDelta}).toArray(),
69                  actualThrustVector.toVector3D().toArray(), 1e-12);
70      }
71  
72      @Test
73      void testGetFlowRateField() {
74          // GIVEN
75          final double isp = 10.;
76          final double thrustMagnitude = 3;
77          final double thrustAlpha = 2;
78          final double thrustDelta = 1.;
79          final Vector3D thrustVector = new Vector3D(thrustAlpha, thrustDelta).scalarMultiply(thrustMagnitude);
80          final SphericalConstantThrustPropulsionModel propulsionModel = new SphericalConstantThrustPropulsionModel(isp,
81                  thrustVector, "");
82          final Binary64Field field = Binary64Field.getInstance();
83          final Binary64[] parameters = MathArrays.buildArray(field, 3);
84          parameters[0] = new Binary64(thrustMagnitude);
85          parameters[1] = new Binary64(thrustAlpha);
86          parameters[2] = new Binary64(thrustDelta);
87          // WHEN
88          final Binary64 actualFlowRate = propulsionModel.getFlowRate(parameters);
89          // THEN
90          assertEquals(propulsionModel.getFlowRate(new double[] {thrustMagnitude, thrustAlpha, thrustDelta}),
91                  actualFlowRate.getReal(), 1e-12);
92      }
93  
94      @Test
95      void testGetParametersDrivers() {
96          // GIVEN
97          final double isp = 10.;
98          final Vector3D thrustVector = new Vector3D(1, 2, 3);
99          final SphericalConstantThrustPropulsionModel propulsionModel = new SphericalConstantThrustPropulsionModel(isp,
100                 thrustVector, "");
101         // WHEN
102         final List<ParameterDriver> parameterDriverList = propulsionModel.getParametersDrivers();
103         // THEN
104         assertEquals(3, parameterDriverList.size());
105         assertEquals(thrustVector.getNorm(), parameterDriverList.get(0).getValue());
106         assertEquals(thrustVector.getAlpha(), parameterDriverList.get(1).getValue());
107         assertEquals(thrustVector.getDelta(), parameterDriverList.get(2).getValue());
108     }
109 }