FieldIntegratedEphemeris.java

  1. /* Copyright 2002-2020 CS GROUP
  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.propagation.integration;

  18. import java.util.List;
  19. import java.util.Map;
  20. import org.hipparchus.RealFieldElement;
  21. import org.hipparchus.ode.FieldDenseOutputModel;
  22. import org.hipparchus.ode.FieldODEStateAndDerivative;
  23. import org.orekit.errors.OrekitException;
  24. import org.orekit.errors.OrekitMessages;
  25. import org.orekit.frames.Frame;
  26. import org.orekit.orbits.FieldOrbit;
  27. import org.orekit.propagation.FieldAdditionalStateProvider;
  28. import org.orekit.propagation.FieldBoundedPropagator;
  29. import org.orekit.propagation.FieldSpacecraftState;
  30. import org.orekit.propagation.PropagationType;
  31. import org.orekit.propagation.analytical.FieldAbstractAnalyticalPropagator;
  32. import org.orekit.time.FieldAbsoluteDate;
  33. import org.orekit.utils.TimeStampedFieldPVCoordinates;

  34. /** This class stores sequentially generated orbital parameters for
  35.  * later retrieval.
  36.  *
  37.  * <p>
  38.  * Instances of this class are built and then must be fed with the results
  39.  * provided by {@link org.orekit.propagation.Propagator Propagator} objects
  40.  * configured in {@link org.orekit.propagation.Propagator#setEphemerisMode()
  41.  * ephemeris generation mode}. Once propagation is o, random access to any
  42.  * intermediate state of the orbit throughout the propagation range is possible.
  43.  * </p>
  44.  * <p>
  45.  * A typical use case is for numerically integrated orbits, which can be used by
  46.  * algorithms that need to wander around according to their own algorithm without
  47.  * cumbersome tight links with the integrator.
  48.  * </p>
  49.  * <p>
  50.  * As this class implements the {@link org.orekit.propagation.Propagator Propagator}
  51.  * interface, it can itself be used in batch mode to build another instance of the
  52.  * same type. This is however not recommended since it would be a waste of resources.
  53.  * </p>
  54.  * <p>
  55.  * Note that this class stores all intermediate states along with interpolation
  56.  * models, so it may be memory intensive.
  57.  * </p>
  58.  *
  59.  * @see org.orekit.propagation.numerical.NumericalPropagator
  60.  * @author Mathieu Rom&eacute;ro
  61.  * @author Luc Maisonobe
  62.  * @author V&eacute;ronique Pommier-Maurussane
  63.  */
  64. public class FieldIntegratedEphemeris <T extends RealFieldElement<T>>
  65.     extends FieldAbstractAnalyticalPropagator<T> implements FieldBoundedPropagator<T> {

  66.     /** Event detection requires evaluating the state slightly before / past an event. */
  67.     private static final double EXTRAPOLATION_TOLERANCE = 1.0;

  68.     /** Mapper between raw double components and spacecraft state. */
  69.     private final FieldStateMapper<T> mapper;

  70.     /** Type of orbit to output (mean or osculating).
  71.      * <p>
  72.      * This is used only in the case of semianalitical propagators where there is a clear separation between
  73.      * mean and short periodic elements. It is ignored by the Numerical propagator.
  74.      * </p>
  75.      */
  76.     private PropagationType type;

  77.     /** Start date of the integration (can be min or max). */
  78.     private final FieldAbsoluteDate<T> startDate;

  79.     /** First date of the range. */
  80.     private final FieldAbsoluteDate<T> minDate;

  81.     /** Last date of the range. */
  82.     private final FieldAbsoluteDate<T> maxDate;

  83.     /** Underlying raw mathematical model. */
  84.     private FieldDenseOutputModel<T> model;

  85.     /** Unmanaged additional states that must be simply copied. */
  86.     private final Map<String, T[]> unmanaged;

  87.     /** Creates a new instance of IntegratedEphemeris.
  88.      * @param startDate Start date of the integration (can be minDate or maxDate)
  89.      * @param minDate first date of the range
  90.      * @param maxDate last date of the range
  91.      * @param mapper mapper between raw double components and spacecraft state
  92.      * @param type type of orbit to output (mean or osculating)
  93.      * @param model underlying raw mathematical model
  94.      * @param unmanaged unmanaged additional states that must be simply copied
  95.      * @param providers providers for pre-integrated states
  96.      * @param equations names of additional equations
  97.      */
  98.     public FieldIntegratedEphemeris(final FieldAbsoluteDate<T> startDate,
  99.                                final FieldAbsoluteDate<T> minDate, final FieldAbsoluteDate<T> maxDate,
  100.                                final FieldStateMapper<T> mapper, final PropagationType type,
  101.                                final FieldDenseOutputModel<T> model,
  102.                                final Map<String, T[]> unmanaged,
  103.                                final List<FieldAdditionalStateProvider<T>> providers,
  104.                                final String[] equations) {

  105.         super(startDate.getField(), mapper.getAttitudeProvider());

  106.         this.startDate = startDate;
  107.         this.minDate   = minDate;
  108.         this.maxDate   = maxDate;
  109.         this.mapper    = mapper;
  110.         this.type      = type;
  111.         this.model     = model;
  112.         this.unmanaged = unmanaged;
  113.         // set up the pre-integrated providers
  114.         for (final FieldAdditionalStateProvider<T> provider : providers) {
  115.             addAdditionalStateProvider(provider);
  116.         }

  117.         // set up providers to map the final elements of the model array to additional states
  118.         for (int i = 0; i < equations.length; ++i) {
  119.             addAdditionalStateProvider(new LocalProvider(equations[i], i));
  120.         }

  121.     }

  122.     /** Interpolate the model at some date.
  123.      * @param date desired interpolation date
  124.      * @return state interpolated at date
  125.           * of supported range
  126.      */
  127.     private FieldODEStateAndDerivative<T> getInterpolatedState(final FieldAbsoluteDate<T> date) {

  128.         // compare using double precision instead of FieldAbsoluteDate<T>.compareTo(...)
  129.         // because time is expressed as a double when searching for events
  130.         if (date.compareTo(minDate.shiftedBy(-EXTRAPOLATION_TOLERANCE)) < 0 ||
  131.                 date.compareTo(maxDate.shiftedBy(EXTRAPOLATION_TOLERANCE)) > 0 ) {
  132.             // date is outside of supported range
  133.             throw new OrekitException(OrekitMessages.OUT_OF_RANGE_EPHEMERIDES_DATE,
  134.                                            date, minDate, maxDate);
  135.         }

  136.         return model.getInterpolatedState(date.durationFrom(startDate));

  137.     }

  138.     /** {@inheritDoc} */
  139.     @Override
  140.     protected FieldSpacecraftState<T> basicPropagate(final FieldAbsoluteDate<T> date) {
  141.         final FieldODEStateAndDerivative<T> os = getInterpolatedState(date);
  142.         FieldSpacecraftState<T> state = mapper.mapArrayToState(mapper.mapDoubleToDate(os.getTime(), date),
  143.                                                                os.getPrimaryState(), os.getPrimaryDerivative(),
  144.                                                                type);
  145.         for (Map.Entry<String, T[]> initial : unmanaged.entrySet()) {
  146.             state = state.addAdditionalState(initial.getKey(), initial.getValue());
  147.         }
  148.         return state;
  149.     }

  150.     /** {@inheritDoc} */
  151.     protected FieldOrbit<T> propagateOrbit(final FieldAbsoluteDate<T> date) {
  152.         return basicPropagate(date).getOrbit();
  153.     }

  154.     /** {@inheritDoc} */
  155.     protected T getMass(final FieldAbsoluteDate<T> date) {
  156.         return basicPropagate(date).getMass();
  157.     }

  158.     /** {@inheritDoc} */
  159.     public TimeStampedFieldPVCoordinates<T> getPVCoordinates(final FieldAbsoluteDate<T> date, final Frame frame) {
  160.         return propagate(date).getPVCoordinates(frame);
  161.     }

  162.     /** Get the first date of the range.
  163.      * @return the first date of the range
  164.      */
  165.     public FieldAbsoluteDate<T> getMinDate() {
  166.         return minDate;
  167.     }

  168.     /** Get the last date of the range.
  169.      * @return the last date of the range
  170.      */
  171.     public FieldAbsoluteDate<T> getMaxDate() {
  172.         return maxDate;
  173.     }

  174.     @Override
  175.     public Frame getFrame() {
  176.         return this.mapper.getFrame();
  177.     }

  178.     /** {@inheritDoc} */
  179.     public void resetInitialState(final FieldSpacecraftState<T> state) {
  180.         throw new OrekitException(OrekitMessages.NON_RESETABLE_STATE);
  181.     }

  182.     /** {@inheritDoc} */
  183.     protected void resetIntermediateState(final FieldSpacecraftState<T> state, final boolean forward) {
  184.         throw new OrekitException(OrekitMessages.NON_RESETABLE_STATE);
  185.     }

  186.     /** {@inheritDoc} */
  187.     public FieldSpacecraftState<T> getInitialState() {
  188.         return updateAdditionalStates(basicPropagate(getMinDate()));
  189.     }

  190.     /** Local provider for additional state data. */
  191.     private class LocalProvider implements FieldAdditionalStateProvider<T> {

  192.         /** Name of the additional state. */
  193.         private final String name;

  194.         /** Index of the additional state. */
  195.         private final int index;

  196.         /** Simple constructor.
  197.          * @param name name of the additional state
  198.          * @param index index of the additional state
  199.          */
  200.         LocalProvider(final String name, final int index) {
  201.             this.name  = name;
  202.             this.index = index;
  203.         }

  204.         /** {@inheritDoc} */
  205.         public String getName() {
  206.             return name;
  207.         }

  208.         /** {@inheritDoc} */
  209.         public T[] getAdditionalState(final FieldSpacecraftState<T> state) {

  210.             // extract the part of the interpolated array corresponding to the additional state
  211.             return getInterpolatedState(state.getDate()).getSecondaryState(index + 1);

  212.         }

  213.     }

  214. }