StateMapper.java

  1. /* Copyright 2002-2019 CS Systèmes d'Information
  2.  * Licensed to CS Systèmes d'Information (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.SpacecraftState;
  23. import org.orekit.time.AbsoluteDate;

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

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

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

  33.     /** Position angle type. */
  34.     private final PositionAngle angleType;

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

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

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

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

  65.     /** Get reference date.
  66.      * @return reference date
  67.      */
  68.     public AbsoluteDate getReferenceDate() {
  69.         return referenceDate;
  70.     }

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

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

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

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

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

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

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

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

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

  136.     /** Map the raw double components to a spacecraft state.
  137.      * @param t date offset
  138.      * @param y state components
  139.      * @param yDot time derivatives of the state components (null if unknown, in which case Keplerian motion is assumed)
  140.      * @param meanOnly use only the mean elements to build the state
  141.      * @return spacecraft state
  142.      */
  143.     public SpacecraftState mapArrayToState(final double t, final double[] y, final double[] yDot, final boolean meanOnly) {
  144.         return mapArrayToState(mapDoubleToDate(t), y, yDot, meanOnly);
  145.     }

  146.     /** Map the raw double components to a spacecraft state.
  147.      * @param date of the state components
  148.      * @param y state components
  149.      * @param yDot time derivatives of the state components (null if unknown, in which case Keplerian motion is assumed)
  150.      * @param meanOnly use only the mean elements to build the state
  151.      * @return spacecraft state
  152.      */
  153.     public abstract SpacecraftState mapArrayToState(AbsoluteDate date, double[] y, double[] yDot, boolean meanOnly);

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

  160. }