FieldIntegratedEphemeris.java

  1. /* Copyright 2002-2021 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.Collections;
  19. import java.util.List;
  20. import java.util.Map;

  21. import org.hipparchus.CalculusFieldElement;
  22. import org.hipparchus.ode.FieldDenseOutputModel;
  23. import org.hipparchus.ode.FieldODEStateAndDerivative;
  24. import org.orekit.errors.OrekitException;
  25. import org.orekit.errors.OrekitMessages;
  26. import org.orekit.frames.Frame;
  27. import org.orekit.orbits.FieldOrbit;
  28. import org.orekit.propagation.FieldAdditionalStateProvider;
  29. import org.orekit.propagation.FieldBoundedPropagator;
  30. import org.orekit.propagation.FieldSpacecraftState;
  31. import org.orekit.propagation.PropagationType;
  32. import org.orekit.propagation.analytical.FieldAbstractAnalyticalPropagator;
  33. import org.orekit.time.FieldAbsoluteDate;
  34. import org.orekit.utils.ParameterDriver;
  35. import org.orekit.utils.TimeStampedFieldPVCoordinates;

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

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

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

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

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

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

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

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

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

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

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

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

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

  123.     }

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

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

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

  143.     }

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

  156.     /** {@inheritDoc} */
  157.     @Override
  158.     protected FieldOrbit<T> propagateOrbit(final FieldAbsoluteDate<T> date, final T[] parameters) {
  159.         return basicPropagate(date).getOrbit();
  160.     }

  161.     /** {@inheritDoc} */
  162.     @Override
  163.     protected T getMass(final FieldAbsoluteDate<T> date) {
  164.         return basicPropagate(date).getMass();
  165.     }

  166.     /** {@inheritDoc} */
  167.     @Override
  168.     public TimeStampedFieldPVCoordinates<T> getPVCoordinates(final FieldAbsoluteDate<T> date, final Frame frame) {
  169.         return propagate(date).getPVCoordinates(frame);
  170.     }

  171.     /** Get the first date of the range.
  172.      * @return the first date of the range
  173.      */
  174.     @Override
  175.     public FieldAbsoluteDate<T> getMinDate() {
  176.         return minDate;
  177.     }

  178.     /** Get the last date of the range.
  179.      * @return the last date of the range
  180.      */
  181.     @Override
  182.     public FieldAbsoluteDate<T> getMaxDate() {
  183.         return maxDate;
  184.     }

  185.     @Override
  186.     public Frame getFrame() {
  187.         return this.mapper.getFrame();
  188.     }

  189.     /** {@inheritDoc} */
  190.     @Override
  191.     public void resetInitialState(final FieldSpacecraftState<T> state) {
  192.         throw new OrekitException(OrekitMessages.NON_RESETABLE_STATE);
  193.     }

  194.     /** {@inheritDoc} */
  195.     @Override
  196.     protected void resetIntermediateState(final FieldSpacecraftState<T> state, final boolean forward) {
  197.         throw new OrekitException(OrekitMessages.NON_RESETABLE_STATE);
  198.     }

  199.     /** {@inheritDoc} */
  200.     @Override
  201.     public FieldSpacecraftState<T> getInitialState() {
  202.         return updateAdditionalStates(basicPropagate(getMinDate()));
  203.     }

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

  206.         /** Name of the additional state. */
  207.         private final String name;

  208.         /** Index of the additional state. */
  209.         private final int index;

  210.         /** Simple constructor.
  211.          * @param name name of the additional state
  212.          * @param index index of the additional state
  213.          */
  214.         LocalProvider(final String name, final int index) {
  215.             this.name  = name;
  216.             this.index = index;
  217.         }

  218.         /** {@inheritDoc} */
  219.         @Override
  220.         public String getName() {
  221.             return name;
  222.         }

  223.         /** {@inheritDoc} */
  224.         @Override
  225.         public T[] getAdditionalState(final FieldSpacecraftState<T> state) {

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

  228.         }

  229.     }

  230.     /** {@inheritDoc} */
  231.     @Override
  232.     protected List<ParameterDriver> getParametersDrivers() {
  233.         // Integrated Ephemeris propagation model does not have parameter drivers.
  234.         return Collections.emptyList();
  235.     }

  236. }