FieldKeplerianPropagator.java

  1. /* Copyright 2002-2019 CS Systèmes d'Information
  2.  * Licensed to CS Systèmes d'Information (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.RealFieldElement;
  19. import org.hipparchus.util.MathArrays;
  20. import org.orekit.attitudes.AttitudeProvider;
  21. import org.orekit.attitudes.FieldAttitude;
  22. import org.orekit.orbits.FieldOrbit;
  23. import org.orekit.orbits.Orbit;
  24. import org.orekit.orbits.OrbitType;
  25. import org.orekit.orbits.PositionAngle;
  26. import org.orekit.propagation.FieldSpacecraftState;
  27. import org.orekit.time.FieldAbsoluteDate;
  28. import org.orekit.utils.FieldTimeSpanMap;

  29. /** Simple Keplerian orbit propagator.
  30.  * @see FieldOrbit
  31.  * @author Guylaine Prat
  32.  */
  33. public class FieldKeplerianPropagator<T extends RealFieldElement<T>> extends FieldAbstractAnalyticalPropagator<T> {


  34.     /** Initial state. */
  35.     private FieldSpacecraftState<T> initialState;

  36.     /** All states. */
  37.     private transient FieldTimeSpanMap<FieldSpacecraftState<T>, T> states;

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

  47.     /** Build a propagator from orbit and central attraction coefficient μ.
  48.      * <p>Mass and attitude provider are set to unspecified non-null arbitrary values.</p>
  49.      * @param initialFieldOrbit initial orbit
  50.      * @param mu central attraction coefficient (m³/s²)
  51.      */
  52.     public FieldKeplerianPropagator(final FieldOrbit<T> initialFieldOrbit, final double mu) {
  53.         this(initialFieldOrbit, DEFAULT_LAW, mu, initialFieldOrbit.getA().getField().getZero().add(DEFAULT_MASS));
  54.     }

  55.     /** Build a propagator from orbit and attitude provider.
  56.      * <p>The central attraction coefficient μ is set to the same value
  57.      * used for the initial orbit definition. Mass is set to an unspecified
  58.      * non-null arbitrary value.</p>
  59.      * @param initialFieldOrbit initial orbit
  60.      * @param attitudeProv  attitude provider
  61.      */
  62.     public FieldKeplerianPropagator(final FieldOrbit<T> initialFieldOrbit,
  63.                                     final AttitudeProvider attitudeProv) {
  64.         this(initialFieldOrbit, attitudeProv, initialFieldOrbit.getMu(), initialFieldOrbit.getA().getField().getZero().add(DEFAULT_MASS));
  65.     }

  66.     /** Build a propagator from orbit, attitude provider and central attraction
  67.      * coefficient μ.
  68.      * <p>Mass is set to an unspecified non-null arbitrary value.</p>
  69.      * @param initialFieldOrbit initial orbit
  70.      * @param attitudeProv attitude provider
  71.      * @param mu central attraction coefficient (m³/s²)
  72.      */
  73.     public FieldKeplerianPropagator(final FieldOrbit<T> initialFieldOrbit,
  74.                                     final AttitudeProvider attitudeProv,
  75.                                     final double mu) {
  76.         this(initialFieldOrbit, attitudeProv, mu, initialFieldOrbit.getA().getField().getZero().add(DEFAULT_MASS));
  77.     }

  78.     /** Build propagator from orbit, attitude provider, central attraction
  79.      * coefficient μ and mass.
  80.      * @param initialOrbit initial orbit
  81.      * @param attitudeProv attitude provider
  82.      * @param mu central attraction coefficient (m³/s²)
  83.      * @param mass spacecraft mass (kg)
  84.      */
  85.     public FieldKeplerianPropagator(final FieldOrbit<T> initialOrbit, final AttitudeProvider attitudeProv,
  86.                                     final double mu, final T mass) {

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

  88.         // ensure the orbit use the specified mu and has no non-Keplerian derivatives
  89.         initialState = fixState(initialOrbit,
  90.                                 getAttitudeProvider().getAttitude(initialOrbit,
  91.                                                                   initialOrbit.getDate(),
  92.                                                                   initialOrbit.getFrame()),
  93.                                 mass, mu);
  94.         states = new FieldTimeSpanMap<>(initialState, initialOrbit.getA().getField());
  95.         super.resetInitialState(initialState);
  96.     }

  97.     /** Fix state to use a specified mu and remove derivatives.
  98.      * <p>
  99.      * This ensures the propagation model (which is based on calling
  100.      * {@link Orbit#shiftedBy(double)}) is Keplerian only and uses a specified mu.
  101.      * </p>
  102.      * @param orbit orbit to fix
  103.      * @param attitude current attitude
  104.      * @param mass current mass
  105.      * @param mu gravity coefficient to use
  106.      * @return fixed orbit
  107.      */
  108.     private FieldSpacecraftState<T> fixState(final FieldOrbit<T> orbit, final FieldAttitude<T> attitude, final T mass,
  109.                                      final double mu) {
  110.         final OrbitType type = orbit.getType();
  111.         final T[] stateVector = MathArrays.buildArray(mass.getField(), 6);
  112.         type.mapOrbitToArray(orbit, PositionAngle.TRUE, stateVector, null);
  113.         final FieldOrbit<T> fixedOrbit = type.mapArrayToOrbit(stateVector, null, PositionAngle.TRUE,
  114.                                                               orbit.getDate(), mu, orbit.getFrame());
  115.         return new FieldSpacecraftState<>(fixedOrbit, attitude, mass);
  116.     }

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

  119.         // ensure the orbit use the specified mu and has no non-Keplerian derivatives
  120.         final double mu = initialState == null ? state.getMu() : initialState.getMu();
  121.         final FieldSpacecraftState<T> fixedState = fixState(state.getOrbit(),
  122.                                                             state.getAttitude(),
  123.                                                             state.getMass(),
  124.                                                             mu);

  125.         initialState = fixedState;
  126.         states       = new FieldTimeSpanMap<>(initialState, state.getDate().getField());
  127.         super.resetInitialState(fixedState);

  128.     }

  129.     /** {@inheritDoc} */
  130.     protected void resetIntermediateState(final FieldSpacecraftState<T> state, final boolean forward) {
  131.         if (forward) {
  132.             states.addValidAfter(state, state.getDate());
  133.         } else {
  134.             states.addValidBefore(state, state.getDate());
  135.         }
  136.     }

  137.     /** {@inheritDoc} */
  138.     protected FieldOrbit<T> propagateOrbit(final FieldAbsoluteDate<T> date) {
  139.         // propagate orbit
  140.         FieldOrbit<T> orbit = states.get(date).getOrbit();
  141.         do {
  142.             // we use a loop here to compensate for very small date shifts error
  143.             // that occur with long propagation time
  144.             orbit = orbit.shiftedBy(date.durationFrom(orbit.getDate()));
  145.         } while (!date.equals(orbit.getDate()));
  146.         return orbit;
  147.     }

  148.     /** {@inheritDoc}*/
  149.     protected T getMass(final FieldAbsoluteDate<T> date) {
  150.         return states.get(date).getMass();
  151.     }

  152. }