Search in sources :

Example 1 with UnivariateDifferentiableFunction

use of org.hipparchus.analysis.differentiation.UnivariateDifferentiableFunction in project Orekit by CS-SI.

the class PoissonSeriesParserTest method testDerivativesAsField.

@Test
public void testDerivativesAsField() throws OrekitException {
    Utils.setDataRoot("regular-data");
    String directory = "/assets/org/orekit/IERS-conventions/";
    PoissonSeriesParser parser = new PoissonSeriesParser(17).withPolynomialPart('t', PolynomialParser.Unit.NO_UNITS).withFirstDelaunay(4).withFirstPlanetary(9).withSinCos(0, 2, 1.0, 3, 1.0);
    PoissonSeries xSeries = parser.parse(getClass().getResourceAsStream(directory + "2010/tab5.2a.txt"), "2010/tab5.2a.txt");
    PoissonSeries ySeries = parser.parse(getClass().getResourceAsStream(directory + "2010/tab5.2b.txt"), "2010/tab5.2b.txt");
    PoissonSeries zSeries = parser.parse(getClass().getResourceAsStream(directory + "2010/tab5.2d.txt"), "2010/tab5.2d.txt");
    TimeScale ut1 = TimeScalesFactory.getUT1(FramesFactory.getEOPHistory(IERSConventions.IERS_2010, true));
    FundamentalNutationArguments arguments = IERSConventions.IERS_2010.getNutationArguments(ut1);
    Coordinate xCoordinate = new Coordinate(xSeries, arguments);
    Coordinate yCoordinate = new Coordinate(ySeries, arguments);
    Coordinate zCoordinate = new Coordinate(zSeries, arguments);
    UnivariateDifferentiableFunction dx = new FiniteDifferencesDifferentiator(4, 0.4).differentiate(xCoordinate);
    UnivariateDifferentiableFunction dy = new FiniteDifferencesDifferentiator(4, 0.4).differentiate(yCoordinate);
    UnivariateDifferentiableFunction dz = new FiniteDifferencesDifferentiator(4, 0.4).differentiate(zCoordinate);
    DSFactory factory = new DSFactory(1, 1);
    FieldAbsoluteDate<DerivativeStructure> ds2000 = FieldAbsoluteDate.getJ2000Epoch(factory.getDerivativeField());
    for (double t = 0; t < Constants.JULIAN_DAY; t += 120) {
        final FieldAbsoluteDate<DerivativeStructure> date = ds2000.shiftedBy(factory.variable(0, t));
        // direct computation of derivatives
        FieldBodiesElements<DerivativeStructure> elements = arguments.evaluateAll(date);
        Assert.assertEquals(0.0, elements.getDate().durationFrom(date).getValue(), 1.0e-15);
        DerivativeStructure xDirect = xSeries.value(elements);
        DerivativeStructure yDirect = ySeries.value(elements);
        DerivativeStructure zDirect = zSeries.value(elements);
        // finite differences computation of derivatives
        DerivativeStructure zero = factory.variable(0, 0.0);
        xCoordinate.setDate(date.toAbsoluteDate());
        DerivativeStructure xFinite = dx.value(zero);
        yCoordinate.setDate(date.toAbsoluteDate());
        DerivativeStructure yFinite = dy.value(zero);
        zCoordinate.setDate(date.toAbsoluteDate());
        DerivativeStructure zFinite = dz.value(zero);
        Assert.assertEquals(xFinite.getValue(), xDirect.getValue(), FastMath.abs(7.0e-15 * xFinite.getValue()));
        Assert.assertEquals(xFinite.getPartialDerivative(1), xDirect.getPartialDerivative(1), FastMath.abs(2.0e-07 * xFinite.getPartialDerivative(1)));
        Assert.assertEquals(yFinite.getValue(), yDirect.getValue(), FastMath.abs(7.0e-15 * yFinite.getValue()));
        Assert.assertEquals(yFinite.getPartialDerivative(1), yDirect.getPartialDerivative(1), FastMath.abs(2.0e-07 * yFinite.getPartialDerivative(1)));
        Assert.assertEquals(zFinite.getValue(), zDirect.getValue(), FastMath.abs(7.0e-15 * zFinite.getValue()));
        Assert.assertEquals(zFinite.getPartialDerivative(1), zDirect.getPartialDerivative(1), FastMath.abs(2.0e-07 * zFinite.getPartialDerivative(1)));
    }
}
Also used : DerivativeStructure(org.hipparchus.analysis.differentiation.DerivativeStructure) DSFactory(org.hipparchus.analysis.differentiation.DSFactory) TimeScale(org.orekit.time.TimeScale) UnivariateDifferentiableFunction(org.hipparchus.analysis.differentiation.UnivariateDifferentiableFunction) FiniteDifferencesDifferentiator(org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator) Test(org.junit.Test)

Example 2 with UnivariateDifferentiableFunction

use of org.hipparchus.analysis.differentiation.UnivariateDifferentiableFunction in project Orekit by CS-SI.

the class IERSConventionsTest method checkScalarFunctionConsistency.

private void checkScalarFunctionConsistency(final TimeScalarFunction function, final AbsoluteDate date, final double span, final double sampleStep, final double h, final double valueTolerance, final double derivativeTolerance) {
    UnivariateDifferentiableFunction differentiated = new FiniteDifferencesDifferentiator(4, h).differentiate(new UnivariateFunction() {

        @Override
        public double value(final double dt) {
            return function.value(date.shiftedBy(dt));
        }
    });
    DSFactory factory = new DSFactory(1, 1);
    FieldAbsoluteDate<DerivativeStructure> dsDate = new FieldAbsoluteDate<>(date, factory.constant(0.0));
    double maxValueError = 0;
    double maxDerivativeError = 0;
    for (double dt = 0; dt < span; dt += sampleStep) {
        DerivativeStructure dsdt = factory.variable(0, dt);
        DerivativeStructure yRef = differentiated.value(dsdt);
        DerivativeStructure y = function.value(dsDate.shiftedBy(dsdt));
        maxValueError = FastMath.max(maxValueError, FastMath.abs(yRef.getValue() - y.getValue()));
        maxDerivativeError = FastMath.max(maxDerivativeError, FastMath.abs(yRef.getPartialDerivative(1) - y.getPartialDerivative(1)));
    }
    Assert.assertEquals(0, maxValueError, valueTolerance);
    Assert.assertEquals(0, maxDerivativeError, derivativeTolerance);
}
Also used : UnivariateFunction(org.hipparchus.analysis.UnivariateFunction) DerivativeStructure(org.hipparchus.analysis.differentiation.DerivativeStructure) UnivariateDifferentiableFunction(org.hipparchus.analysis.differentiation.UnivariateDifferentiableFunction) DSFactory(org.hipparchus.analysis.differentiation.DSFactory) FieldAbsoluteDate(org.orekit.time.FieldAbsoluteDate) FiniteDifferencesDifferentiator(org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator)

Example 3 with UnivariateDifferentiableFunction

use of org.hipparchus.analysis.differentiation.UnivariateDifferentiableFunction in project Orekit by CS-SI.

the class IERSConventionsTest method checkGMSTRate.

private void checkGMSTRate(final TimeScalarFunction gmst, final TimeScalarFunction gmstRate, final AbsoluteDate date, final double span, final double sampleStep, final double h, final double tolerance) throws OrekitException {
    UnivariateDifferentiableFunction differentiated = new FiniteDifferencesDifferentiator(4, h).differentiate(new UnivariateFunction() {

        @Override
        public double value(final double dt) {
            return gmst.value(date.shiftedBy(dt));
        }
    });
    DSFactory factory = new DSFactory(1, 1);
    double maxRateError = 0;
    for (double dt = 0; dt < span; dt += sampleStep) {
        double rateRef = differentiated.value(factory.variable(0, dt)).getPartialDerivative(1);
        double rate = gmstRate.value(date.shiftedBy(dt));
        maxRateError = FastMath.max(maxRateError, FastMath.abs(rateRef - rate));
    }
    Assert.assertEquals(0, maxRateError, tolerance);
}
Also used : UnivariateFunction(org.hipparchus.analysis.UnivariateFunction) UnivariateDifferentiableFunction(org.hipparchus.analysis.differentiation.UnivariateDifferentiableFunction) DSFactory(org.hipparchus.analysis.differentiation.DSFactory) FiniteDifferencesDifferentiator(org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator)

Example 4 with UnivariateDifferentiableFunction

use of org.hipparchus.analysis.differentiation.UnivariateDifferentiableFunction in project Orekit by CS-SI.

the class CartesianOrbitTest method differentiate.

private <S extends Function<CartesianOrbit, Double>> double differentiate(TimeStampedPVCoordinates pv, Frame frame, double mu, S picker) {
    final DSFactory factory = new DSFactory(1, 1);
    FiniteDifferencesDifferentiator differentiator = new FiniteDifferencesDifferentiator(8, 0.1);
    UnivariateDifferentiableFunction diff = differentiator.differentiate(new UnivariateFunction() {

        public double value(double dt) {
            return picker.apply(new CartesianOrbit(pv.shiftedBy(dt), frame, mu));
        }
    });
    return diff.value(factory.variable(0, 0.0)).getPartialDerivative(1);
}
Also used : UnivariateFunction(org.hipparchus.analysis.UnivariateFunction) DSFactory(org.hipparchus.analysis.differentiation.DSFactory) UnivariateDifferentiableFunction(org.hipparchus.analysis.differentiation.UnivariateDifferentiableFunction) FiniteDifferencesDifferentiator(org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator)

Example 5 with UnivariateDifferentiableFunction

use of org.hipparchus.analysis.differentiation.UnivariateDifferentiableFunction in project Orekit by CS-SI.

the class CircularOrbitTest method differentiate.

private <S extends Function<CircularOrbit, Double>> double differentiate(TimeStampedPVCoordinates pv, Frame frame, double mu, S picker) {
    final DSFactory factory = new DSFactory(1, 1);
    FiniteDifferencesDifferentiator differentiator = new FiniteDifferencesDifferentiator(8, 0.1);
    UnivariateDifferentiableFunction diff = differentiator.differentiate(new UnivariateFunction() {

        public double value(double dt) {
            return picker.apply(new CircularOrbit(pv.shiftedBy(dt), frame, mu));
        }
    });
    return diff.value(factory.variable(0, 0.0)).getPartialDerivative(1);
}
Also used : UnivariateFunction(org.hipparchus.analysis.UnivariateFunction) DSFactory(org.hipparchus.analysis.differentiation.DSFactory) UnivariateDifferentiableFunction(org.hipparchus.analysis.differentiation.UnivariateDifferentiableFunction) FiniteDifferencesDifferentiator(org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator)

Aggregations

UnivariateDifferentiableFunction (org.hipparchus.analysis.differentiation.UnivariateDifferentiableFunction)18 DSFactory (org.hipparchus.analysis.differentiation.DSFactory)17 FiniteDifferencesDifferentiator (org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator)16 UnivariateFunction (org.hipparchus.analysis.UnivariateFunction)15 DerivativeStructure (org.hipparchus.analysis.differentiation.DerivativeStructure)7 Test (org.junit.Test)5 FieldAbsoluteDate (org.orekit.time.FieldAbsoluteDate)4 TimeScale (org.orekit.time.TimeScale)3 AbsoluteDate (org.orekit.time.AbsoluteDate)2 IERSConventions (org.orekit.utils.IERSConventions)2 UnivariateVectorFunction (org.hipparchus.analysis.UnivariateVectorFunction)1 UnivariateDifferentiableVectorFunction (org.hipparchus.analysis.differentiation.UnivariateDifferentiableVectorFunction)1 Decimal64 (org.hipparchus.util.Decimal64)1 OldIAUPole (org.orekit.bodies.IAUPoleFactory.OldIAUPole)1 OrekitException (org.orekit.errors.OrekitException)1 OrekitExceptionWrapper (org.orekit.errors.OrekitExceptionWrapper)1 PVCoordinates (org.orekit.utils.PVCoordinates)1 TimeStampedPVCoordinates (org.orekit.utils.TimeStampedPVCoordinates)1