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().newInstance(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().newInstance(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(),
  75.                 initialFieldOrbit.getA().getField().getZero().newInstance(DEFAULT_MASS));
  76.     }

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

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

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

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

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

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

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

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

  156.     }

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

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

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

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

  187. }