FieldKeplerianPropagator.java

  1. /* Copyright 2002-2022 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.List;

  20. import org.hipparchus.CalculusFieldElement;
  21. import org.hipparchus.util.MathArrays;
  22. import org.orekit.attitudes.AttitudeProvider;
  23. import org.orekit.attitudes.FieldAttitude;
  24. import org.orekit.attitudes.InertialProvider;
  25. import org.orekit.orbits.FieldOrbit;
  26. import org.orekit.orbits.Orbit;
  27. import org.orekit.orbits.OrbitType;
  28. import org.orekit.orbits.PositionAngle;
  29. import org.orekit.propagation.FieldSpacecraftState;
  30. import org.orekit.time.FieldAbsoluteDate;
  31. import org.orekit.utils.FieldArrayDictionary;
  32. import org.orekit.utils.FieldTimeSpanMap;
  33. import org.orekit.utils.ParameterDriver;

  34. /** Simple Keplerian orbit propagator.
  35.  * @see FieldOrbit
  36.  * @author Guylaine Prat
  37.  */
  38. public class FieldKeplerianPropagator<T extends CalculusFieldElement<T>> extends FieldAbstractAnalyticalPropagator<T> {


  39.     /** All states. */
  40.     private transient FieldTimeSpanMap<FieldSpacecraftState<T>, T> states;

  41.     /** Build a propagator from orbit only.
  42.      * <p>The central attraction coefficient μ is set to the same value used
  43.      * for the initial orbit definition. Mass and attitude provider are set to
  44.      * unspecified non-null arbitrary values.</p>
  45.      *
  46.      * @param initialFieldOrbit initial orbit
  47.      * @see #FieldKeplerianPropagator(FieldOrbit, AttitudeProvider)
  48.      */
  49.     public FieldKeplerianPropagator(final FieldOrbit<T> initialFieldOrbit) {
  50.         this(initialFieldOrbit, InertialProvider.of(initialFieldOrbit.getFrame()),
  51.                 initialFieldOrbit.getMu(), initialFieldOrbit.getA().getField().getZero().add(DEFAULT_MASS));
  52.     }

  53.     /** Build a propagator from orbit and central attraction coefficient μ.
  54.      * <p>Mass and attitude provider are set to unspecified non-null arbitrary values.</p>
  55.      *
  56.      * @param initialFieldOrbit initial orbit
  57.      * @param mu central attraction coefficient (m³/s²)
  58.      * @see #FieldKeplerianPropagator(FieldOrbit, AttitudeProvider, CalculusFieldElement)
  59.      */
  60.     public FieldKeplerianPropagator(final FieldOrbit<T> initialFieldOrbit, final T mu) {
  61.         this(initialFieldOrbit, InertialProvider.of(initialFieldOrbit.getFrame()),
  62.                 mu, initialFieldOrbit.getA().getField().getZero().add(DEFAULT_MASS));
  63.     }

  64.     /** Build a propagator from orbit and attitude provider.
  65.      * <p>The central attraction coefficient μ is set to the same value
  66.      * used for the initial orbit definition. Mass is set to an unspecified
  67.      * non-null arbitrary value.</p>
  68.      * @param initialFieldOrbit initial orbit
  69.      * @param attitudeProv  attitude provider
  70.      */
  71.     public FieldKeplerianPropagator(final FieldOrbit<T> initialFieldOrbit,
  72.                                     final AttitudeProvider attitudeProv) {
  73.         this(initialFieldOrbit, attitudeProv, initialFieldOrbit.getMu(), initialFieldOrbit.getA().getField().getZero().add(DEFAULT_MASS));
  74.     }

  75.     /** Build a propagator from orbit, attitude provider and central attraction
  76.      * coefficient μ.
  77.      * <p>Mass is set to an unspecified non-null arbitrary value.</p>
  78.      * @param initialFieldOrbit initial orbit
  79.      * @param attitudeProv attitude provider
  80.      * @param mu central attraction coefficient (m³/s²)
  81.      */
  82.     public FieldKeplerianPropagator(final FieldOrbit<T> initialFieldOrbit,
  83.                                     final AttitudeProvider attitudeProv,
  84.                                     final T mu) {
  85.         this(initialFieldOrbit, attitudeProv, mu, initialFieldOrbit.getA().getField().getZero().add(DEFAULT_MASS));
  86.     }

  87.     /** Build propagator from orbit, attitude provider, central attraction
  88.      * coefficient μ and mass.
  89.      * @param initialOrbit initial orbit
  90.      * @param attitudeProv attitude provider
  91.      * @param mu central attraction coefficient (m³/s²)
  92.      * @param mass spacecraft mass (kg)
  93.      */
  94.     public FieldKeplerianPropagator(final FieldOrbit<T> initialOrbit, final AttitudeProvider attitudeProv,
  95.                                     final T mu, final T mass) {

  96.         super(initialOrbit.getA().getField(), attitudeProv);

  97.         // ensure the orbit use the specified mu and has no non-Keplerian derivatives
  98.         final FieldSpacecraftState<T> initial = fixState(initialOrbit,
  99.                                                          getAttitudeProvider().getAttitude(initialOrbit,
  100.                                                                                            initialOrbit.getDate(),
  101.                                                                                            initialOrbit.getFrame()),
  102.                                                          mass, mu, null, null);
  103.         states = new FieldTimeSpanMap<>(initial, initialOrbit.getA().getField());
  104.         super.resetInitialState(initial);
  105.     }

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

  140.     /** {@inheritDoc} */
  141.     public void resetInitialState(final FieldSpacecraftState<T> state) {

  142.         // ensure the orbit use the specified mu and has no non-Keplerian derivatives
  143.         final FieldSpacecraftState<T> formerInitial = getInitialState();
  144.         final T mu = formerInitial == null ? state.getMu() : formerInitial.getMu();
  145.         final FieldSpacecraftState<T> fixedState = fixState(state.getOrbit(),
  146.                                                             state.getAttitude(),
  147.                                                             state.getMass(),
  148.                                                             mu,
  149.                                                             state.getAdditionalStatesValues(),
  150.                                                             state.getAdditionalStatesDerivatives());

  151.         states = new FieldTimeSpanMap<>(fixedState, state.getDate().getField());
  152.         super.resetInitialState(fixedState);

  153.     }

  154.     /** {@inheritDoc} */
  155.     protected void resetIntermediateState(final FieldSpacecraftState<T> state, final boolean forward) {
  156.         if (forward) {
  157.             states.addValidAfter(state, state.getDate());
  158.         } else {
  159.             states.addValidBefore(state, state.getDate());
  160.         }
  161.         stateChanged(state);
  162.     }

  163.     /** {@inheritDoc} */
  164.     protected FieldOrbit<T> propagateOrbit(final FieldAbsoluteDate<T> date, final T[] parameters) {
  165.         // propagate orbit
  166.         FieldOrbit<T> orbit = states.get(date).getOrbit();
  167.         do {
  168.             // we use a loop here to compensate for very small date shifts error
  169.             // that occur with long propagation time
  170.             orbit = orbit.shiftedBy(date.durationFrom(orbit.getDate()));
  171.         } while (!date.equals(orbit.getDate()));
  172.         return orbit;
  173.     }

  174.     /** {@inheritDoc}*/
  175.     protected T getMass(final FieldAbsoluteDate<T> date) {
  176.         return states.get(date).getMass();
  177.     }

  178.     /** {@inheritDoc} */
  179.     @Override
  180.     protected List<ParameterDriver> getParametersDrivers() {
  181.         // Keplerian propagation model does not have parameter drivers.
  182.         return Collections.emptyList();
  183.     }

  184. }