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 package org.orekit.utils;
18
19 import org.hipparchus.CalculusFieldElement;
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.orekit.propagation.FieldStateCovariance;
25 import org.orekit.propagation.StateCovariance;
26 import org.orekit.time.FieldAbsoluteDate;
27
28 /**
29 * Utility class used to convert class to their Field equivalent.
30 *
31 * @author Vincent Cucchietti
32 */
33 public class Fieldifier {
34
35 /** Private constructor. */
36 private Fieldifier() {
37 // Empty constructor
38 }
39
40 /**
41 * Fieldify given matrix with given field.
42 *
43 * @param field field to fieldify with
44 * @param matrix matrix to fieldify
45 * @param <T> type of the elements
46 *
47 * @return fielded matrix
48 */
49 public static <T extends CalculusFieldElement<T>> FieldMatrix<T> fieldify(final Field<T> field,
50 final RealMatrix matrix) {
51
52 final int rowDim = matrix.getRowDimension();
53 final int columnDim = matrix.getColumnDimension();
54
55 final FieldMatrix<T> fieldMatrix = MatrixUtils.createFieldMatrix(field, rowDim, columnDim);
56
57 for (int i = 0; i < rowDim; i++) {
58 for (int j = 0; j < columnDim; j++) {
59 fieldMatrix.setEntry(i, j, field.getOne().newInstance(matrix.getEntry(i, j)));
60 }
61 }
62
63 return fieldMatrix;
64 }
65
66 /**
67 * Fieldify given state covariance with given field.
68 *
69 * @param field field to which the
70 * @param stateCovariance state covariance to fieldify
71 * @param <T> type of the elements
72 *
73 * @return fielded state covariance
74 *
75 * @since 12.0
76 */
77 public static <T extends CalculusFieldElement<T>> FieldStateCovariance<T> fieldify(final Field<T> field,
78 final StateCovariance stateCovariance) {
79 final FieldMatrix<T> fieldMatrix = fieldify(field, stateCovariance.getMatrix());
80 final FieldAbsoluteDate<T> fieldEpoch = new FieldAbsoluteDate<>(field, stateCovariance.getDate());
81 if (stateCovariance.getLOF() == null) {
82 return new FieldStateCovariance<>(fieldMatrix, fieldEpoch, stateCovariance.getFrame(),
83 stateCovariance.getOrbitType(), stateCovariance.getPositionAngleType());
84 }
85 return new FieldStateCovariance<>(fieldMatrix, fieldEpoch, stateCovariance.getLOF());
86 }
87
88 }