AdapterPropagator.java

  1. /* Copyright 2002-2021 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.ArrayList;
  19. import java.util.Collections;
  20. import java.util.List;
  21. import java.util.Map;

  22. import org.orekit.errors.OrekitException;
  23. import org.orekit.errors.OrekitMessages;
  24. import org.orekit.orbits.Orbit;
  25. import org.orekit.propagation.Propagator;
  26. import org.orekit.propagation.SpacecraftState;
  27. import org.orekit.time.AbsoluteDate;

  28. /** Orbit propagator that adapts an underlying propagator, adding {@link
  29.  * DifferentialEffect differential effects}.
  30.  * <p>
  31.  * This propagator is used when a reference propagator does not handle
  32.  * some effects that we need. A typical example would be an ephemeris
  33.  * that was computed for a reference orbit, and we want to compute a
  34.  * station-keeping maneuver on top of this ephemeris, changing its
  35.  * final state. The principal is to add one or more {@link
  36.  * org.orekit.forces.maneuvers.SmallManeuverAnalyticalModel small maneuvers
  37.  * analytical models} to it and use it as a new propagator, which takes the
  38.  * maneuvers into account.
  39.  * </p>
  40.  * <p>
  41.  * From a space flight dynamics point of view, this is a differential
  42.  * correction approach. From a computer science point of view, this is
  43.  * a use of the decorator design pattern.
  44.  * </p>
  45.  * @see Propagator
  46.  * @see org.orekit.forces.maneuvers.SmallManeuverAnalyticalModel
  47.  * @author Luc Maisonobe
  48.  */
  49. public class AdapterPropagator extends AbstractAnalyticalPropagator {

  50.     /** Interface for orbit differential effects. */
  51.     public interface DifferentialEffect {

  52.         /** Apply the effect to a {@link SpacecraftState spacecraft state}.
  53.          * <p>
  54.          * Applying the effect may be a no-op in some cases. A typical example
  55.          * is maneuvers, for which the state is changed only for time <em>after</em>
  56.          * the maneuver occurrence.
  57.          * </p>
  58.          * @param original original state <em>without</em> the effect
  59.          * @return updated state at the same date, taking the effect
  60.          * into account if meaningful
  61.          */
  62.         SpacecraftState apply(SpacecraftState original);

  63.     }

  64.     /** Underlying reference propagator. */
  65.     private Propagator reference;

  66.     /** Effects to add. */
  67.     private List<DifferentialEffect> effects;

  68.     /** Build a propagator from an underlying reference propagator.
  69.      * <p>The reference propagator can be almost anything, numerical,
  70.      * analytical, and even an ephemeris. It may already take some maneuvers
  71.      * into account.</p>
  72.      * @param reference reference propagator
  73.      */
  74.     public AdapterPropagator(final Propagator reference) {
  75.         super(reference.getAttitudeProvider());
  76.         this.reference = reference;
  77.         this.effects = new ArrayList<DifferentialEffect>();
  78.     }

  79.     /** Add a differential effect.
  80.      * @param effect differential effect
  81.      */
  82.     public void addEffect(final DifferentialEffect effect) {
  83.         effects.add(effect);
  84.     }

  85.     /** Get the reference propagator.
  86.      * @return reference propagator
  87.      */
  88.     public Propagator getPropagator() {
  89.         return reference;
  90.     }

  91.     /** Get the differential effects.
  92.      * @return differential effects models, as an unmodifiable list
  93.      */
  94.     public List<DifferentialEffect> getEffects() {
  95.         return Collections.unmodifiableList(effects);
  96.     }

  97.     /** {@inheritDoc} */
  98.     public SpacecraftState getInitialState() {
  99.         return reference.getInitialState();
  100.     }

  101.     /** {@inheritDoc} */
  102.     @Override
  103.     public void resetInitialState(final SpacecraftState state) {
  104.         reference.resetInitialState(state);
  105.     }

  106.     /** {@inheritDoc} */
  107.     protected void resetIntermediateState(final SpacecraftState state, final boolean forward) {
  108.         if (reference instanceof AbstractAnalyticalPropagator) {
  109.             ((AbstractAnalyticalPropagator) reference).resetIntermediateState(state, forward);
  110.         } else {
  111.             throw new OrekitException(OrekitMessages.NON_RESETABLE_STATE);
  112.         }
  113.     }

  114.     /** {@inheritDoc} */
  115.     @Override
  116.     protected SpacecraftState basicPropagate(final AbsoluteDate date) {

  117.         // compute reference state
  118.         SpacecraftState state = reference.propagate(date);
  119.         final Map<String, double[]> before = state.getAdditionalStates();

  120.         // add all the effects
  121.         for (final DifferentialEffect effect : effects) {
  122.             state = effect.apply(state);
  123.         }

  124.         // forward additional states from the reference propagator
  125.         for (final Map.Entry<String, double[]> entry : before.entrySet()) {
  126.             if (!state.hasAdditionalState(entry.getKey())) {
  127.                 state = state.addAdditionalState(entry.getKey(), entry.getValue());
  128.             }
  129.         }

  130.         return state;

  131.     }

  132.     /** {@inheritDoc} */
  133.     protected Orbit propagateOrbit(final AbsoluteDate date) {
  134.         return basicPropagate(date).getOrbit();
  135.     }

  136.     /** {@inheritDoc}*/
  137.     protected double getMass(final AbsoluteDate date) {
  138.         return basicPropagate(date).getMass();
  139.     }

  140. }