StateMapper.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.orekit.attitudes.AttitudeProvider;
  19. import org.orekit.frames.Frame;
  20. import org.orekit.orbits.OrbitType;
  21. import org.orekit.orbits.PositionAngleType;
  22. import org.orekit.propagation.PropagationType;
  23. import org.orekit.propagation.SpacecraftState;
  24. import org.orekit.time.AbsoluteDate;

  25. /** This class maps between raw double elements and {@link SpacecraftState} instances.
  26.  * @author Luc Maisonobe
  27.  * @since 6.0
  28.  */
  29. public abstract class StateMapper {

  30.     /** Reference date. */
  31.     private final AbsoluteDate referenceDate;

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

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

  36.     /** Central attraction coefficient. */
  37.     private final double mu;

  38.     /** Inertial frame. */
  39.     private final Frame frame;

  40.     /** Attitude provider. */
  41.     private AttitudeProvider attitudeProvider;

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

  68.     /** Get reference date.
  69.      * @return reference date
  70.      */
  71.     public AbsoluteDate getReferenceDate() {
  72.         return referenceDate;
  73.     }

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

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

  86.     /** Get the central attraction coefficient μ.
  87.      * @return mu central attraction coefficient (m³/s²)
  88.      */
  89.     public double getMu() {
  90.         return mu;
  91.     }

  92.     /** Get the inertial frame.
  93.      * @return inertial frame
  94.      */
  95.     public Frame getFrame() {
  96.         return frame;
  97.     }

  98.     /** Get the attitude provider.
  99.      * @return attitude provider
  100.      */
  101.     public AttitudeProvider getAttitudeProvider() {
  102.         return attitudeProvider;
  103.     }

  104.     /** Set the attitude provider.
  105.      * @param attitudeProvider the provider to set
  106.      */
  107.     public void setAttitudeProvider(final AttitudeProvider attitudeProvider) {
  108.         this.attitudeProvider = attitudeProvider;
  109.     }

  110.     /** Map the raw double time offset to a date.
  111.      * @param t date offset
  112.      * @return date
  113.      */
  114.     public AbsoluteDate mapDoubleToDate(final double t) {
  115.         return referenceDate.shiftedBy(t);
  116.     }

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

  134.     /** Map a date to a raw double time offset.
  135.      * @param date date
  136.      * @return time offset
  137.      */
  138.     public double mapDateToDouble(final AbsoluteDate date) {
  139.         return date.durationFrom(referenceDate);
  140.     }

  141.     /** Map the raw double components to a spacecraft state.
  142.      * @param t date offset
  143.      * @param y state components
  144.      * @param yDot time derivatives of the state components (null if unknown, in which case Keplerian motion is assumed)
  145.      * @param type type of the elements used to build the state (mean or osculating).
  146.      * @return spacecraft state
  147.      */
  148.     public SpacecraftState mapArrayToState(final double t, final double[] y, final double[] yDot, final PropagationType type) {
  149.         return mapArrayToState(mapDoubleToDate(t), y, yDot, type);
  150.     }

  151.     /** Map the raw double components to a spacecraft state.
  152.      * @param date of the state components
  153.      * @param y state components
  154.      * @param yDot time derivatives of the state components (null if unknown, in which case Keplerian motion is assumed)
  155.      * @param type type of the elements used to build the state (mean or osculating).
  156.      * @return spacecraft state
  157.      */
  158.     public abstract SpacecraftState mapArrayToState(AbsoluteDate date, double[] y, double[] yDot, PropagationType type);

  159.     /** Map a spacecraft state to raw double components.
  160.      * @param state state to map
  161.      * @param y placeholder where to put the components
  162.      * @param yDot placeholder where to put the components derivatives
  163.      */
  164.     public abstract void mapStateToArray(SpacecraftState state, double[] y, double[] yDot);

  165. }