FieldOrbitBlender.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.CalculusFieldElement;
  19. import org.hipparchus.analysis.polynomials.SmoothStepFactory;
  20. import org.orekit.errors.OrekitException;
  21. import org.orekit.frames.Frame;
  22. import org.orekit.propagation.FieldSpacecraftState;
  23. import org.orekit.propagation.analytical.AbstractAnalyticalPropagator;
  24. import org.orekit.propagation.analytical.FieldAbstractAnalyticalPropagator;
  25. import org.orekit.time.FieldAbsoluteDate;
  26. import org.orekit.utils.FieldPVCoordinates;

  27. import java.util.List;

  28. /**
  29.  * Orbit blender.
  30.  * <p>
  31.  * Its purpose is to interpolate orbit state between tabulated orbit states using the concept of blending, exposed in :
  32.  * "Efficient Covariance Interpolation using Blending of Approximate State Error Transitions" by Sergei Tanygin, and applying
  33.  * it to orbit states instead of covariances.
  34.  * <p>
  35.  * It propagates tabulated values to the interpolating time using given analytical propagator and then blend each propagated
  36.  * states using a smoothstep function. It gives especially good results as explained
  37.  * <a href="https://orekit.org/doc/technical-notes/Implementation_of_covariance_interpolation_in_Orekit.pdf">here</a>
  38.  * compared to Hermite interpolation when time steps between tabulated values get significant (In LEO, &gt; 10 mn for
  39.  * example).
  40.  *
  41.  * @param <KK> type of field element
  42.  *
  43.  * @author Vincent Cucchietti
  44.  * @see org.hipparchus.analysis.polynomials.SmoothStepFactory
  45.  * @see org.hipparchus.analysis.polynomials.SmoothStepFactory.FieldSmoothStepFunction
  46.  */
  47. public class FieldOrbitBlender<KK extends CalculusFieldElement<KK>> extends AbstractFieldOrbitInterpolator<KK> {

  48.     /** Analytical propagator used to propagate tabulated orbits to interpolating time. */
  49.     private final FieldAbstractAnalyticalPropagator<KK> analyticalPropagator;

  50.     /** Blending function. */
  51.     private final SmoothStepFactory.FieldSmoothStepFunction<KK> blendingFunction;

  52.     /**
  53.      * Default constructor.
  54.      *
  55.      * @param blendingFunction
  56.      * {@link org.hipparchus.analysis.polynomials.SmoothStepFactory.SmoothStepFunction smoothstep function} used for
  57.      * blending
  58.      * @param analyticalPropagator analytical propagator used to propagate tabulated orbits to interpolating time
  59.      * @param outputInertialFrame output inertial frame
  60.      *
  61.      * @throws OrekitException if output frame is not inertial
  62.      */
  63.     public FieldOrbitBlender(final SmoothStepFactory.FieldSmoothStepFunction<KK> blendingFunction,
  64.                              final FieldAbstractAnalyticalPropagator<KK> analyticalPropagator,
  65.                              final Frame outputInertialFrame) {
  66.         super(DEFAULT_INTERPOLATION_POINTS, 0., outputInertialFrame);
  67.         this.blendingFunction     = blendingFunction;
  68.         this.analyticalPropagator = analyticalPropagator;
  69.     }

  70.     /** {@inheritDoc} */
  71.     @Override
  72.     public FieldOrbit<KK> interpolate(final InterpolationData interpolationData) {

  73.         // Get interpolation date
  74.         final FieldAbsoluteDate<KK> interpolationDate = interpolationData.getInterpolationDate();

  75.         // Get first and last entry
  76.         final List<FieldOrbit<KK>> neighborList  = interpolationData.getNeighborList();
  77.         final FieldOrbit<KK>       previousOrbit = neighborList.get(0);
  78.         final FieldOrbit<KK>       nextOrbit     = neighborList.get(1);

  79.         // Propagate orbits
  80.         final FieldOrbit<KK> forwardedOrbit  = propagateOrbitAnalytically(previousOrbit, interpolationDate);
  81.         final FieldOrbit<KK> backwardedOrbit = propagateOrbitAnalytically(nextOrbit, interpolationDate);

  82.         // Extract position-velocity-acceleration coordinates
  83.         final FieldPVCoordinates<KK> forwardedPV  = forwardedOrbit.getPVCoordinates(getOutputInertialFrame());
  84.         final FieldPVCoordinates<KK> backwardedPV = backwardedOrbit.getPVCoordinates(getOutputInertialFrame());

  85.         // Blend PV coordinates
  86.         final KK timeParameter = getTimeParameter(interpolationDate, previousOrbit.getDate(), nextOrbit.getDate());
  87.         final KK blendingValue = blendingFunction.value(timeParameter);

  88.         final FieldPVCoordinates<KK> blendedPV = forwardedPV.blendArithmeticallyWith(backwardedPV, blendingValue);

  89.         // Output new blended instance
  90.         return new FieldCartesianOrbit<>(blendedPV, getOutputInertialFrame(), interpolationDate, previousOrbit.getMu());
  91.     }

  92.     /**
  93.      * Propagate orbit using predefined {@link AbstractAnalyticalPropagator analytical propagator}.
  94.      *
  95.      * @param tabulatedOrbit tabulated orbit to propagate
  96.      * @param propagationDate propagation date
  97.      *
  98.      * @return orbit propagated to propagation date
  99.      */
  100.     private FieldOrbit<KK> propagateOrbitAnalytically(final FieldOrbit<KK> tabulatedOrbit,
  101.                                                       final FieldAbsoluteDate<KK> propagationDate) {

  102.         analyticalPropagator.resetInitialState(new FieldSpacecraftState<>(tabulatedOrbit));

  103.         return analyticalPropagator.propagate(propagationDate).getOrbit();
  104.     }
  105. }