EphemerisSegmentPropagator.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.files.general;

  18. import java.util.List;
  19. import java.util.stream.Stream;

  20. import org.orekit.errors.OrekitException;
  21. import org.orekit.errors.OrekitMessages;
  22. import org.orekit.files.general.EphemerisFile.EphemerisSegment;
  23. import org.orekit.frames.Frame;
  24. import org.orekit.frames.FramesFactory;
  25. import org.orekit.orbits.CartesianOrbit;
  26. import org.orekit.orbits.Orbit;
  27. import org.orekit.propagation.BoundedPropagator;
  28. import org.orekit.propagation.Propagator;
  29. import org.orekit.propagation.SpacecraftState;
  30. import org.orekit.propagation.analytical.AbstractAnalyticalPropagator;
  31. import org.orekit.time.AbsoluteDate;
  32. import org.orekit.utils.ImmutableTimeStampedCache;
  33. import org.orekit.utils.TimeStampedPVCoordinates;

  34. /**
  35.  * A {@link Propagator} based on a {@link EphemerisSegment}.
  36.  *
  37.  * <p> The {@link #getPVCoordinates(AbsoluteDate, Frame)} is implemented without using the
  38.  * {@link #propagate(AbsoluteDate)} methods so using this class as a {@link
  39.  * org.orekit.utils.PVCoordinatesProvider} still behaves as expected when the ephemeris
  40.  * file did not have a valid gravitational parameter.
  41.  *
  42.  * @author Evan Ward
  43.  */
  44. class EphemerisSegmentPropagator extends AbstractAnalyticalPropagator
  45.         implements BoundedPropagator {

  46.     /** Default frame to use when creating orbits. */
  47.     public static final Frame DEFAULT_INERTIAL_FRAME = FramesFactory.getGCRF();

  48.     /**
  49.      * Sorted cache of state vectors. A duplication of the information in {@link
  50.      * #ephemeris} that could be avoided by duplicating the logic of {@link
  51.      * ImmutableTimeStampedCache#getNeighbors(AbsoluteDate)} for a general {@link List}.
  52.      */
  53.     private final ImmutableTimeStampedCache<TimeStampedPVCoordinates> cache;
  54.     /** Tabular data from which this propagator is built. */
  55.     private final EphemerisSegment ephemeris;
  56.     /** Inertial frame used for creating orbits. */
  57.     private final Frame inertialFrame;
  58.     /** Frame of the ephemeris data. */
  59.     private final Frame ephemerisFrame;

  60.     /**
  61.      * Create a {@link Propagator} from an ephemeris segment.
  62.      *
  63.      * <p> If the {@link EphemerisSegment#getFrame() ephemeris frame} is not {@link
  64.      * Frame#isPseudoInertial() inertial} then {@link #DEFAULT_INERTIAL_FRAME} is used as
  65.      * the frame for orbits created by this propagator.
  66.      *
  67.      * @param ephemeris segment containing the data for this propagator.
  68.      * @throws OrekitException if {@link EphemerisSegment#getFrame()} throws one.
  69.      */
  70.     EphemerisSegmentPropagator(final EphemerisSegment ephemeris) throws OrekitException {
  71.         super(Propagator.DEFAULT_LAW);
  72.         this.cache = new ImmutableTimeStampedCache<>(
  73.                 ephemeris.getInterpolationSamples(),
  74.                 ephemeris.getCoordinates());
  75.         this.ephemeris = ephemeris;
  76.         this.ephemerisFrame = ephemeris.getFrame();
  77.         if (ephemerisFrame.isPseudoInertial()) {
  78.             this.inertialFrame = ephemerisFrame;
  79.         } else {
  80.             this.inertialFrame = DEFAULT_INERTIAL_FRAME;
  81.         }
  82.         // set the initial state so getFrame() works
  83.         final TimeStampedPVCoordinates ic = cache.getEarliest();
  84.         final TimeStampedPVCoordinates icInertial = ephemerisFrame
  85.                 .getTransformTo(inertialFrame, ic.getDate())
  86.                 .transformPVCoordinates(ic);
  87.         super.resetInitialState(
  88.                 new SpacecraftState(
  89.                         new CartesianOrbit(
  90.                                 icInertial, inertialFrame, ephemeris.getMu()
  91.                         ),
  92.                         DEFAULT_LAW.getAttitude(
  93.                                 icInertial.toTaylorProvider(inertialFrame),
  94.                                 ic.getDate(),
  95.                                 inertialFrame),
  96.                         DEFAULT_MASS
  97.                 )
  98.         );
  99.     }

  100.     @Override
  101.     public TimeStampedPVCoordinates getPVCoordinates(final AbsoluteDate date,
  102.                                                      final Frame frame) throws OrekitException {
  103.         final Stream<TimeStampedPVCoordinates> neighbors = this.cache.getNeighbors(date);
  104.         final TimeStampedPVCoordinates point =
  105.                 TimeStampedPVCoordinates.interpolate(date, ephemeris.getAvailableDerivatives(), neighbors);
  106.         return ephemerisFrame.getTransformTo(frame, date).transformPVCoordinates(point);
  107.     }

  108.     @Override
  109.     protected Orbit propagateOrbit(final AbsoluteDate date) throws OrekitException {
  110.         final TimeStampedPVCoordinates pv = this.getPVCoordinates(date, inertialFrame);
  111.         return new CartesianOrbit(pv, inertialFrame, this.ephemeris.getMu());
  112.     }

  113.     @Override
  114.     public AbsoluteDate getMinDate() {
  115.         return ephemeris.getStart();
  116.     }

  117.     @Override
  118.     public AbsoluteDate getMaxDate() {
  119.         return ephemeris.getStop();
  120.     }

  121.     @Override
  122.     protected double getMass(final AbsoluteDate date) throws OrekitException {
  123.         return DEFAULT_MASS;
  124.     }

  125.     @Override
  126.     public SpacecraftState getInitialState() throws OrekitException {
  127.         return this.basicPropagate(this.getMinDate());
  128.     }

  129.     @Override
  130.     protected void resetIntermediateState(final SpacecraftState state,
  131.                                           final boolean forward) throws OrekitException {
  132.         throw new OrekitException(OrekitMessages.NON_RESETABLE_STATE);
  133.     }

  134.     @Override
  135.     public void resetInitialState(final SpacecraftState state) throws OrekitException {
  136.         throw new OrekitException(OrekitMessages.NON_RESETABLE_STATE);
  137.     }

  138. }