KeplerianPropagator.java

  1. /* Copyright 2002-2021 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.analytical;

  18. import java.util.Collections;
  19. import java.util.Map;

  20. import org.orekit.attitudes.Attitude;
  21. import org.orekit.attitudes.AttitudeProvider;
  22. import org.orekit.attitudes.InertialProvider;
  23. import org.orekit.orbits.Orbit;
  24. import org.orekit.orbits.OrbitType;
  25. import org.orekit.orbits.PositionAngle;
  26. import org.orekit.propagation.SpacecraftState;
  27. import org.orekit.time.AbsoluteDate;
  28. import org.orekit.utils.TimeSpanMap;

  29. /** Simple Keplerian orbit propagator.
  30.  * @see Orbit
  31.  * @author Guylaine Prat
  32.  */
  33. public class KeplerianPropagator extends AbstractAnalyticalPropagator {

  34.     /** All states. */
  35.     private TimeSpanMap<SpacecraftState> states;

  36.     /** Build a propagator from orbit only.
  37.      * <p>The central attraction coefficient μ is set to the same value used
  38.      * for the initial orbit definition. Mass and attitude provider are set to
  39.      * unspecified non-null arbitrary values.</p>
  40.      *
  41.      * @param initialOrbit initial orbit
  42.      * @see #KeplerianPropagator(Orbit, AttitudeProvider)
  43.      */
  44.     public KeplerianPropagator(final Orbit initialOrbit) {
  45.         this(initialOrbit, InertialProvider.of(initialOrbit.getFrame()),
  46.                 initialOrbit.getMu(), DEFAULT_MASS);
  47.     }

  48.     /** Build a propagator from orbit and central attraction coefficient μ.
  49.      * <p>Mass and attitude provider are set to unspecified non-null arbitrary values.</p>
  50.      *
  51.      * @param initialOrbit initial orbit
  52.      * @param mu central attraction coefficient (m³/s²)
  53.      * @see #KeplerianPropagator(Orbit, AttitudeProvider, double)
  54.      */
  55.     public KeplerianPropagator(final Orbit initialOrbit, final double mu) {
  56.         this(initialOrbit, InertialProvider.of(initialOrbit.getFrame()),
  57.                 mu, DEFAULT_MASS);
  58.     }

  59.     /** Build a propagator from orbit and attitude provider.
  60.      * <p>The central attraction coefficient μ is set to the same value
  61.      * used for the initial orbit definition. Mass is set to an unspecified
  62.      * non-null arbitrary value.</p>
  63.      * @param initialOrbit initial orbit
  64.      * @param attitudeProv  attitude provider
  65.      */
  66.     public KeplerianPropagator(final Orbit initialOrbit,
  67.                                final AttitudeProvider attitudeProv) {
  68.         this(initialOrbit, attitudeProv, initialOrbit.getMu(), DEFAULT_MASS);
  69.     }

  70.     /** Build a propagator from orbit, attitude provider and central attraction
  71.      * coefficient μ.
  72.      * <p>Mass is set to an unspecified non-null arbitrary value.</p>
  73.      * @param initialOrbit initial orbit
  74.      * @param attitudeProv attitude provider
  75.      * @param mu central attraction coefficient (m³/s²)
  76.      */
  77.     public KeplerianPropagator(final Orbit initialOrbit,
  78.                                final AttitudeProvider attitudeProv,
  79.                                final double mu) {
  80.         this(initialOrbit, attitudeProv, mu, DEFAULT_MASS);
  81.     }

  82.     /** Build propagator from orbit, attitude provider, central attraction
  83.      * coefficient μ and mass.
  84.      * @param initialOrbit initial orbit
  85.      * @param attitudeProv attitude provider
  86.      * @param mu central attraction coefficient (m³/s²)
  87.      * @param mass spacecraft mass (kg)
  88.      */
  89.     public KeplerianPropagator(final Orbit initialOrbit, final AttitudeProvider attitudeProv,
  90.                                final double mu, final double mass) {

  91.         super(attitudeProv);

  92.         // ensure the orbit use the specified mu and has no non-Keplerian derivatives
  93.         final SpacecraftState initial = fixState(initialOrbit,
  94.                                                  getAttitudeProvider().getAttitude(initialOrbit,
  95.                                                                                    initialOrbit.getDate(),
  96.                                                                                    initialOrbit.getFrame()),
  97.                                                  mass, mu, Collections.emptyMap());
  98.         states = new TimeSpanMap<SpacecraftState>(initial);
  99.         super.resetInitialState(initial);

  100.     }

  101.     /** Fix state to use a specified mu and remove derivatives.
  102.      * <p>
  103.      * This ensures the propagation model (which is based on calling
  104.      * {@link Orbit#shiftedBy(double)}) is Keplerian only and uses a specified mu.
  105.      * </p>
  106.      * @param orbit orbit to fix
  107.      * @param attitude current attitude
  108.      * @param mass current mass
  109.      * @param mu gravity coefficient to use
  110.      * @param additionalStates additional states
  111.      * @return fixed orbit
  112.      */
  113.     private SpacecraftState fixState(final Orbit orbit, final Attitude attitude, final double mass,
  114.                                      final double mu, final Map<String, double[]> additionalStates) {
  115.         final OrbitType type = orbit.getType();
  116.         final double[] stateVector = new double[6];
  117.         type.mapOrbitToArray(orbit, PositionAngle.TRUE, stateVector, null);
  118.         final Orbit fixedOrbit = type.mapArrayToOrbit(stateVector, null, PositionAngle.TRUE,
  119.                                                       orbit.getDate(), mu, orbit.getFrame());
  120.         SpacecraftState fixedState = new SpacecraftState(fixedOrbit, attitude, mass);
  121.         for (final Map.Entry<String, double[]> entry : additionalStates.entrySet()) {
  122.             fixedState = fixedState.addAdditionalState(entry.getKey(), entry.getValue());
  123.         }
  124.         return fixedState;
  125.     }

  126.     /** {@inheritDoc} */
  127.     public void resetInitialState(final SpacecraftState state) {

  128.         // ensure the orbit use the specified mu and has no non-Keplerian derivatives
  129.         final SpacecraftState formerInitial = getInitialState();
  130.         final double mu = formerInitial == null ? state.getMu() : formerInitial.getMu();
  131.         final SpacecraftState fixedState = fixState(state.getOrbit(),
  132.                                                     state.getAttitude(),
  133.                                                     state.getMass(),
  134.                                                     mu,
  135.                                                     state.getAdditionalStates());

  136.         states = new TimeSpanMap<SpacecraftState>(fixedState);
  137.         super.resetInitialState(fixedState);

  138.     }

  139.     /** {@inheritDoc} */
  140.     protected void resetIntermediateState(final SpacecraftState state, final boolean forward) {
  141.         if (forward) {
  142.             states.addValidAfter(state, state.getDate());
  143.         } else {
  144.             states.addValidBefore(state, state.getDate());
  145.         }
  146.         stateChanged(state);
  147.     }

  148.     /** {@inheritDoc} */
  149.     protected Orbit propagateOrbit(final AbsoluteDate date) {

  150.         // propagate orbit
  151.         Orbit orbit = states.get(date).getOrbit();
  152.         do {
  153.             // we use a loop here to compensate for very small date shifts error
  154.             // that occur with long propagation time
  155.             orbit = orbit.shiftedBy(date.durationFrom(orbit.getDate()));
  156.         } while (!date.equals(orbit.getDate()));

  157.         return orbit;

  158.     }

  159.     /** {@inheritDoc}*/
  160.     protected double getMass(final AbsoluteDate date) {
  161.         return states.get(date).getMass();
  162.     }

  163. }