1 /* Copyright 2002-2024 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.orbits.FieldOrbit;
25 import org.orekit.orbits.Orbit;
26 import org.orekit.propagation.FieldStateCovariance;
27 import org.orekit.propagation.StateCovariance;
28 import org.orekit.time.FieldAbsoluteDate;
29
30 /**
31 * Utility class used to convert class to their Field equivalent.
32 *
33 * @author Vincent Cucchietti
34 */
35 public class Fieldifier {
36
37 /** Private constructor. */
38 private Fieldifier() {
39 // Empty constructor
40 }
41
42 /**
43 * Fieldify given orbit with given field.
44 * <p>
45 * Conserve derivatives and return orbit in same orbit type as input orbit.
46 *
47 * @param field field to fieldify with
48 * @param orbit orbit to fieldify
49 * @param <T> type of the elements
50 *
51 * @return fielded orbit
52 * @deprecated
53 */
54 @Deprecated
55 public static <T extends CalculusFieldElement<T>> FieldOrbit<T> fieldify(final Field<T> field, final Orbit orbit) {
56
57 return orbit.getType().convertToFieldOrbit(field, orbit);
58 }
59
60 /**
61 * Fieldify given matrix with given field.
62 *
63 * @param field field to fieldify with
64 * @param matrix matrix to fieldify
65 * @param <T> type of the elements
66 *
67 * @return fielded matrix
68 */
69 public static <T extends CalculusFieldElement<T>> FieldMatrix<T> fieldify(final Field<T> field,
70 final RealMatrix matrix) {
71
72 final int rowDim = matrix.getRowDimension();
73 final int columnDim = matrix.getColumnDimension();
74
75 final FieldMatrix<T> fieldMatrix = MatrixUtils.createFieldMatrix(field, rowDim, columnDim);
76
77 for (int i = 0; i < rowDim; i++) {
78 for (int j = 0; j < columnDim; j++) {
79 fieldMatrix.setEntry(i, j, field.getOne().newInstance(matrix.getEntry(i, j)));
80 }
81 }
82
83 return fieldMatrix;
84 }
85
86 /**
87 * Fieldify given state covariance with given field.
88 *
89 * @param field field to which the
90 * @param stateCovariance state covariance to fieldify
91 * @param <T> type of the elements
92 *
93 * @return fielded state covariance
94 *
95 * @since 12.0
96 */
97 public static <T extends CalculusFieldElement<T>> FieldStateCovariance<T> fieldify(final Field<T> field,
98 final StateCovariance stateCovariance) {
99 final FieldMatrix<T> fieldMatrix = fieldify(field, stateCovariance.getMatrix());
100 final FieldAbsoluteDate<T> fieldEpoch = new FieldAbsoluteDate<>(field, stateCovariance.getDate());
101 if (stateCovariance.getLOF() == null) {
102 return new FieldStateCovariance<>(fieldMatrix, fieldEpoch, stateCovariance.getFrame(),
103 stateCovariance.getOrbitType(), stateCovariance.getPositionAngleType());
104 }
105 return new FieldStateCovariance<>(fieldMatrix, fieldEpoch, stateCovariance.getLOF());
106 }
107
108 }