FieldSpacecraftState.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;


  18. import java.util.ArrayList;
  19. import java.util.Collections;
  20. import java.util.HashMap;
  21. import java.util.List;
  22. import java.util.Map;
  23. import java.util.stream.Stream;

  24. import org.hipparchus.Field;
  25. import org.hipparchus.RealFieldElement;
  26. import org.hipparchus.analysis.interpolation.FieldHermiteInterpolator;
  27. import org.hipparchus.exception.LocalizedCoreFormats;
  28. import org.hipparchus.exception.MathIllegalArgumentException;
  29. import org.hipparchus.exception.MathIllegalStateException;
  30. import org.hipparchus.util.MathArrays;
  31. import org.orekit.attitudes.FieldAttitude;
  32. import org.orekit.attitudes.LofOffset;
  33. import org.orekit.errors.OrekitException;
  34. import org.orekit.errors.OrekitIllegalArgumentException;
  35. import org.orekit.errors.OrekitMessages;
  36. import org.orekit.frames.FieldTransform;
  37. import org.orekit.frames.Frame;
  38. import org.orekit.frames.LOFType;
  39. import org.orekit.orbits.FieldOrbit;
  40. import org.orekit.orbits.PositionAngle;
  41. import org.orekit.time.FieldAbsoluteDate;
  42. import org.orekit.time.FieldTimeInterpolable;
  43. import org.orekit.time.FieldTimeShiftable;
  44. import org.orekit.time.FieldTimeStamped;
  45. import org.orekit.utils.TimeStampedFieldPVCoordinates;


  46. /** This class is the representation of a complete state holding orbit, attitude
  47.  * and mass information at a given date.
  48.  *
  49.  * <p>It contains an {@link FieldOrbit orbital state} at a current
  50.  * {@link FieldAbsoluteDate} both handled by an {@link FieldOrbit}, plus the current
  51.  * mass and attitude. FieldOrbitand state are guaranteed to be consistent in terms
  52.  * of date and reference frame. The spacecraft state may also contain additional
  53.  * states, which are simply named double arrays which can hold any user-defined
  54.  * data.
  55.  * </p>
  56.  * <p>
  57.  * The state can be slightly shifted to close dates. This shift is based on
  58.  * a simple Keplerian model for orbit, a linear extrapolation for attitude
  59.  * taking the spin rate into account and no mass change. It is <em>not</em>
  60.  * intended as a replacement for proper orbit and attitude propagation but
  61.  * should be sufficient for either small time shifts or coarse accuracy.
  62.  * </p>
  63.  * <p>
  64.  * The instance {@code FieldSpacecraftState} is guaranteed to be immutable.
  65.  * </p>
  66.  * @see org.orekit.propagation.numerical.NumericalPropagator
  67.  * @author Fabien Maussion
  68.  * @author V&eacute;ronique Pommier-Maurussane
  69.  * @author Luc Maisonobe
  70.  */
  71. public class FieldSpacecraftState <T extends RealFieldElement<T>>
  72.     implements FieldTimeStamped<T>, FieldTimeShiftable<FieldSpacecraftState<T>, T>, FieldTimeInterpolable<FieldSpacecraftState<T>, T> {

  73.     /** Default mass. */
  74.     private static final double DEFAULT_MASS = 1000.0;

  75.     /**
  76.      * tolerance on date comparison in {@link #checkConsistency(FieldOrbit<T>, FieldAttitude<T>)}. 100 ns
  77.      * corresponds to sub-mm accuracy at LEO orbital velocities.
  78.      */
  79.     private static final double DATE_INCONSISTENCY_THRESHOLD = 100e-9;

  80.     /** Orbital state. */
  81.     private final FieldOrbit<T> orbit;

  82.     /** FieldAttitude<T>. */
  83.     private final FieldAttitude<T> attitude;

  84.     /** Current mass (kg). */
  85.     private final T mass;

  86.     /** Additional states. */
  87.     private final Map<String, T[]> additional;

  88.     /** Build a spacecraft state from orbit only.
  89.      * <p>FieldAttitude<T> and mass are set to unspecified non-null arbitrary values.</p>
  90.      * @param orbit the orbit
  91.      */
  92.     public FieldSpacecraftState(final FieldOrbit<T> orbit) {
  93.         this(orbit,
  94.              new LofOffset(orbit.getFrame(), LOFType.VVLH).getAttitude(orbit, orbit.getDate(), orbit.getFrame()),
  95.              orbit.getA().getField().getZero().add(DEFAULT_MASS), null);
  96.     }

  97.     /** Build a spacecraft state from orbit and attitude provider.
  98.      * <p>Mass is set to an unspecified non-null arbitrary value.</p>
  99.      * @param orbit the orbit
  100.      * @param attitude attitude
  101.      * @exception IllegalArgumentException if orbit and attitude dates
  102.      * or frames are not equal
  103.      */
  104.     public FieldSpacecraftState(final FieldOrbit<T> orbit, final FieldAttitude<T> attitude)
  105.         throws IllegalArgumentException {
  106.         this(orbit, attitude, orbit.getA().getField().getZero().add(DEFAULT_MASS), null);
  107.     }

  108.     /** Create a new instance from orbit and mass.
  109.      * <p>FieldAttitude<T> law is set to an unspecified default attitude.</p>
  110.      * @param orbit the orbit
  111.      * @param mass the mass (kg)
  112.      */
  113.     public FieldSpacecraftState(final FieldOrbit<T> orbit, final T mass) {
  114.         this(orbit,
  115.              new LofOffset(orbit.getFrame(), LOFType.VVLH).getAttitude(orbit, orbit.getDate(), orbit.getFrame()),
  116.              mass, null);
  117.     }

  118.     /** Build a spacecraft state from orbit, attitude provider and mass.
  119.      * @param orbit the orbit
  120.      * @param attitude attitude
  121.      * @param mass the mass (kg)
  122.      * @exception IllegalArgumentException if orbit and attitude dates
  123.      * or frames are not equal
  124.      */
  125.     public FieldSpacecraftState(final FieldOrbit<T> orbit, final FieldAttitude<T> attitude, final T mass)
  126.         throws IllegalArgumentException {
  127.         this(orbit, attitude, mass, null);
  128.     }

  129.     /** Build a spacecraft state from orbit only.
  130.      * <p>FieldAttitude<T> and mass are set to unspecified non-null arbitrary values.</p>
  131.      * @param orbit the orbit
  132.      * @param additional additional states
  133.      */
  134.     public FieldSpacecraftState(final FieldOrbit<T> orbit, final Map<String, T[]> additional) {
  135.         this(orbit,
  136.              new LofOffset(orbit.getFrame(), LOFType.VVLH).getAttitude(orbit, orbit.getDate(), orbit.getFrame()),
  137.              orbit.getA().getField().getZero().add(DEFAULT_MASS), additional);
  138.     }

  139.     /** Build a spacecraft state from orbit and attitude provider.
  140.      * <p>Mass is set to an unspecified non-null arbitrary value.</p>
  141.      * @param orbit the orbit
  142.      * @param attitude attitude
  143.      * @param additional additional states
  144.      * @exception IllegalArgumentException if orbit and attitude dates
  145.      * or frames are not equal
  146.      */
  147.     public FieldSpacecraftState(final FieldOrbit<T> orbit, final FieldAttitude<T> attitude, final Map<String, T[]> additional)
  148.         throws IllegalArgumentException {
  149.         this(orbit, attitude, orbit.getA().getField().getZero().add(DEFAULT_MASS), additional);
  150.     }

  151.     /** Create a new instance from orbit and mass.
  152.      * <p>FieldAttitude<T> law is set to an unspecified default attitude.</p>
  153.      * @param orbit the orbit
  154.      * @param mass the mass (kg)
  155.      * @param additional additional states
  156.      */
  157.     public FieldSpacecraftState(final FieldOrbit<T> orbit, final T mass, final Map<String, T[]> additional) {
  158.         this(orbit,
  159.              new LofOffset(orbit.getFrame(), LOFType.VVLH).getAttitude(orbit, orbit.getDate(), orbit.getFrame()),
  160.              mass, additional);
  161.     }

  162.     /** Build a spacecraft state from orbit, attitude provider and mass.
  163.      * @param orbit the orbit
  164.      * @param attitude attitude
  165.      * @param mass the mass (kg)
  166.      * @param additional additional states (may be null if no additional states are available)
  167.      * @exception IllegalArgumentException if orbit and attitude dates
  168.      * or frames are not equal
  169.      */
  170.     public FieldSpacecraftState(final FieldOrbit<T> orbit, final FieldAttitude<T> attitude,
  171.                                 final T mass, final Map<String, T[]> additional)
  172.         throws IllegalArgumentException {
  173.         checkConsistency(orbit, attitude);
  174.         this.orbit      = orbit;
  175.         this.attitude   = attitude;
  176.         this.mass       = mass;


  177.         if (additional == null) {
  178.             this.additional = Collections.emptyMap();
  179.         } else {

  180.             this.additional = new HashMap<String, T[]>(additional.size());
  181.             for (final Map.Entry<String, T[]> entry : additional.entrySet()) {
  182.                 this.additional.put(entry.getKey(), entry.getValue().clone());
  183.             }
  184.         }
  185.     }

  186.     /** Convert a {@link SpacecraftState}.
  187.      * @param field field to which the elements belong
  188.      * @param state state to convert
  189.      */
  190.     public FieldSpacecraftState(final Field<T> field, final SpacecraftState state) {

  191.         final double[] stateD    = new double[6];
  192.         final double[] stateDotD = state.getOrbit().hasDerivatives() ? new double[6] : null;
  193.         state.getOrbit().getType().mapOrbitToArray(state.getOrbit(), PositionAngle.TRUE, stateD, stateDotD);
  194.         final T[] stateF    = MathArrays.buildArray(field, 6);
  195.         for (int i = 0; i < stateD.length; ++i) {
  196.             stateF[i]    = field.getZero().add(stateD[i]);
  197.         }
  198.         final T[] stateDotF;
  199.         if (stateDotD == null) {
  200.             stateDotF = null;
  201.         } else {
  202.             stateDotF = MathArrays.buildArray(field, 6);
  203.             for (int i = 0; i < stateDotD.length; ++i) {
  204.                 stateDotF[i] = field.getZero().add(stateDotD[i]);
  205.             }
  206.         }

  207.         final FieldAbsoluteDate<T> dateF = new FieldAbsoluteDate<>(field, state.getDate());

  208.         this.orbit    = state.getOrbit().getType().mapArrayToOrbit(stateF, stateDotF,
  209.                                                                    PositionAngle.TRUE,
  210.                                                                    dateF, state.getMu(), state.getFrame());
  211.         this.attitude = new FieldAttitude<>(field, state.getAttitude());
  212.         this.mass     = field.getZero().add(state.getMass());

  213.         final Map<String, double[]> additionalD = state.getAdditionalStates();
  214.         if (additionalD.isEmpty()) {
  215.             this.additional = Collections.emptyMap();
  216.         } else {
  217.             this.additional = new HashMap<String, T[]>(additionalD.size());
  218.             for (final Map.Entry<String, double[]> entry : additionalD.entrySet()) {
  219.                 final T[] array = MathArrays.buildArray(field, entry.getValue().length);
  220.                 for (int k = 0; k < array.length; ++k) {
  221.                     array[k] = field.getZero().add(entry.getValue()[k]);
  222.                 }
  223.                 this.additional.put(entry.getKey(), array);
  224.             }
  225.         }

  226.     }

  227.     /** Add an additional state.
  228.      * <p>
  229.      * {@link FieldSpacecraftState SpacecraftState} instances are immutable,
  230.      * so this method does <em>not</em> change the instance, but rather
  231.      * creates a new instance, which has the same orbit, attitude, mass
  232.      * and additional states as the original instance, except it also
  233.      * has the specified state. If the original instance already had an
  234.      * additional state with the same name, it will be overridden. If it
  235.      * did not have any additional state with that name, the new instance
  236.      * will have one more additional state than the original instance.
  237.      * </p>
  238.      * @param name name of the additional state
  239.      * @param value value of the additional state
  240.      * @return a new instance, with the additional state added
  241.      * @see #hasAdditionalState(String)
  242.      * @see #getAdditionalState(String)
  243.      * @see #getAdditionalStates()
  244.      */
  245.     @SafeVarargs
  246.     public final FieldSpacecraftState<T> addAdditionalState(final String name, final T... value) {
  247.         final Map<String, T[]> newMap = new HashMap<String, T[]>(additional.size() + 1);
  248.         newMap.putAll(additional);
  249.         newMap.put(name, value.clone());
  250.         return new FieldSpacecraftState<>(orbit, attitude, mass, newMap);
  251.     }

  252.     /** Check orbit and attitude dates are equal.
  253.      * @param orbitN the orbit
  254.      * @param attitudeN attitude
  255.      * @exception IllegalArgumentException if orbit and attitude dates
  256.      * are not equal
  257.      */
  258.     private void checkConsistency(final FieldOrbit<T> orbitN, final FieldAttitude<T> attitudeN)
  259.         throws IllegalArgumentException {
  260.         if (orbitN.getDate().durationFrom(attitudeN.getDate()).abs().getReal() >
  261.             DATE_INCONSISTENCY_THRESHOLD) {

  262.             throw new OrekitIllegalArgumentException(OrekitMessages.ORBIT_AND_ATTITUDE_DATES_MISMATCH,
  263.                                                      orbitN.getDate(), attitudeN.getDate());
  264.         }

  265.         if (orbitN.getFrame() != attitudeN.getReferenceFrame()) {
  266.             throw new OrekitIllegalArgumentException(OrekitMessages.FRAMES_MISMATCH,
  267.                                                      orbitN.getFrame().getName(),
  268.                                                      attitudeN.getReferenceFrame().getName());
  269.         }
  270.     }

  271.     /** Get a time-shifted state.
  272.      * <p>
  273.      * The state can be slightly shifted to close dates. This shift is based on
  274.      * a simple Keplerian model for orbit, a linear extrapolation for attitude
  275.      * taking the spin rate into account and neither mass nor additional states
  276.      * changes. It is <em>not</em> intended as a replacement for proper orbit
  277.      * and attitude propagation but should be sufficient for small time shifts
  278.      * or coarse accuracy.
  279.      * </p>
  280.      * <p>
  281.      * As a rough order of magnitude, the following table shows the extrapolation
  282.      * errors obtained between this simple shift method and an {@link
  283.      * org.orekit.propagation.numerical.NumericalPropagator numerical
  284.      * propagator} for a low Earth Sun Synchronous Orbit, with a 20x20 gravity field,
  285.      * Sun and Moon third bodies attractions, drag and solar radiation pressure.
  286.      * Beware that these results will be different for other orbits.
  287.      * </p>
  288.      * <table border="1" cellpadding="5">
  289.      * <caption>Extrapolation Error</caption>
  290.      * <tr bgcolor="#ccccff"><th>interpolation time (s)</th>
  291.      * <th>position error without derivatives (m)</th><th>position error with derivatives (m)</th></tr>
  292.      * <tr><td bgcolor="#eeeeff"> 60</td><td>  18</td><td> 1.1</td></tr>
  293.      * <tr><td bgcolor="#eeeeff">120</td><td>  72</td><td> 9.1</td></tr>
  294.      * <tr><td bgcolor="#eeeeff">300</td><td> 447</td><td> 140</td></tr>
  295.      * <tr><td bgcolor="#eeeeff">600</td><td>1601</td><td>1067</td></tr>
  296.      * <tr><td bgcolor="#eeeeff">900</td><td>3141</td><td>3307</td></tr>
  297.      * </table>
  298.      * @param dt time shift in seconds
  299.      * @return a new state, shifted with respect to the instance (which is immutable)
  300.      * except for the mass which stay unchanged
  301.      */
  302.     public FieldSpacecraftState<T> shiftedBy(final double dt) {
  303.         return new FieldSpacecraftState<>(orbit.shiftedBy(dt), attitude.shiftedBy(dt),
  304.                                           mass, additional);
  305.     }

  306.     /** Get a time-shifted state.
  307.      * <p>
  308.      * The state can be slightly shifted to close dates. This shift is based on
  309.      * a simple Keplerian model for orbit, a linear extrapolation for attitude
  310.      * taking the spin rate into account and neither mass nor additional states
  311.      * changes. It is <em>not</em> intended as a replacement for proper orbit
  312.      * and attitude propagation but should be sufficient for small time shifts
  313.      * or coarse accuracy.
  314.      * </p>
  315.      * <p>
  316.      * As a rough order of magnitude, the following table shows the extrapolation
  317.      * errors obtained between this simple shift method and an {@link
  318.      * org.orekit.propagation.numerical.NumericalPropagator numerical
  319.      * propagator} for a low Earth Sun Synchronous Orbit, with a 20x20 gravity field,
  320.      * Sun and Moon third bodies attractions, drag and solar radiation pressure.
  321.      * Beware that these results will be different for other orbits.
  322.      * </p>
  323.      * <table border="1" cellpadding="5">
  324.      * <caption>Extrapolation Error</caption>
  325.      * <tr bgcolor="#ccccff"><th>interpolation time (s)</th>
  326.      * <th>position error without derivatives (m)</th><th>position error with derivatives (m)</th></tr>
  327.      * <tr><td bgcolor="#eeeeff"> 60</td><td>  18</td><td> 1.1</td></tr>
  328.      * <tr><td bgcolor="#eeeeff">120</td><td>  72</td><td> 9.1</td></tr>
  329.      * <tr><td bgcolor="#eeeeff">300</td><td> 447</td><td> 140</td></tr>
  330.      * <tr><td bgcolor="#eeeeff">600</td><td>1601</td><td>1067</td></tr>
  331.      * <tr><td bgcolor="#eeeeff">900</td><td>3141</td><td>3307</td></tr>
  332.      * </table>
  333.      * @param dt time shift in seconds
  334.      * @return a new state, shifted with respect to the instance (which is immutable)
  335.      * except for the mass which stay unchanged
  336.      */
  337.     public FieldSpacecraftState<T> shiftedBy(final T dt) {
  338.         return new FieldSpacecraftState<>(orbit.shiftedBy(dt), attitude.shiftedBy(dt),
  339.                                           mass, additional);
  340.     }

  341.     /** Get an interpolated instance.
  342.      * <p>
  343.      * The additional states that are interpolated are the ones already present
  344.      * in the instance. The sample instances must therefore have at least the same
  345.      * additional states has the instance. They may have more additional states,
  346.      * but the extra ones will be ignored.
  347.      * </p>
  348.      * <p>
  349.      * As this implementation of interpolation is polynomial, it should be used only
  350.      * with small samples (about 10-20 points) in order to avoid <a
  351.      * href="http://en.wikipedia.org/wiki/Runge%27s_phenomenon">Runge's phenomenon</a>
  352.      * and numerical problems (including NaN appearing).
  353.      * </p>
  354.      * @param date interpolation date
  355.      * @param sample sample points on which interpolation should be done
  356.      * @return a new instance, interpolated at specified date
  357.      */
  358.     public FieldSpacecraftState<T> interpolate(final FieldAbsoluteDate<T> date,
  359.                                                final Stream<FieldSpacecraftState<T>> sample) {

  360.         // prepare interpolators
  361.         final List<FieldOrbit<T>> orbits = new ArrayList<>();
  362.         final List<FieldAttitude<T>> attitudes = new ArrayList<>();
  363.         final FieldHermiteInterpolator<T> massInterpolator = new FieldHermiteInterpolator<>();
  364.         final Map<String, FieldHermiteInterpolator<T>> additionalInterpolators =
  365.                 new HashMap<String, FieldHermiteInterpolator<T>>(additional.size());
  366.         for (final String name : additional.keySet()) {
  367.             additionalInterpolators.put(name, new FieldHermiteInterpolator<>());
  368.         }

  369.         // extract sample data
  370.         sample.forEach(state -> {
  371.             final T deltaT = state.getDate().durationFrom(date);
  372.             orbits.add(state.getOrbit());
  373.             attitudes.add(state.getAttitude());
  374.             final T[] mm = MathArrays.buildArray(orbit.getA().getField(), 1);
  375.             mm[0] = state.getMass();
  376.             massInterpolator.addSamplePoint(deltaT,
  377.                                             mm);
  378.             for (final Map.Entry<String, FieldHermiteInterpolator<T>> entry : additionalInterpolators.entrySet()) {
  379.                 entry.getValue().addSamplePoint(deltaT, state.getAdditionalState(entry.getKey()));
  380.             }
  381.         });

  382.         // perform interpolations
  383.         final FieldOrbit<T> interpolatedOrbit       = orbit.interpolate(date, orbits);
  384.         final FieldAttitude<T> interpolatedAttitude = attitude.interpolate(date, attitudes);
  385.         final T interpolatedMass       = massInterpolator.value(orbit.getA().getField().getZero())[0];
  386.         final Map<String, T[]> interpolatedAdditional;
  387.         if (additional.isEmpty()) {
  388.             interpolatedAdditional = null;
  389.         } else {
  390.             interpolatedAdditional = new HashMap<String, T[]>(additional.size());
  391.             for (final Map.Entry<String, FieldHermiteInterpolator<T>> entry : additionalInterpolators.entrySet()) {
  392.                 interpolatedAdditional.put(entry.getKey(), entry.getValue().value(orbit.getA().getField().getZero()));
  393.             }
  394.         }

  395.         // create the complete interpolated state
  396.         return new FieldSpacecraftState<>(interpolatedOrbit, interpolatedAttitude,
  397.                                           interpolatedMass, interpolatedAdditional);

  398.     }

  399.     /** Gets the current orbit.
  400.      * @return the orbit
  401.      */
  402.     public FieldOrbit<T> getOrbit() {
  403.         return orbit;
  404.     }

  405.     /** Get the date.
  406.      * @return date
  407.      */
  408.     public FieldAbsoluteDate<T> getDate() {
  409.         return orbit.getDate();
  410.     }

  411.     /** Get the inertial frame.
  412.      * @return the frame
  413.      */
  414.     public Frame getFrame() {
  415.         return orbit.getFrame();
  416.     }

  417.     /** Check if an additional state is available.
  418.      * @param name name of the additional state
  419.      * @return true if the additional state is available
  420.      * @see #addAdditionalState(String, RealFieldElement...)
  421.      * @see #getAdditionalState(String)
  422.      * @see #getAdditionalStates()
  423.      */
  424.     public boolean hasAdditionalState(final String name) {
  425.         return additional.containsKey(name);
  426.     }

  427.     /** Check if two instances have the same set of additional states available.
  428.      * <p>
  429.      * Only the names and dimensions of the additional states are compared,
  430.      * not their values.
  431.      * </p>
  432.      * @param state state to compare to instance
  433.      * @exception MathIllegalArgumentException if an additional state does not have
  434.      * the same dimension in both states
  435.      */
  436.     public void ensureCompatibleAdditionalStates(final FieldSpacecraftState<T> state)
  437.         throws MathIllegalArgumentException {

  438.         // check instance additional states is a subset of the other one
  439.         for (final Map.Entry<String, T[]> entry : additional.entrySet()) {
  440.             final T[] other = state.additional.get(entry.getKey());
  441.             if (other == null) {
  442.                 throw new OrekitException(OrekitMessages.UNKNOWN_ADDITIONAL_STATE,
  443.                                           entry.getKey());
  444.             }
  445.             if (other.length != entry.getValue().length) {
  446.                 throw new MathIllegalStateException(LocalizedCoreFormats.DIMENSIONS_MISMATCH,
  447.                                                     other.length, entry.getValue().length);
  448.             }
  449.         }

  450.         if (state.additional.size() > additional.size()) {
  451.             // the other state has more additional states
  452.             for (final String name : state.additional.keySet()) {
  453.                 if (!additional.containsKey(name)) {
  454.                     throw new OrekitException(OrekitMessages.UNKNOWN_ADDITIONAL_STATE,
  455.                                               name);
  456.                 }
  457.             }
  458.         }

  459.     }

  460.     /** Get an additional state.
  461.      * @param name name of the additional state
  462.      * @return value of the additional state
  463.           * @see #addAdditionalState(String, RealFieldElement...)
  464.      * @see #hasAdditionalState(String)
  465.      * @see #getAdditionalStates()
  466.      */
  467.     public T[] getAdditionalState(final String name) {
  468.         if (!additional.containsKey(name)) {
  469.             throw new OrekitException(OrekitMessages.UNKNOWN_ADDITIONAL_STATE, name);
  470.         }
  471.         return additional.get(name).clone();
  472.     }

  473.     /** Get an unmodifiable map of additional states.
  474.      * @return unmodifiable map of additional states
  475.      * @see #addAdditionalState(String, RealFieldElement...)
  476.      * @see #hasAdditionalState(String)
  477.      * @see #getAdditionalState(String)
  478.      */
  479.     public Map<String, T[]> getAdditionalStates() {
  480.         return Collections.unmodifiableMap(additional);
  481.     }

  482.     /** Compute the transform from orbite/attitude reference frame to spacecraft frame.
  483.      * <p>The spacecraft frame origin is at the point defined by the orbit,
  484.      * and its orientation is defined by the attitude.</p>
  485.      * @return transform from specified frame to current spacecraft frame
  486.      */
  487.     public FieldTransform<T> toTransform() {
  488.         final FieldAbsoluteDate<T> date = orbit.getDate();
  489.         return new FieldTransform<>(date,
  490.                                     new FieldTransform<>(date, orbit.getPVCoordinates().negate()),
  491.                                     new FieldTransform<>(date, attitude.getOrientation()));
  492.     }

  493.     /** Get the central attraction coefficient.
  494.      * @return mu central attraction coefficient (m^3/s^2)
  495.      */
  496.     public double getMu() {
  497.         return orbit.getMu();
  498.     }

  499.     /** Get the Keplerian period.
  500.      * <p>The Keplerian period is computed directly from semi major axis
  501.      * and central acceleration constant.</p>
  502.      * @return Keplerian period in seconds
  503.      */
  504.     public T getKeplerianPeriod() {
  505.         return orbit.getKeplerianPeriod();
  506.     }

  507.     /** Get the Keplerian mean motion.
  508.      * <p>The Keplerian mean motion is computed directly from semi major axis
  509.      * and central acceleration constant.</p>
  510.      * @return Keplerian mean motion in radians per second
  511.      */
  512.     public T getKeplerianMeanMotion() {
  513.         return orbit.getKeplerianMeanMotion();
  514.     }

  515.     /** Get the semi-major axis.
  516.      * @return semi-major axis (m)
  517.      */
  518.     public T getA() {
  519.         return orbit.getA();
  520.     }

  521.     /** Get the first component of the eccentricity vector (as per equinoctial parameters).
  522.      * @return e cos(ω + Ω), first component of eccentricity vector
  523.      * @see #getE()
  524.      */
  525.     public T getEquinoctialEx() {
  526.         return orbit.getEquinoctialEx();
  527.     }

  528.     /** Get the second component of the eccentricity vector (as per equinoctial parameters).
  529.      * @return e sin(ω + Ω), second component of the eccentricity vector
  530.      * @see #getE()
  531.      */
  532.     public T getEquinoctialEy() {
  533.         return orbit.getEquinoctialEy();
  534.     }

  535.     /** Get the first component of the inclination vector (as per equinoctial parameters).
  536.      * @return tan(i/2) cos(Ω), first component of the inclination vector
  537.      * @see #getI()
  538.      */
  539.     public T getHx() {
  540.         return orbit.getHx();
  541.     }

  542.     /** Get the second component of the inclination vector (as per equinoctial parameters).
  543.      * @return tan(i/2) sin(Ω), second component of the inclination vector
  544.      * @see #getI()
  545.      */
  546.     public T getHy() {
  547.         return orbit.getHy();
  548.     }

  549.     /** Get the true latitude argument (as per equinoctial parameters).
  550.      * @return v + ω + Ω true latitude argument (rad)
  551.      * @see #getLE()
  552.      * @see #getLM()
  553.      */
  554.     public T getLv() {
  555.         return orbit.getLv();
  556.     }

  557.     /** Get the eccentric latitude argument (as per equinoctial parameters).
  558.      * @return E + ω + Ω eccentric latitude argument (rad)
  559.      * @see #getLv()
  560.      * @see #getLM()
  561.      */
  562.     public T getLE() {
  563.         return orbit.getLE();
  564.     }

  565.     /** Get the mean latitude argument (as per equinoctial parameters).
  566.      * @return M + ω + Ω mean latitude argument (rad)
  567.      * @see #getLv()
  568.      * @see #getLE()
  569.      */
  570.     public T getLM() {
  571.         return orbit.getLM();
  572.     }

  573.     // Additional orbital elements

  574.     /** Get the eccentricity.
  575.      * @return eccentricity
  576.      * @see #getEquinoctialEx()
  577.      * @see #getEquinoctialEy()
  578.      */
  579.     public T getE() {
  580.         return orbit.getE();
  581.     }

  582.     /** Get the inclination.
  583.      * @return inclination (rad)
  584.      * @see #getHx()
  585.      * @see #getHy()
  586.      */
  587.     public T getI() {
  588.         return orbit.getI();
  589.     }

  590.     /** Get the {@link TimeStampedFieldPVCoordinates} in orbit definition frame.
  591.      * Compute the position and velocity of the satellite. This method caches its
  592.      * results, and recompute them only when the method is called with a new value
  593.      * for mu. The result is provided as a reference to the internally cached
  594.      * {@link TimeStampedFieldPVCoordinates}, so the caller is responsible to copy it in a separate
  595.      * {@link TimeStampedFieldPVCoordinates} if it needs to keep the value for a while.
  596.      * @return pvCoordinates in orbit definition frame
  597.      */
  598.     public TimeStampedFieldPVCoordinates<T> getPVCoordinates() {
  599.         return orbit.getPVCoordinates();
  600.     }

  601.     /** Get the {@link TimeStampedFieldPVCoordinates} in given output frame.
  602.      * Compute the position and velocity of the satellite. This method caches its
  603.      * results, and recompute them only when the method is called with a new value
  604.      * for mu. The result is provided as a reference to the internally cached
  605.      * {@link TimeStampedFieldPVCoordinates}, so the caller is responsible to copy it in a separate
  606.      * {@link TimeStampedFieldPVCoordinates} if it needs to keep the value for a while.
  607.      * @param outputFrame frame in which coordinates should be defined
  608.      * @return pvCoordinates in orbit definition frame
  609.      */
  610.     public TimeStampedFieldPVCoordinates<T> getPVCoordinates(final Frame outputFrame) {
  611.         return orbit.getPVCoordinates(outputFrame);
  612.     }

  613.     /** Get the attitude.
  614.      * @return the attitude.
  615.      */
  616.     public FieldAttitude<T> getAttitude() {
  617.         return attitude;
  618.     }

  619.     /** Gets the current mass.
  620.      * @return the mass (kg)
  621.      */
  622.     public T getMass() {
  623.         return mass;
  624.     }

  625.     /**To convert a FieldSpacecraftState instance into a SpacecraftState instance.
  626.      *
  627.      * @return SpacecraftState instance with the same properties
  628.      */
  629.     public SpacecraftState toSpacecraftState() {
  630.         final Map<String, double[]> map;
  631.         if (additional.isEmpty()) {
  632.             map = Collections.emptyMap();
  633.         } else {
  634.             map = new HashMap<>(additional.size());
  635.             for (final Map.Entry<String, T[]> entry : additional.entrySet()) {
  636.                 final double[] array = new double[entry.getValue().length];
  637.                 for (int k = 0; k < array.length; ++k) {
  638.                     array[k] = entry.getValue()[k].getReal();
  639.                 }
  640.                 map.put(entry.getKey(), array);
  641.             }
  642.         }
  643.         return new SpacecraftState(orbit.toOrbit(), attitude.toAttitude(), mass.getReal(), map);
  644.     }

  645. }