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.      */
  55.     public AggregateBoundedPropagator(
  56.             final Collection<? extends BoundedPropagator> propagators) {
  57.         super(DEFAULT_LAW);
  58.         if (propagators.isEmpty()) {
  59.             throw new OrekitException(OrekitMessages.NOT_ENOUGH_PROPAGATORS);
  60.         }
  61.         this.propagators = new TreeMap<>();
  62.         for (final BoundedPropagator propagator : propagators) {
  63.             this.propagators.put(propagator.getMinDate(), propagator);
  64.         }
  65.         super.resetInitialState(
  66.                 this.propagators.firstEntry().getValue().getInitialState());
  67.     }


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

  73.     @Override
  74.     protected Orbit propagateOrbit(final AbsoluteDate date) {
  75.         return getPropagator(date).propagate(date).getOrbit();
  76.     }

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

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

  85.     @Override
  86.     protected double getMass(final AbsoluteDate date) {
  87.         return getPropagator(date).propagate(date).getMass();
  88.     }

  89.     @Override
  90.     public SpacecraftState getInitialState() {
  91.         return propagators.firstEntry().getValue().getInitialState();
  92.     }

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

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

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

  117. }