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.control.indirect.adjoint.cost;
18  
19  import org.hipparchus.Field;
20  import org.hipparchus.complex.Complex;
21  import org.hipparchus.complex.ComplexField;
22  import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
23  import org.hipparchus.geometry.euclidean.threed.Vector3D;
24  import org.hipparchus.util.Binary64;
25  import org.hipparchus.util.Binary64Field;
26  import org.hipparchus.util.MathArrays;
27  import org.junit.jupiter.api.Assertions;
28  import org.junit.jupiter.api.Test;
29  
30  class FieldUnboundedCartesianEnergyNeglectingMassTest {
31  
32      @Test
33      void testGetFieldHamiltonianContribution() {
34          // GIVEN
35          final FieldUnboundedCartesianEnergyNeglectingMass<Complex> mockedEnergy = new FieldUnboundedCartesianEnergyNeglectingMass<>("", ComplexField.getInstance());
36          final Field<Complex> field = ComplexField.getInstance();
37          final Complex[] fieldAdjoint = MathArrays.buildArray(field, 6);
38          final Complex fieldMass = Complex.ONE;
39          final double mass = fieldMass.getReal();
40          final double[] adjoint = new double[fieldAdjoint.length];
41          // WHEN
42          final Complex fieldContribution = mockedEnergy.getFieldHamiltonianContribution(fieldAdjoint, fieldMass);
43          // THEN
44          final double contribution = mockedEnergy.toCartesianCost().getHamiltonianContribution(adjoint, mass);
45          Assertions.assertEquals(contribution, fieldContribution.getReal());
46      }
47  
48      @Test
49      void testGetFieldThrustAccelerationVector() {
50          // GIVEN
51          final FieldUnboundedCartesianEnergyNeglectingMass<Binary64> energyNeglectingMass = new FieldUnboundedCartesianEnergyNeglectingMass<>("",
52                  Binary64Field.getInstance());
53          final Binary64[] adjoint = MathArrays.buildArray(Binary64Field.getInstance(), 6);
54          adjoint[3] = Binary64.ONE;
55          // WHEN
56          final FieldVector3D<Binary64> fieldThrustVector = energyNeglectingMass.getFieldThrustAccelerationVector(adjoint, Binary64.ONE);
57          // THEN
58          final Vector3D thrustVector = energyNeglectingMass.toCartesianCost().getThrustAccelerationVector(new double[] { 0., 0., 0., 1., 0., 0.}, 1.);
59          Assertions.assertEquals(thrustVector, fieldThrustVector.toVector3D());
60      }
61  
62  }