StateMapper.java

  1. /* Copyright 2002-2020 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.PositionAngle;
  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 PositionAngle angleType;

  36.     /** Attitude provider. */
  37.     private final AttitudeProvider attitudeProvider;

  38.     /** Central attraction coefficient. */
  39.     private final double mu;

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

  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 PositionAngle 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.     /** Set position angle type.
  81.      */
  82.     public void setPositionAngleType() {
  83.     }

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

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

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

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

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

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

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

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

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

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

  163. }