Fieldifier.java

  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. 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.orbits.FieldOrbit;
  24. import org.orekit.orbits.Orbit;
  25. import org.orekit.propagation.FieldStateCovariance;
  26. import org.orekit.propagation.StateCovariance;
  27. import org.orekit.time.FieldAbsoluteDate;

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

  34.     /** Private constructor. */
  35.     private Fieldifier() {
  36.         // Empty constructor
  37.     }

  38.     /**
  39.      * Fieldify given orbit with given field.
  40.      * <p>
  41.      * Conserve derivatives and return orbit in same orbit type as input orbit.
  42.      *
  43.      * @param field field to fieldify with
  44.      * @param orbit orbit to fieldify
  45.      * @param <T> type of the elements
  46.      *
  47.      * @return fielded orbit
  48.      * @deprecated
  49.      */
  50.     @Deprecated
  51.     public static <T extends CalculusFieldElement<T>> FieldOrbit<T> fieldify(final Field<T> field, final Orbit orbit) {

  52.         return orbit.getType().convertToFieldOrbit(field, orbit);
  53.     }

  54.     /**
  55.      * Fieldify given matrix with given field.
  56.      *
  57.      * @param field field to fieldify with
  58.      * @param matrix matrix to fieldify
  59.      * @param <T> type of the elements
  60.      *
  61.      * @return fielded matrix
  62.      */
  63.     public static <T extends CalculusFieldElement<T>> FieldMatrix<T> fieldify(final Field<T> field,
  64.                                                                               final RealMatrix matrix) {

  65.         final int rowDim    = matrix.getRowDimension();
  66.         final int columnDim = matrix.getColumnDimension();

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

  68.         for (int i = 0; i < rowDim; i++) {
  69.             for (int j = 0; j < columnDim; j++) {
  70.                 fieldMatrix.setEntry(i, j, field.getOne().newInstance(matrix.getEntry(i, j)));
  71.             }
  72.         }

  73.         return fieldMatrix;
  74.     }

  75.     /**
  76.      * Fieldify given state covariance with given field.
  77.      *
  78.      * @param field field to which the
  79.      * @param stateCovariance state covariance to fieldify
  80.      * @param <T> type of the elements
  81.      *
  82.      * @return fielded state covariance
  83.      *
  84.      * @since 12.0
  85.      */
  86.     public static <T extends CalculusFieldElement<T>> FieldStateCovariance<T> fieldify(final Field<T> field,
  87.                                                                                        final StateCovariance stateCovariance) {
  88.         final FieldMatrix<T>       fieldMatrix = fieldify(field, stateCovariance.getMatrix());
  89.         final FieldAbsoluteDate<T> fieldEpoch  = new FieldAbsoluteDate<>(field, stateCovariance.getDate());
  90.         if (stateCovariance.getLOF() == null) {
  91.             return new FieldStateCovariance<>(fieldMatrix, fieldEpoch, stateCovariance.getFrame(),
  92.                                               stateCovariance.getOrbitType(), stateCovariance.getPositionAngleType());
  93.         }
  94.         return new FieldStateCovariance<>(fieldMatrix, fieldEpoch, stateCovariance.getLOF());
  95.     }

  96. }