Fieldifier.java

  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. import org.hipparchus.CalculusFieldElement;
  19. import org.hipparchus.Field;
  20. import org.hipparchus.linear.FieldMatrix;
  21. import org.hipparchus.linear.MatrixUtils;
  22. import org.hipparchus.linear.RealMatrix;
  23. import org.orekit.propagation.FieldStateCovariance;
  24. import org.orekit.propagation.StateCovariance;
  25. import org.orekit.time.FieldAbsoluteDate;

  26. /**
  27.  * Utility class used to convert class to their Field equivalent.
  28.  *
  29.  * @author Vincent Cucchietti
  30.  */
  31. public class Fieldifier {

  32.     /** Private constructor. */
  33.     private Fieldifier() {
  34.         // Empty constructor
  35.     }

  36.     /**
  37.      * Fieldify given matrix with given field.
  38.      *
  39.      * @param field field to fieldify with
  40.      * @param matrix matrix to fieldify
  41.      * @param <T> type of the elements
  42.      *
  43.      * @return fielded matrix
  44.      */
  45.     public static <T extends CalculusFieldElement<T>> FieldMatrix<T> fieldify(final Field<T> field,
  46.                                                                               final RealMatrix matrix) {

  47.         final int rowDim    = matrix.getRowDimension();
  48.         final int columnDim = matrix.getColumnDimension();

  49.         final FieldMatrix<T> fieldMatrix = MatrixUtils.createFieldMatrix(field, rowDim, columnDim);

  50.         for (int i = 0; i < rowDim; i++) {
  51.             for (int j = 0; j < columnDim; j++) {
  52.                 fieldMatrix.setEntry(i, j, field.getOne().newInstance(matrix.getEntry(i, j)));
  53.             }
  54.         }

  55.         return fieldMatrix;
  56.     }

  57.     /**
  58.      * Fieldify given state covariance with given field.
  59.      *
  60.      * @param field field to which the
  61.      * @param stateCovariance state covariance to fieldify
  62.      * @param <T> type of the elements
  63.      *
  64.      * @return fielded state covariance
  65.      *
  66.      * @since 12.0
  67.      */
  68.     public static <T extends CalculusFieldElement<T>> FieldStateCovariance<T> fieldify(final Field<T> field,
  69.                                                                                        final StateCovariance stateCovariance) {
  70.         final FieldMatrix<T>       fieldMatrix = fieldify(field, stateCovariance.getMatrix());
  71.         final FieldAbsoluteDate<T> fieldEpoch  = new FieldAbsoluteDate<>(field, stateCovariance.getDate());
  72.         if (stateCovariance.getLOF() == null) {
  73.             return new FieldStateCovariance<>(fieldMatrix, fieldEpoch, stateCovariance.getFrame(),
  74.                                               stateCovariance.getOrbitType(), stateCovariance.getPositionAngleType());
  75.         }
  76.         return new FieldStateCovariance<>(fieldMatrix, fieldEpoch, stateCovariance.getLOF());
  77.     }

  78. }