KeplerianPropagator.java

  1. /* Copyright 2002-2024 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 org.hipparchus.linear.RealMatrix;
  19. import org.orekit.attitudes.Attitude;
  20. import org.orekit.attitudes.AttitudeProvider;
  21. import org.orekit.attitudes.FrameAlignedProvider;
  22. import org.orekit.orbits.Orbit;
  23. import org.orekit.orbits.OrbitType;
  24. import org.orekit.orbits.PositionAngleType;
  25. import org.orekit.propagation.AbstractMatricesHarvester;
  26. import org.orekit.propagation.SpacecraftState;
  27. import org.orekit.time.AbsoluteDate;
  28. import org.orekit.utils.DoubleArrayDictionary;
  29. import org.orekit.utils.TimeSpanMap;

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

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

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

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

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

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

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

  92.         super(attitudeProv);

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

  101.     }

  102.     /** Fix state to use a specified mu and remove derivatives.
  103.      * <p>
  104.      * This ensures the propagation model (which is based on calling
  105.      * {@link Orbit#shiftedBy(double)}) is Keplerian only and uses a specified mu.
  106.      * </p>
  107.      * @param orbit orbit to fix
  108.      * @param attitude current attitude
  109.      * @param mass current mass
  110.      * @param mu gravity coefficient to use
  111.      * @param additionalStates additional states (may be null)
  112.      * @param additionalStatesDerivatives additional states derivatives (may be null)
  113.      * @return fixed orbit
  114.      */
  115.     private SpacecraftState fixState(final Orbit orbit, final Attitude attitude, final double mass, final double mu,
  116.                                      final DoubleArrayDictionary additionalStates,
  117.                                      final DoubleArrayDictionary additionalStatesDerivatives) {
  118.         final OrbitType type = orbit.getType();
  119.         final double[] stateVector = new double[6];
  120.         final PositionAngleType positionAngleType = PositionAngleType.MEAN;
  121.         type.mapOrbitToArray(orbit, positionAngleType, stateVector, null);
  122.         final Orbit fixedOrbit = type.mapArrayToOrbit(stateVector, null, positionAngleType,
  123.                                                       orbit.getDate(), mu, orbit.getFrame());
  124.         SpacecraftState fixedState = new SpacecraftState(fixedOrbit, attitude, mass);
  125.         if (additionalStates != null) {
  126.             for (final DoubleArrayDictionary.Entry entry : additionalStates.getData()) {
  127.                 fixedState = fixedState.addAdditionalState(entry.getKey(), entry.getValue());
  128.             }
  129.         }
  130.         if (additionalStatesDerivatives != null) {
  131.             for (final DoubleArrayDictionary.Entry entry : additionalStatesDerivatives.getData()) {
  132.                 fixedState = fixedState.addAdditionalStateDerivative(entry.getKey(), entry.getValue());
  133.             }
  134.         }
  135.         return fixedState;
  136.     }

  137.     /** {@inheritDoc} */
  138.     public void resetInitialState(final SpacecraftState state) {

  139.         // ensure the orbit use the specified mu and has no non-Keplerian derivatives
  140.         final SpacecraftState formerInitial = getInitialState();
  141.         final double mu = formerInitial == null ? state.getMu() : formerInitial.getMu();
  142.         final SpacecraftState fixedState = fixState(state.getOrbit(),
  143.                                                     state.getAttitude(),
  144.                                                     state.getMass(),
  145.                                                     mu,
  146.                                                     state.getAdditionalStatesValues(),
  147.                                                     state.getAdditionalStatesDerivatives());

  148.         states = new TimeSpanMap<SpacecraftState>(fixedState);
  149.         super.resetInitialState(fixedState);

  150.     }

  151.     /** {@inheritDoc} */
  152.     protected void resetIntermediateState(final SpacecraftState state, final boolean forward) {
  153.         if (forward) {
  154.             states.addValidAfter(state, state.getDate(), false);
  155.         } else {
  156.             states.addValidBefore(state, state.getDate(), false);
  157.         }
  158.         stateChanged(state);
  159.     }

  160.     /** {@inheritDoc} */
  161.     protected Orbit propagateOrbit(final AbsoluteDate date) {

  162.         // propagate orbit
  163.         Orbit orbit = states.get(date).getOrbit();
  164.         do {
  165.             // we use a loop here to compensate for very small date shifts error
  166.             // that occur with long propagation time
  167.             orbit = orbit.shiftedBy(date.durationFrom(orbit.getDate()));
  168.         } while (!date.equals(orbit.getDate()));

  169.         return orbit;

  170.     }

  171.     /** {@inheritDoc}*/
  172.     protected double getMass(final AbsoluteDate date) {
  173.         return states.get(date).getMass();
  174.     }

  175.     /** {@inheritDoc} */
  176.     @Override
  177.     protected AbstractMatricesHarvester createHarvester(final String stmName, final RealMatrix initialStm,
  178.                                                         final DoubleArrayDictionary initialJacobianColumns) {
  179.         // Create the harvester
  180.         final KeplerianHarvester harvester = new KeplerianHarvester(this, stmName, initialStm, initialJacobianColumns);
  181.         // Update the list of additional state provider
  182.         addAdditionalStateProvider(harvester);
  183.         // Return the configured harvester
  184.         return harvester;
  185.     }

  186. }