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.      */
  69.     EphemerisSegmentPropagator(final EphemerisSegment ephemeris) {
  70.         super(Propagator.DEFAULT_LAW);
  71.         this.cache = new ImmutableTimeStampedCache<>(
  72.                 ephemeris.getInterpolationSamples(),
  73.                 ephemeris.getCoordinates());
  74.         this.ephemeris = ephemeris;
  75.         this.ephemerisFrame = ephemeris.getFrame();
  76.         if (ephemerisFrame.isPseudoInertial()) {
  77.             this.inertialFrame = ephemerisFrame;
  78.         } else {
  79.             this.inertialFrame = DEFAULT_INERTIAL_FRAME;
  80.         }
  81.         // set the initial state so getFrame() works
  82.         final TimeStampedPVCoordinates ic = cache.getEarliest();
  83.         final TimeStampedPVCoordinates icInertial = ephemerisFrame
  84.                 .getTransformTo(inertialFrame, ic.getDate())
  85.                 .transformPVCoordinates(ic);
  86.         super.resetInitialState(
  87.                 new SpacecraftState(
  88.                         new CartesianOrbit(
  89.                                 icInertial, inertialFrame, ephemeris.getMu()
  90.                         ),
  91.                         DEFAULT_LAW.getAttitude(
  92.                                 icInertial.toTaylorProvider(inertialFrame),
  93.                                 ic.getDate(),
  94.                                 inertialFrame),
  95.                         DEFAULT_MASS
  96.                 )
  97.         );
  98.     }

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

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

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

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

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

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

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

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

  137. }