1   /* Copyright 2002-2025 CS GROUP
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  
18  package org.orekit.utils;
19  
20  import org.hipparchus.Field;
21  import org.hipparchus.linear.FieldMatrix;
22  import org.hipparchus.linear.MatrixUtils;
23  import org.hipparchus.linear.RealMatrix;
24  import org.hipparchus.util.Binary64;
25  import org.hipparchus.util.Binary64Field;
26  import org.junit.jupiter.api.Assertions;
27  import org.junit.jupiter.api.BeforeAll;
28  import org.junit.jupiter.api.Test;
29  import org.orekit.Utils;
30  import org.orekit.frames.LOFType;
31  import org.orekit.propagation.FieldStateCovariance;
32  import org.orekit.propagation.StateCovariance;
33  import org.orekit.time.AbsoluteDate;
34  
35  class FieldifierTest {
36  
37      final Field<Binary64> field = Binary64Field.getInstance();
38  
39      @BeforeAll
40      static void setUp() {
41          Utils.setDataRoot("regular-data");
42      }
43  
44      @Test
45      void testMatrix() {
46          // GIVEN
47          // Create fake matrix
48          final RealMatrix m = MatrixUtils.createRealMatrix(new double[][] {
49                  {  1.0,  2.0,  3.0 },
50                  { -3.0, -2.0, -1.0 }
51          });
52  
53          // WHEN
54          final FieldMatrix<Binary64> fieldMatrix = Fieldifier.fieldify(field, m);
55  
56          // THEN
57  
58          // Assert matrix dimension
59          Assertions.assertEquals(m.getRowDimension(),    fieldMatrix.getRowDimension());
60          Assertions.assertEquals(m.getColumnDimension(), fieldMatrix.getColumnDimension());
61  
62          // Assert matrix elements
63          for (int i = 0; i < m.getRowDimension(); ++i) {
64              for (int j = 0; j < m.getColumnDimension(); ++j) {
65                  Assertions.assertEquals(m.getEntry(i, j), fieldMatrix.getEntry(i, j).getReal());
66              }
67          }
68  
69      }
70  
71      @Test
72      void testStateCovariance() {
73          // GIVEN
74          // Create fake covariance
75          final RealMatrix rowVector = MatrixUtils.createRealMatrix(new double[][] {
76                  {  1.0,  2.0,  3.0, -3.0, -2.0, -1.0 }
77          });
78          final StateCovariance stateCovariance =
79                  new StateCovariance(rowVector.transposeMultiply(rowVector),
80                                      AbsoluteDate.QZSS_EPOCH,
81                                      LOFType.LVLH_CCSDS);
82  
83          // WHEN
84          final FieldStateCovariance<Binary64> fieldStateCovariance =
85                  Fieldifier.fieldify(field, stateCovariance);
86  
87          // THEN
88  
89          // Assert date
90          Assertions.assertEquals(0.0,
91                                  fieldStateCovariance.getDate().durationFrom(stateCovariance.getDate()).getReal(),
92                            1.0e-15);
93  
94          // Assert matrix dimension
95          final RealMatrix m = stateCovariance.getMatrix();
96          final FieldMatrix<Binary64> fieldMatrix = fieldStateCovariance.getMatrix();
97          Assertions.assertEquals(m.getRowDimension(),    fieldMatrix.getRowDimension());
98          Assertions.assertEquals(m.getColumnDimension(), fieldMatrix.getColumnDimension());
99  
100         // Assert matrix elements
101         for (int i = 0; i < m.getRowDimension(); ++i) {
102             for (int j = 0; j < m.getColumnDimension(); ++j) {
103                 Assertions.assertEquals(m.getEntry(i, j), fieldMatrix.getEntry(i, j).getReal());
104             }
105         }
106 
107         // Assert types
108         Assertions.assertEquals(stateCovariance.getLOF(), fieldStateCovariance.getLOF());
109 
110     }
111 
112 }