FieldStateMapper.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.propagation.integration;

  18. import org.hipparchus.CalculusFieldElement;
  19. import org.orekit.attitudes.AttitudeProvider;
  20. import org.orekit.frames.Frame;
  21. import org.orekit.orbits.OrbitType;
  22. import org.orekit.orbits.PositionAngleType;
  23. import org.orekit.propagation.FieldSpacecraftState;
  24. import org.orekit.propagation.PropagationType;
  25. import org.orekit.time.FieldAbsoluteDate;

  26. /** This class maps between raw double elements and {@link FieldSpacecraftState} instances.
  27.  * @author Luc Maisonobe
  28.  * @param <T> type of the field elements
  29.  */
  30. public abstract class FieldStateMapper<T extends CalculusFieldElement<T>> {

  31.     /** Reference date. */
  32.     private final FieldAbsoluteDate<T> referenceDate;

  33.     /** Propagation orbit type. */
  34.     private final OrbitType orbitType;

  35.     /** Position angle type. */
  36.     private final PositionAngleType angleType;

  37.     /** Attitude provider. */
  38.     private AttitudeProvider attitudeProvider;

  39.     /** Central attraction coefficient. */
  40.     private final T mu;

  41.     /** Inertial frame. */
  42.     private final Frame frame;

  43.     /** Simple constructor.
  44.      * <p>
  45.      * The position parameter type is meaningful only if {@link
  46.      * #getOrbitType() propagation orbit type}
  47.      * support it. As an example, it is not meaningful for propagation
  48.      * in {@link  OrbitType#CARTESIAN Cartesian} parameters.
  49.      * </p>
  50.      * @param referenceDate reference date
  51.      * @param mu central attraction coefficient (m³/s²)
  52.      * @param orbitType orbit type to use for mapping
  53.      * @param positionAngleType angle type to use for propagation
  54.      * @param attitudeProvider attitude provider
  55.      * @param frame inertial frame
  56.      */
  57.     protected FieldStateMapper(final FieldAbsoluteDate<T> referenceDate, final T mu,
  58.                           final OrbitType orbitType, final PositionAngleType positionAngleType,
  59.                           final AttitudeProvider attitudeProvider, final Frame frame) {
  60.         this.referenceDate    = referenceDate;
  61.         this.mu               = mu;
  62.         this.orbitType        = orbitType;
  63.         this.angleType        = positionAngleType;
  64.         this.attitudeProvider = attitudeProvider;
  65.         this.frame            = frame;
  66.     }

  67.     /** Get reference date.
  68.      * @return reference date
  69.      */
  70.     public FieldAbsoluteDate<T> getReferenceDate() {
  71.         return referenceDate;
  72.     }

  73.     /** Get propagation parameter type.
  74.      * @return orbit type used for propagation
  75.      */
  76.     public  OrbitType getOrbitType() {
  77.         return orbitType;
  78.     }

  79.     /** Set position angle type.
  80.      */
  81.     public void setPositionAngleType() {
  82.     }

  83.     /** Get propagation parameter type.
  84.      * @return angle type to use for propagation
  85.      */
  86.     public PositionAngleType getPositionAngleType() {
  87.         return angleType;
  88.     }

  89.     /** Get the central attraction coefficient μ.
  90.      * @return mu central attraction coefficient (m³/s²)
  91.      */
  92.     public T getMu() {
  93.         return mu;
  94.     }

  95.     /** Get the inertial frame.
  96.      * @return inertial frame
  97.      */
  98.     public Frame getFrame() {
  99.         return frame;
  100.     }

  101.     /** Get the attitude provider.
  102.      * @return attitude provider
  103.      */
  104.     public AttitudeProvider getAttitudeProvider() {
  105.         return attitudeProvider;
  106.     }

  107.     /**
  108.      * Setter for the attitude provider.
  109.      * @param attitudeProvider new attitude provider
  110.      */
  111.     public void setAttitudeProvider(final AttitudeProvider attitudeProvider) {
  112.         this.attitudeProvider = attitudeProvider;
  113.     }

  114.     /** Map the raw double time offset to a date.
  115.      * @param t date offset
  116.      * @return date
  117.      */
  118.     public FieldAbsoluteDate<T> mapDoubleToDate(final T t) {
  119.         return referenceDate.shiftedBy(t);
  120.     }

  121.     /**
  122.      * Map the raw double time offset to a date.
  123.      *
  124.      * @param t    date offset
  125.      * @param date The expected date.
  126.      * @return {@code date} if it is the same time as {@code t} to within the
  127.      * lower precision of the latter. Otherwise a new date is returned that
  128.      * corresponds to time {@code t}.
  129.      */
  130.     public FieldAbsoluteDate<T> mapDoubleToDate(final T t,
  131.                                         final FieldAbsoluteDate<T> date) {
  132.         if (date.durationFrom(referenceDate).getReal() == t.getReal()) {
  133.             return date;
  134.         } else {
  135.             return mapDoubleToDate(t);
  136.         }
  137.     }

  138.     /** Map a date to a raw double time offset.
  139.      * @param date date
  140.      * @return time offset
  141.      */
  142.     public T mapDateToDouble(final FieldAbsoluteDate<T> date) {
  143.         return date.durationFrom(referenceDate);
  144.     }

  145.     /** Map the raw double components to a spacecraft state.
  146.      * @param t date offset
  147.      * @param y state components
  148.      * @param yDot state derivative components
  149.      * @param type type of the elements used to build the state (mean or osculating)
  150.      * @return spacecraft state
  151.      */
  152.     public FieldSpacecraftState<T> mapArrayToState(final T t, final T[] y, final T[] yDot, final PropagationType type) {
  153.         return mapArrayToState(mapDoubleToDate(t), y, yDot, type);
  154.     }

  155.     /** Map the raw double components to a spacecraft state.
  156.      * @param date of the state components
  157.      * @param y state components
  158.      * @param yDot state derivative components
  159.      * @param type type of the elements used to build the state (mean or osculating).
  160.      * @return spacecraft state
  161.      */
  162.     public abstract FieldSpacecraftState<T> mapArrayToState(FieldAbsoluteDate<T> date, T[] y, T[] yDot, PropagationType type);

  163.     /** Map a spacecraft state to raw double components.
  164.      * @param state state to map
  165.      * @param y placeholder where to put the components
  166.      * @param yDot placeholder where to put the components derivatives
  167.      */
  168.     public abstract void mapStateToArray(FieldSpacecraftState<T> state, T[] y, T[] yDot);

  169. }