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;
18  
19  import org.hipparchus.util.Binary64;
20  import org.hipparchus.util.Binary64Field;
21  import org.hipparchus.util.MathArrays;
22  import org.junit.jupiter.api.Assertions;
23  import org.junit.jupiter.api.Test;
24  import org.mockito.Mockito;
25  
26  class AbstractCartesianAdjointNewtonianTermTest {
27  
28      @Test
29      void testGetVelocityAdjointContributionField() {
30          // GIVEN
31          final AbstractCartesianAdjointNewtonianTerm adjointNewtonianTerm = Mockito.mock(AbstractCartesianAdjointNewtonianTerm.class);
32          final Binary64Field field = Binary64Field.getInstance();
33          final Binary64[] fieldAdjoint = MathArrays.buildArray(field, 6);
34          final Binary64[] fieldState = MathArrays.buildArray(field, 6);
35          for (int i = 0; i < fieldAdjoint.length; i++) {
36              fieldState[i] = field.getZero().newInstance(-i+1);
37              fieldAdjoint[i] = field.getZero().newInstance(i);
38          }
39          final double mu = 2.;
40          Mockito.when(adjointNewtonianTerm.getFieldNewtonianVelocityAdjointContribution(fieldState, fieldAdjoint)).thenCallRealMethod();
41          // WHEN
42          final Binary64[] fieldContribution = adjointNewtonianTerm.getFieldNewtonianVelocityAdjointContribution(fieldState, fieldAdjoint);
43          // THEN
44          final double[] state = new double[fieldState.length];
45          for (int i = 0; i < fieldState.length; i++) {
46              state[i] = fieldState[i].getReal();
47          }
48          final double[] adjoint = new double[fieldAdjoint.length];
49          for (int i = 0; i < fieldAdjoint.length; i++) {
50              adjoint[i] = fieldAdjoint[i].getReal();
51          }
52          Mockito.when(adjointNewtonianTerm.getNewtonianVelocityAdjointContribution(state, adjoint)).thenCallRealMethod();
53          final double[] contribution = adjointNewtonianTerm.getNewtonianVelocityAdjointContribution(state, adjoint);
54          for (int i = 0; i < contribution.length; i++) {
55              Assertions.assertEquals(fieldContribution[i].getReal(), contribution[i]);
56          }
57      }
58  }