FieldKeplerianPropagator.java

  1. /* Copyright 2002-2020 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.hipparchus.RealFieldElement;
  21. import org.hipparchus.util.MathArrays;
  22. import org.orekit.annotation.DefaultDataContext;
  23. import org.orekit.attitudes.AttitudeProvider;
  24. import org.orekit.attitudes.FieldAttitude;
  25. import org.orekit.data.DataContext;
  26. import org.orekit.orbits.FieldOrbit;
  27. import org.orekit.orbits.Orbit;
  28. import org.orekit.orbits.OrbitType;
  29. import org.orekit.orbits.PositionAngle;
  30. import org.orekit.propagation.FieldSpacecraftState;
  31. import org.orekit.propagation.Propagator;
  32. import org.orekit.time.FieldAbsoluteDate;
  33. import org.orekit.utils.FieldTimeSpanMap;

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


  39.     /** Initial state. */
  40.     private FieldSpacecraftState<T> initialState;

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

  43.     /** Build a propagator from orbit only.
  44.      * <p>The central attraction coefficient μ is set to the same value used
  45.      * for the initial orbit definition. Mass and attitude provider are set to
  46.      * unspecified non-null arbitrary values.</p>
  47.      *
  48.      * <p>This constructor uses the {@link DataContext#getDefault() default data context}.
  49.      *
  50.      * @param initialFieldOrbit initial orbit
  51.      * @see #FieldKeplerianPropagator(FieldOrbit, AttitudeProvider)
  52.      */
  53.     @DefaultDataContext
  54.     public FieldKeplerianPropagator(final FieldOrbit<T> initialFieldOrbit) {
  55.         this(initialFieldOrbit, Propagator.getDefaultLaw(DataContext.getDefault().getFrames()),
  56.                 initialFieldOrbit.getMu(), initialFieldOrbit.getA().getField().getZero().add(DEFAULT_MASS));
  57.     }

  58.     /** Build a propagator from orbit and central attraction coefficient μ.
  59.      * <p>Mass and attitude provider are set to unspecified non-null arbitrary values.</p>
  60.      *
  61.      * <p>This constructor uses the {@link DataContext#getDefault() default data context}.
  62.      *
  63.      * @param initialFieldOrbit initial orbit
  64.      * @param mu central attraction coefficient (m³/s²)
  65.      * @see #FieldKeplerianPropagator(FieldOrbit, AttitudeProvider, RealFieldElement)
  66.      */
  67.     @DefaultDataContext
  68.     public FieldKeplerianPropagator(final FieldOrbit<T> initialFieldOrbit, final T mu) {
  69.         this(initialFieldOrbit, Propagator.getDefaultLaw(DataContext.getDefault().getFrames()),
  70.                 mu, initialFieldOrbit.getA().getField().getZero().add(DEFAULT_MASS));
  71.     }

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

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

  95.     /** Build propagator from orbit, attitude provider, central attraction
  96.      * coefficient μ and mass.
  97.      * @param initialOrbit initial orbit
  98.      * @param attitudeProv attitude provider
  99.      * @param mu central attraction coefficient (m³/s²)
  100.      * @param mass spacecraft mass (kg)
  101.      */
  102.     public FieldKeplerianPropagator(final FieldOrbit<T> initialOrbit, final AttitudeProvider attitudeProv,
  103.                                     final T mu, final T mass) {

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

  105.         // ensure the orbit use the specified mu and has no non-Keplerian derivatives
  106.         initialState = fixState(initialOrbit,
  107.                                 getAttitudeProvider().getAttitude(initialOrbit,
  108.                                                                   initialOrbit.getDate(),
  109.                                                                   initialOrbit.getFrame()),
  110.                                 mass, mu, Collections.emptyMap());
  111.         states = new FieldTimeSpanMap<>(initialState, initialOrbit.getA().getField());
  112.         super.resetInitialState(initialState);
  113.     }

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

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

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

  148.         initialState = fixedState;
  149.         states       = new FieldTimeSpanMap<>(initialState, state.getDate().getField());
  150.         super.resetInitialState(fixedState);

  151.     }

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

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

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

  176. }