FieldTimeInterpolator.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.time;

  18. import org.hipparchus.CalculusFieldElement;
  19. import org.orekit.errors.OrekitIllegalArgumentException;
  20. import org.orekit.errors.OrekitMessages;

  21. import java.util.Collection;
  22. import java.util.List;
  23. import java.util.Optional;
  24. import java.util.stream.Collectors;
  25. import java.util.stream.Stream;

  26. /**
  27.  * This interface represents objects that can interpolate a time stamped value with respect to time.
  28.  *
  29.  * @param <T> type of the interpolated instance
  30.  * @param <KK> type of the field element
  31.  *
  32.  * @author Vincent Cucchietti
  33.  * @see FieldAbsoluteDate
  34.  * @see FieldTimeStamped
  35.  * @see CalculusFieldElement
  36.  */
  37. public interface FieldTimeInterpolator<T extends FieldTimeStamped<KK>, KK extends CalculusFieldElement<KK>> {

  38.     /**
  39.      * Get an interpolated instance.
  40.      *
  41.      * @param interpolationDate interpolation date
  42.      * @param sample time stamped sample
  43.      *
  44.      * @return a new instance, interpolated at specified date
  45.      *
  46.      * @see TimeStamped
  47.      * @see AbsoluteDate
  48.      */
  49.     default T interpolate(AbsoluteDate interpolationDate, Stream<T> sample) {
  50.         return interpolate(interpolationDate, sample.collect(Collectors.toList()));
  51.     }

  52.     /**
  53.      * Get an interpolated instance.
  54.      *
  55.      * @param interpolationDate interpolation date
  56.      * @param sample time stamped sample
  57.      *
  58.      * @return a new instance, interpolated at specified date
  59.      */
  60.     default T interpolate(AbsoluteDate interpolationDate, Collection<T> sample) {
  61.         final Optional<T> optionalElement = sample.stream().findAny();
  62.         if (optionalElement.isPresent()) {
  63.             final T element = optionalElement.get();
  64.             return interpolate(new FieldAbsoluteDate<>(element.getDate().getField(), interpolationDate), sample);
  65.         }
  66.         throw new OrekitIllegalArgumentException(OrekitMessages.NOT_ENOUGH_DATA, 0);
  67.     }

  68.     /**
  69.      * Get an interpolated instance.
  70.      *
  71.      * @param interpolationDate interpolation date
  72.      * @param sample time stamped sample
  73.      *
  74.      * @return a new instance, interpolated at specified date
  75.      *
  76.      * @see TimeStamped
  77.      * @see AbsoluteDate
  78.      */
  79.     T interpolate(FieldAbsoluteDate<KK> interpolationDate, Stream<T> sample);

  80.     /**
  81.      * Get an interpolated instance.
  82.      *
  83.      * @param interpolationDate interpolation date
  84.      * @param sample time stamped sample
  85.      *
  86.      * @return a new instance, interpolated at specified date
  87.      */
  88.     T interpolate(FieldAbsoluteDate<KK> interpolationDate, Collection<T> sample);

  89.     /**
  90.      * Get all lowest level interpolators implemented by this instance, otherwise return a list with this instance only.
  91.      * <p>
  92.      * An example would be the spacecraft state interpolator which can use different interpolators for each of its attributes
  93.      * (orbit, absolute position-velocity-acceleration coordinates, mass...). In this case, it would return the list of all
  94.      * of these interpolators (or possibly all of their sub-interpolators if they were to use multiple interpolators
  95.      * themselves).
  96.      *
  97.      * @return list of interpolators
  98.      */
  99.     List<FieldTimeInterpolator<? extends FieldTimeStamped<KK>, KK>> getSubInterpolators();

  100.     /**
  101.      * Get the number of interpolation points. In the specific case where this interpolator contains multiple
  102.      * sub-interpolators, this method will return the maximum number of interpolation points required among all
  103.      * sub-interpolators.
  104.      *
  105.      * @return the number of interpolation points
  106.      *
  107.      * @since 12.0.1
  108.      */
  109.     int getNbInterpolationPoints();

  110.     /** Get the extrapolation threshold.
  111.      * @return get the extrapolation threshold.
  112.      */
  113.     double getExtrapolationThreshold();
  114. }