OrbitBlender.java

  1. /* Copyright 2002-2024 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.orbits;

  18. import org.hipparchus.analysis.polynomials.SmoothStepFactory;
  19. import org.orekit.errors.OrekitException;
  20. import org.orekit.frames.Frame;
  21. import org.orekit.propagation.Propagator;
  22. import org.orekit.propagation.SpacecraftState;
  23. import org.orekit.propagation.analytical.AbstractAnalyticalPropagator;
  24. import org.orekit.time.AbsoluteDate;
  25. import org.orekit.utils.PVCoordinates;

  26. import java.util.List;

  27. /**
  28.  * Orbit blender.
  29.  * <p>
  30.  * Its purpose is to interpolate orbit state between tabulated orbit states using the concept of blending, exposed in :
  31.  * "Efficient Covariance Interpolation using Blending of Approximate State Error Transitions" by Sergei Tanygin, and applying
  32.  * it to orbit states instead of covariances.
  33.  * <p>
  34.  * It propagates tabulated values to the interpolating time using given propagator and then blend each propagated
  35.  * states using a smoothstep function. It gives especially good results as explained
  36.  * <a href="https://orekit.org/doc/technical-notes/Implementation_of_covariance_interpolation_in_Orekit.pdf">here</a>
  37.  * compared to Hermite interpolation when time steps between tabulated values get significant (In LEO, &gt; 10 mn for
  38.  * example).
  39.  * <p>
  40.  * <b>In most cases, an analytical propagator would be used to quickly fill the gap between tabulated values and recreate
  41.  * a dense ephemeris</b>.
  42.  * <p>
  43.  * However, a fully configured and accurate numerical propagator can be used to recreate an even
  44.  * more precise ephemeris in case the initial tabulated values were obtained from an external source.
  45.  * <p>
  46.  * Note that in the current implementation, the returned blended orbit is necessarily Cartesian.
  47.  *
  48.  * @author Vincent Cucchietti
  49.  * @see org.hipparchus.analysis.polynomials.SmoothStepFactory
  50.  * @see org.hipparchus.analysis.polynomials.SmoothStepFactory.SmoothStepFunction
  51.  * @see Propagator
  52.  * @see AbstractAnalyticalPropagator
  53.  *
  54.  * @since 12.0
  55.  */
  56. public class OrbitBlender extends AbstractOrbitInterpolator {

  57.     /** Propagator used to propagate tabulated orbits to interpolating time. */
  58.     private final Propagator blendingPropagator;

  59.     /** Blending function. */
  60.     private final SmoothStepFactory.SmoothStepFunction blendingFunction;

  61.     /**
  62.      * Default constructor.
  63.      * <p>
  64.      * <b>In most cases, an analytical propagator would be used to quickly fill the gap between tabulated values and recreate
  65.      * a dense ephemeris</b>.
  66.      * <p>
  67.      * However, a fully configured and accurate numerical propagator can be used to recreate an even
  68.      * more precise ephemeris in case the initial tabulated values were obtained from an external source.
  69.      *
  70.      * @param blendingFunction
  71.      * {@link org.hipparchus.analysis.polynomials.SmoothStepFactory.SmoothStepFunction smoothstep function} used for
  72.      * blending
  73.      * @param blendingPropagator propagator used to propagate tabulated orbits to interpolating time
  74.      * @param outputInertialFrame output inertial frame
  75.      *
  76.      * @throws OrekitException if output frame is not inertial
  77.      * @see org.hipparchus.analysis.polynomials.SmoothStepFactory.SmoothStepFunction
  78.      */
  79.     public OrbitBlender(final SmoothStepFactory.SmoothStepFunction blendingFunction,
  80.                         final Propagator blendingPropagator,
  81.                         final Frame outputInertialFrame) {
  82.         super(DEFAULT_INTERPOLATION_POINTS, 0., outputInertialFrame);
  83.         this.blendingFunction   = blendingFunction;
  84.         this.blendingPropagator = blendingPropagator;
  85.     }

  86.     /** {@inheritDoc} */
  87.     @Override
  88.     protected Orbit interpolate(final InterpolationData interpolationData) {

  89.         // Get first and last entry
  90.         final List<Orbit> neighborList  = interpolationData.getNeighborList();
  91.         final Orbit       previousOrbit = neighborList.get(0);
  92.         final Orbit       nextOrbit     = neighborList.get(1);

  93.         // Propagate orbits
  94.         final AbsoluteDate interpolationDate = interpolationData.getInterpolationDate();
  95.         final Orbit forwardedOrbit  = propagateOrbit(previousOrbit, interpolationDate);
  96.         final Orbit backwardedOrbit = propagateOrbit(nextOrbit, interpolationDate);

  97.         // Extract position-velocity-acceleration coordinates
  98.         final PVCoordinates forwardedPV  = forwardedOrbit.getPVCoordinates(getOutputInertialFrame());
  99.         final PVCoordinates backwardedPV = backwardedOrbit.getPVCoordinates(getOutputInertialFrame());

  100.         // Blend PV coordinates
  101.         final double timeParameter = getTimeParameter(interpolationDate, previousOrbit.getDate(), nextOrbit.getDate());
  102.         final double blendingValue = blendingFunction.value(timeParameter);

  103.         final PVCoordinates blendedPV = forwardedPV.blendArithmeticallyWith(backwardedPV, blendingValue);

  104.         // Output new blended instance
  105.         return new CartesianOrbit(blendedPV, getOutputInertialFrame(), interpolationDate, previousOrbit.getMu());
  106.     }

  107.     /**
  108.      * Propagate orbit using predefined {@link Propagator propagator}.
  109.      *
  110.      * @param tabulatedOrbit tabulated orbit to propagate
  111.      * @param propagationDate propagation date
  112.      *
  113.      * @return orbit propagated to propagation date
  114.      */
  115.     private Orbit propagateOrbit(final Orbit tabulatedOrbit,
  116.                                  final AbsoluteDate propagationDate) {
  117.         blendingPropagator.resetInitialState(new SpacecraftState(tabulatedOrbit));
  118.         return blendingPropagator.propagate(propagationDate).getOrbit();
  119.     }
  120. }