FieldKeplerianPropagator.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 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.FrameAlignedProvider;
  25. import org.orekit.orbits.FieldOrbit;
  26. import org.orekit.orbits.Orbit;
  27. import org.orekit.orbits.OrbitType;
  28. import org.orekit.orbits.PositionAngleType;
  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.  * @param <T> type of the field elements
  38.  */
  39. public class FieldKeplerianPropagator<T extends CalculusFieldElement<T>> extends FieldAbstractAnalyticalPropagator<T> {


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

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

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

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

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

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

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

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

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

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

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

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

  154.     }

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

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

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

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

  185. }