EphemerisSegmentPropagator.java

  1. /* Contributed in the public domain.
  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.files.general;

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

  20. import org.orekit.attitudes.InertialProvider;
  21. import org.orekit.errors.OrekitException;
  22. import org.orekit.errors.OrekitMessages;
  23. import org.orekit.files.general.EphemerisFile.EphemerisSegment;
  24. import org.orekit.frames.Frame;
  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.  * @param <C> type of the Cartesian coordinates
  42.  *
  43.  * @author Evan Ward
  44.  */
  45. class EphemerisSegmentPropagator<C extends TimeStampedPVCoordinates> extends AbstractAnalyticalPropagator
  46.         implements BoundedPropagator {

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

  59.     /**
  60.      * Create a {@link Propagator} from an ephemeris segment.
  61.      *
  62.      * @param ephemeris segment containing the data for this propagator.
  63.      */
  64.     EphemerisSegmentPropagator(final EphemerisSegment<C> ephemeris) {
  65.         super(new InertialProvider(ephemeris.getInertialFrame()));
  66.         this.cache = new ImmutableTimeStampedCache<>(
  67.                 ephemeris.getInterpolationSamples(),
  68.                 ephemeris.getCoordinates());
  69.         this.ephemeris = ephemeris;
  70.         this.ephemerisFrame = ephemeris.getFrame();
  71.         this.inertialFrame = ephemeris.getInertialFrame();
  72.         // set the initial state so getFrame() works
  73.         final TimeStampedPVCoordinates ic = cache.getEarliest();
  74.         final TimeStampedPVCoordinates icInertial = ephemerisFrame
  75.                 .getTransformTo(inertialFrame, ic.getDate())
  76.                 .transformPVCoordinates(ic);
  77.         super.resetInitialState(
  78.                 new SpacecraftState(
  79.                         new CartesianOrbit(
  80.                                 icInertial, inertialFrame, ephemeris.getMu()
  81.                         ),
  82.                         getAttitudeProvider().getAttitude(
  83.                                 icInertial.toTaylorProvider(inertialFrame),
  84.                                 ic.getDate(),
  85.                                 inertialFrame),
  86.                         DEFAULT_MASS
  87.                 )
  88.         );
  89.     }

  90.     @Override
  91.     public TimeStampedPVCoordinates getPVCoordinates(final AbsoluteDate date, final Frame frame) {
  92.         final Stream<C> neighbors = this.cache.getNeighbors(date);
  93.         final TimeStampedPVCoordinates point =
  94.                 TimeStampedPVCoordinates.interpolate(date, ephemeris.getAvailableDerivatives(), neighbors);
  95.         return ephemerisFrame.getTransformTo(frame, date).transformPVCoordinates(point);
  96.     }

  97.     @Override
  98.     protected Orbit propagateOrbit(final AbsoluteDate date) {
  99.         final TimeStampedPVCoordinates pv = this.getPVCoordinates(date, inertialFrame);
  100.         return new CartesianOrbit(pv, inertialFrame, this.ephemeris.getMu());
  101.     }

  102.     @Override
  103.     public AbsoluteDate getMinDate() {
  104.         return ephemeris.getStart();
  105.     }

  106.     @Override
  107.     public AbsoluteDate getMaxDate() {
  108.         return ephemeris.getStop();
  109.     }

  110.     @Override
  111.     protected double getMass(final AbsoluteDate date) {
  112.         return DEFAULT_MASS;
  113.     }

  114.     @Override
  115.     public SpacecraftState getInitialState() {
  116.         return this.basicPropagate(this.getMinDate());
  117.     }

  118.     @Override
  119.     protected void resetIntermediateState(final SpacecraftState state,
  120.                                           final boolean forward) {
  121.         throw new OrekitException(OrekitMessages.NON_RESETABLE_STATE);
  122.     }

  123.     @Override
  124.     public void resetInitialState(final SpacecraftState state) {
  125.         throw new OrekitException(OrekitMessages.NON_RESETABLE_STATE);
  126.     }

  127. }