AggregateBoundedPropagator.java

  1. /* Contributed in the public domain.
  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 java.util.Collection;
  19. import java.util.Map.Entry;
  20. import java.util.NavigableMap;
  21. import java.util.TreeMap;

  22. import org.orekit.errors.OrekitException;
  23. import org.orekit.errors.OrekitMessages;
  24. import org.orekit.frames.Frame;
  25. import org.orekit.orbits.Orbit;
  26. import org.orekit.propagation.BoundedPropagator;
  27. import org.orekit.propagation.SpacecraftState;
  28. import org.orekit.time.AbsoluteDate;
  29. import org.orekit.utils.TimeStampedPVCoordinates;

  30. /**
  31.  * A {@link BoundedPropagator} that covers a larger time span from several constituent
  32.  * propagators that cover shorter time spans.
  33.  *
  34.  * @author Evan Ward
  35.  * @see #AggregateBoundedPropagator(Collection)
  36.  */
  37. public class AggregateBoundedPropagator extends AbstractAnalyticalPropagator
  38.         implements BoundedPropagator {

  39.     /** Constituent propagators. */
  40.     private final NavigableMap<AbsoluteDate, BoundedPropagator> propagators;

  41.     /**
  42.      * Create a propagator by concatenating several {@link BoundedPropagator}s.
  43.      *
  44.      * @param propagators that provide the backing data for this instance. There must be
  45.      *                    at least one propagator in the collection. If there are gaps
  46.      *                    between the {@link BoundedPropagator#getMaxDate()} of one
  47.      *                    propagator and the {@link BoundedPropagator#getMinDate()} of the
  48.      *                    next propagator an exception may be thrown by any method of this
  49.      *                    class at any time. If there are overlaps between the the {@link
  50.      *                    BoundedPropagator#getMaxDate()} of one propagator and the {@link
  51.      *                    BoundedPropagator#getMinDate()} of the next propagator then the
  52.      *                    propagator with the latest {@link BoundedPropagator#getMinDate()}
  53.      *                    is used.
  54.      * @throws OrekitException if {@code propagators} does not have at least one element.
  55.      */
  56.     public AggregateBoundedPropagator(
  57.             final Collection<? extends BoundedPropagator> propagators) throws OrekitException {
  58.         super(DEFAULT_LAW);
  59.         if (propagators.isEmpty()) {
  60.             throw new OrekitException(OrekitMessages.NOT_ENOUGH_PROPAGATORS);
  61.         }
  62.         this.propagators = new TreeMap<>();
  63.         for (final BoundedPropagator propagator : propagators) {
  64.             this.propagators.put(propagator.getMinDate(), propagator);
  65.         }
  66.         super.resetInitialState(
  67.                 this.propagators.firstEntry().getValue().getInitialState());
  68.     }


  69.     @Override
  70.     public TimeStampedPVCoordinates getPVCoordinates(final AbsoluteDate date,
  71.                                                      final Frame frame)
  72.             throws OrekitException {
  73.         return getPropagator(date).getPVCoordinates(date, frame);
  74.     }

  75.     @Override
  76.     protected Orbit propagateOrbit(final AbsoluteDate date) throws OrekitException {
  77.         return getPropagator(date).propagate(date).getOrbit();
  78.     }

  79.     @Override
  80.     public AbsoluteDate getMinDate() {
  81.         return propagators.firstEntry().getValue().getMinDate();
  82.     }

  83.     @Override
  84.     public AbsoluteDate getMaxDate() {
  85.         return propagators.lastEntry().getValue().getMaxDate();
  86.     }

  87.     @Override
  88.     protected double getMass(final AbsoluteDate date) throws OrekitException {
  89.         return getPropagator(date).propagate(date).getMass();
  90.     }

  91.     @Override
  92.     public SpacecraftState getInitialState() throws OrekitException {
  93.         return propagators.firstEntry().getValue().getInitialState();
  94.     }

  95.     @Override
  96.     protected void resetIntermediateState(final SpacecraftState state,
  97.                                           final boolean forward) throws OrekitException {
  98.         throw new OrekitException(OrekitMessages.NON_RESETABLE_STATE);
  99.     }

  100.     @Override
  101.     public void resetInitialState(final SpacecraftState state) throws OrekitException {
  102.         throw new OrekitException(OrekitMessages.NON_RESETABLE_STATE);
  103.     }

  104.     /**
  105.      * Get the propagator to use for the given date.
  106.      *
  107.      * @param date of query
  108.      * @return propagator to use on date.
  109.      */
  110.     private BoundedPropagator getPropagator(final AbsoluteDate date) {
  111.         final Entry<AbsoluteDate, BoundedPropagator> entry = propagators.floorEntry(date);
  112.         if (entry != null) {
  113.             return entry.getValue();
  114.         } else {
  115.             // let the first propagator throw the exception
  116.             return propagators.firstEntry().getValue();
  117.         }
  118.     }

  119. }