Search in sources :

Example 1 with FieldHermiteInterpolator

use of org.hipparchus.analysis.interpolation.FieldHermiteInterpolator in project Orekit by CS-SI.

the class EOPHistory method interpolate.

/**
 * Interpolate a single EOP component.
 * <p>
 * This method should be called <em>only</em> when {@link #hasDataFor(AbsoluteDate)} returns true.
 * </p>
 * @param date interpolation date
 * @param aDate interpolation date, as an {@link AbsoluteDate}
 * @param selector selector for EOP entry component
 * @param <T> type of the field elements
 * @return interpolated value
 */
private <T extends RealFieldElement<T>> T interpolate(final FieldAbsoluteDate<T> date, final AbsoluteDate aDate, final Function<EOPEntry, Double> selector) {
    try {
        final FieldHermiteInterpolator<T> interpolator = new FieldHermiteInterpolator<>();
        final T[] y = MathArrays.buildArray(date.getField(), 1);
        final T zero = date.getField().getZero();
        // here, we attempt to get a constant date,
        final FieldAbsoluteDate<T> central = new FieldAbsoluteDate<>(aDate, zero);
        // for example removing derivatives
        // if T was DerivativeStructure
        getNeighbors(aDate).forEach(entry -> {
            y[0] = zero.add(selector.apply(entry));
            interpolator.addSamplePoint(central.durationFrom(entry.getDate()).negate(), y);
        });
        // here, we introduce derivatives again (in DerivativeStructure case)
        return interpolator.value(date.durationFrom(central))[0];
    } catch (TimeStampedCacheException tce) {
        // this should not happen because of date check performed by caller
        throw new OrekitInternalError(tce);
    }
}
Also used : TimeStampedCacheException(org.orekit.errors.TimeStampedCacheException) FieldHermiteInterpolator(org.hipparchus.analysis.interpolation.FieldHermiteInterpolator) OrekitInternalError(org.orekit.errors.OrekitInternalError) FieldAbsoluteDate(org.orekit.time.FieldAbsoluteDate)

Example 2 with FieldHermiteInterpolator

use of org.hipparchus.analysis.interpolation.FieldHermiteInterpolator in project Orekit by CS-SI.

the class FieldSpacecraftState method interpolate.

/**
 * Get an interpolated instance.
 * <p>
 * The additional states that are interpolated are the ones already present
 * in the instance. The sample instances must therefore have at least the same
 * additional states has the instance. They may have more additional states,
 * but the extra ones will be ignored.
 * </p>
 * <p>
 * As this implementation of interpolation is polynomial, it should be used only
 * with small samples (about 10-20 points) in order to avoid <a
 * href="http://en.wikipedia.org/wiki/Runge%27s_phenomenon">Runge's phenomenon</a>
 * and numerical problems (including NaN appearing).
 * </p>
 * @param date interpolation date
 * @param sample sample points on which interpolation should be done
 * @return a new instance, interpolated at specified date
 * @exception OrekitException if the number of point is too small for interpolating
 */
public FieldSpacecraftState<T> interpolate(final FieldAbsoluteDate<T> date, final Stream<FieldSpacecraftState<T>> sample) throws OrekitException {
    // prepare interpolators
    final List<FieldOrbit<T>> orbits = new ArrayList<>();
    final List<FieldAttitude<T>> attitudes = new ArrayList<>();
    final FieldHermiteInterpolator<T> massInterpolator = new FieldHermiteInterpolator<>();
    final Map<String, FieldHermiteInterpolator<T>> additionalInterpolators = new HashMap<String, FieldHermiteInterpolator<T>>(additional.size());
    for (final String name : additional.keySet()) {
        additionalInterpolators.put(name, new FieldHermiteInterpolator<>());
    }
    // extract sample data
    try {
        sample.forEach(state -> {
            try {
                final T deltaT = state.getDate().durationFrom(date);
                orbits.add(state.getOrbit());
                attitudes.add(state.getAttitude());
                final T[] mm = MathArrays.buildArray(orbit.getA().getField(), 1);
                mm[0] = state.getMass();
                massInterpolator.addSamplePoint(deltaT, mm);
                for (final Map.Entry<String, FieldHermiteInterpolator<T>> entry : additionalInterpolators.entrySet()) {
                    entry.getValue().addSamplePoint(deltaT, state.getAdditionalState(entry.getKey()));
                }
            } catch (OrekitException oe) {
                throw new OrekitExceptionWrapper(oe);
            }
        });
    } catch (OrekitExceptionWrapper oew) {
        throw oew.getException();
    }
    // perform interpolations
    final FieldOrbit<T> interpolatedOrbit = orbit.interpolate(date, orbits);
    final FieldAttitude<T> interpolatedAttitude = attitude.interpolate(date, attitudes);
    final T interpolatedMass = massInterpolator.value(orbit.getA().getField().getZero())[0];
    final Map<String, T[]> interpolatedAdditional;
    if (additional.isEmpty()) {
        interpolatedAdditional = null;
    } else {
        interpolatedAdditional = new HashMap<String, T[]>(additional.size());
        for (final Map.Entry<String, FieldHermiteInterpolator<T>> entry : additionalInterpolators.entrySet()) {
            interpolatedAdditional.put(entry.getKey(), entry.getValue().value(orbit.getA().getField().getZero()));
        }
    }
    // create the complete interpolated state
    return new FieldSpacecraftState<>(interpolatedOrbit, interpolatedAttitude, interpolatedMass, interpolatedAdditional);
}
Also used : FieldOrbit(org.orekit.orbits.FieldOrbit) FieldHermiteInterpolator(org.hipparchus.analysis.interpolation.FieldHermiteInterpolator) OrekitExceptionWrapper(org.orekit.errors.OrekitExceptionWrapper) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FieldAttitude(org.orekit.attitudes.FieldAttitude) OrekitException(org.orekit.errors.OrekitException) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

FieldHermiteInterpolator (org.hipparchus.analysis.interpolation.FieldHermiteInterpolator)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 FieldAttitude (org.orekit.attitudes.FieldAttitude)1 OrekitException (org.orekit.errors.OrekitException)1 OrekitExceptionWrapper (org.orekit.errors.OrekitExceptionWrapper)1 OrekitInternalError (org.orekit.errors.OrekitInternalError)1 TimeStampedCacheException (org.orekit.errors.TimeStampedCacheException)1 FieldOrbit (org.orekit.orbits.FieldOrbit)1 FieldAbsoluteDate (org.orekit.time.FieldAbsoluteDate)1