FieldIntegratedEphemeris.java

  1. /* Copyright 2002-2019 CS Systèmes d'Information
  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.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.analytical.FieldAbstractAnalyticalPropagator;
  31. import org.orekit.time.FieldAbsoluteDate;
  32. import org.orekit.utils.TimeStampedFieldPVCoordinates;

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

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

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

  73.     /** Output only the mean orbit. <br/>
  74.      * <p>
  75.      * This is used only in the case of semianalitical propagators where there is a clear separation between
  76.      * mean and short periodic elements. It is ignored by the Numerical propagator.
  77.      * </p>
  78.      */
  79.     private boolean meanFieldOrbit;

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

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

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

  86.     /** Underlying raw mathematical model. */
  87.     private FieldDenseOutputModel<T> model;

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

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

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

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

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

  124.     }

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

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

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

  140.     }

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

  153.     /** {@inheritDoc} */
  154.     protected FieldOrbit<T> propagateOrbit(final FieldAbsoluteDate<T> date) {
  155.         return basicPropagate(date).getOrbit();
  156.     }

  157.     /** {@inheritDoc} */
  158.     protected T getMass(final FieldAbsoluteDate<T> date) {
  159.         return basicPropagate(date).getMass();
  160.     }

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

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

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

  177.     @Override
  178.     public Frame getFrame() {
  179.         return this.mapper.getFrame();
  180.     }

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

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

  189.     /** {@inheritDoc} */
  190.     public FieldSpacecraftState<T> getInitialState() {
  191.         return updateAdditionalStates(basicPropagate(getMinDate()));
  192.     }

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

  195.         /** Name of the additional state. */
  196.         private final String name;

  197.         /** Index of the additional state. */
  198.         private final int index;

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

  207.         /** {@inheritDoc} */
  208.         public String getName() {
  209.             return name;
  210.         }

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

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

  215.         }

  216.     }

  217. }