Search in sources :

Example 71 with DSFactory

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

the class KeplerianOrbitTest method differentiate.

private <S extends Function<KeplerianOrbit, 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 KeplerianOrbit(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 72 with DSFactory

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

the class IERSConventionsTest method testGMST2000vs82.

@Test
public void testGMST2000vs82() throws OrekitException {
    final TimeScalarFunction gmst82 = IERSConventions.IERS_1996.getGMSTFunction(TimeScalesFactory.getUT1(IERSConventions.IERS_1996, true));
    final TimeScalarFunction gmst00 = IERSConventions.IERS_2003.getGMSTFunction(TimeScalesFactory.getUT1(IERSConventions.IERS_2003, true));
    final DSFactory factory = new DSFactory(1, 1);
    final FieldAbsoluteDate<DerivativeStructure> ds2000 = FieldAbsoluteDate.getJ2000Epoch(factory.getDerivativeField());
    for (double dt = 0; dt < 10 * Constants.JULIAN_YEAR; dt += 10 * Constants.JULIAN_DAY) {
        FieldAbsoluteDate<DerivativeStructure> date = ds2000.shiftedBy(factory.variable(0, dt));
        DerivativeStructure delta = gmst00.value(date).subtract(gmst82.value(date));
        // GMST82 and GMST2000 are similar to about 15 milli-arcseconds between 2000 and 2010
        Assert.assertEquals(0.0, MathUtils.normalizeAngle(delta.getValue(), 0.0), 7.1e-8);
        Assert.assertEquals(0.0, delta.getPartialDerivative(1), 1.0e-15);
    }
}
Also used : DerivativeStructure(org.hipparchus.analysis.differentiation.DerivativeStructure) DSFactory(org.hipparchus.analysis.differentiation.DSFactory) TimeScalarFunction(org.orekit.time.TimeScalarFunction) Test(org.junit.Test)

Example 73 with DSFactory

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

the class TimeStampedFieldAngularCoordinatesTest method testInterpolationTooSmallSample.

@Test
public void testInterpolationTooSmallSample() throws OrekitException {
    DSFactory factory = new DSFactory(4, 1);
    AbsoluteDate date = AbsoluteDate.GALILEO_EPOCH;
    double alpha0 = 0.5 * FastMath.PI;
    double omega = 0.5 * FastMath.PI;
    TimeStampedFieldAngularCoordinates<DerivativeStructure> reference = new TimeStampedFieldAngularCoordinates<>(date, new FieldRotation<>(createVector(0, 0, 1, 4), factory.variable(3, alpha0), RotationConvention.VECTOR_OPERATOR), createVector(0, 0, -omega, 4), createVector(0, 0, 0, 4));
    List<TimeStampedFieldAngularCoordinates<DerivativeStructure>> sample = new ArrayList<TimeStampedFieldAngularCoordinates<DerivativeStructure>>();
    FieldRotation<DerivativeStructure> r = reference.shiftedBy(0.2).getRotation();
    sample.add(new TimeStampedFieldAngularCoordinates<>(date.shiftedBy(0.2), r, createVector(0, 0, 0, 4), createVector(0, 0, 0, 4)));
    try {
        TimeStampedFieldAngularCoordinates.interpolate(date.shiftedBy(0.3), AngularDerivativesFilter.USE_R, sample);
        Assert.fail("an exception should have been thrown");
    } catch (OrekitException oe) {
        Assert.assertEquals(OrekitMessages.NOT_ENOUGH_DATA_FOR_INTERPOLATION, oe.getSpecifier());
        Assert.assertEquals(1, ((Integer) oe.getParts()[0]).intValue());
    }
}
Also used : DerivativeStructure(org.hipparchus.analysis.differentiation.DerivativeStructure) ArrayList(java.util.ArrayList) DSFactory(org.hipparchus.analysis.differentiation.DSFactory) AbsoluteDate(org.orekit.time.AbsoluteDate) OrekitException(org.orekit.errors.OrekitException) Test(org.junit.Test)

Example 74 with DSFactory

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

the class PVCoordinatesTest method testCrossProduct.

@Test
public void testCrossProduct() {
    DSFactory factory = new DSFactory(1, 2);
    RandomGenerator generator = new Well19937a(0x85c592b3be733d23l);
    FiniteDifferencesDifferentiator differentiator = new FiniteDifferencesDifferentiator(5, 1.0e-3);
    for (int i = 0; i < 200; ++i) {
        final PVCoordinates pv1 = randomPVCoordinates(generator, 1.0, 1.0, 1.0);
        final PVCoordinates pv2 = randomPVCoordinates(generator, 1.0, 1.0, 1.0);
        DerivativeStructure x = differentiator.differentiate(new UnivariateFunction() {

            public double value(double t) {
                return Vector3D.crossProduct(pv1.shiftedBy(t).getPosition(), pv2.shiftedBy(t).getPosition()).getX();
            }
        }).value(factory.variable(0, 0.0));
        DerivativeStructure y = differentiator.differentiate(new UnivariateFunction() {

            public double value(double t) {
                return Vector3D.crossProduct(pv1.shiftedBy(t).getPosition(), pv2.shiftedBy(t).getPosition()).getY();
            }
        }).value(factory.variable(0, 0.0));
        DerivativeStructure z = differentiator.differentiate(new UnivariateFunction() {

            public double value(double t) {
                return Vector3D.crossProduct(pv1.shiftedBy(t).getPosition(), pv2.shiftedBy(t).getPosition()).getZ();
            }
        }).value(factory.variable(0, 0.0));
        PVCoordinates product = PVCoordinates.crossProduct(pv1, pv2);
        Assert.assertEquals(x.getValue(), product.getPosition().getX(), 1.0e-16);
        Assert.assertEquals(y.getValue(), product.getPosition().getY(), 1.0e-16);
        Assert.assertEquals(z.getValue(), product.getPosition().getZ(), 1.0e-16);
        Assert.assertEquals(x.getPartialDerivative(1), product.getVelocity().getX(), 9.0e-10);
        Assert.assertEquals(y.getPartialDerivative(1), product.getVelocity().getY(), 9.0e-10);
        Assert.assertEquals(z.getPartialDerivative(1), product.getVelocity().getZ(), 9.0e-10);
        Assert.assertEquals(x.getPartialDerivative(2), product.getAcceleration().getX(), 3.0e-9);
        Assert.assertEquals(y.getPartialDerivative(2), product.getAcceleration().getY(), 3.0e-9);
        Assert.assertEquals(z.getPartialDerivative(2), product.getAcceleration().getZ(), 3.0e-9);
    }
}
Also used : UnivariateFunction(org.hipparchus.analysis.UnivariateFunction) DerivativeStructure(org.hipparchus.analysis.differentiation.DerivativeStructure) DSFactory(org.hipparchus.analysis.differentiation.DSFactory) Well19937a(org.hipparchus.random.Well19937a) RandomGenerator(org.hipparchus.random.RandomGenerator) FiniteDifferencesDifferentiator(org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator) Test(org.junit.Test)

Example 75 with DSFactory

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

the class FieldPVCoordinatesTest method testNormalize.

@Test
public void testNormalize() {
    DSFactory factory = new DSFactory(1, 2);
    RandomGenerator generator = new Well19937a(0x7ede9376e4e1ab5al);
    FiniteDifferencesDifferentiator differentiator = new FiniteDifferencesDifferentiator(5, 1.0e-3);
    for (int i = 0; i < 200; ++i) {
        final FieldPVCoordinates<DerivativeStructure> pv = randomPVCoordinates(generator, 1e6, 1e3, 1.0);
        DerivativeStructure x = differentiator.differentiate(new UnivariateFunction() {

            public double value(double t) {
                return pv.shiftedBy(t).getPosition().normalize().getX().getValue();
            }
        }).value(factory.variable(0, 0.0));
        DerivativeStructure y = differentiator.differentiate(new UnivariateFunction() {

            public double value(double t) {
                return pv.shiftedBy(t).getPosition().normalize().getY().getValue();
            }
        }).value(factory.variable(0, 0.0));
        DerivativeStructure z = differentiator.differentiate(new UnivariateFunction() {

            public double value(double t) {
                return pv.shiftedBy(t).getPosition().normalize().getZ().getValue();
            }
        }).value(factory.variable(0, 0.0));
        FieldPVCoordinates<DerivativeStructure> normalized = pv.normalize();
        Assert.assertEquals(x.getValue(), normalized.getPosition().getX().getValue(), 1.0e-16);
        Assert.assertEquals(y.getValue(), normalized.getPosition().getY().getValue(), 1.0e-16);
        Assert.assertEquals(z.getValue(), normalized.getPosition().getZ().getValue(), 1.0e-16);
        Assert.assertEquals(x.getPartialDerivative(1), normalized.getVelocity().getX().getValue(), 3.0e-13);
        Assert.assertEquals(y.getPartialDerivative(1), normalized.getVelocity().getY().getValue(), 3.0e-13);
        Assert.assertEquals(z.getPartialDerivative(1), normalized.getVelocity().getZ().getValue(), 3.0e-13);
        Assert.assertEquals(x.getPartialDerivative(2), normalized.getAcceleration().getX().getValue(), 6.0e-10);
        Assert.assertEquals(y.getPartialDerivative(2), normalized.getAcceleration().getY().getValue(), 6.0e-10);
        Assert.assertEquals(z.getPartialDerivative(2), normalized.getAcceleration().getZ().getValue(), 6.0e-10);
    }
}
Also used : UnivariateFunction(org.hipparchus.analysis.UnivariateFunction) DerivativeStructure(org.hipparchus.analysis.differentiation.DerivativeStructure) FieldDerivativeStructure(org.hipparchus.analysis.differentiation.FieldDerivativeStructure) DSFactory(org.hipparchus.analysis.differentiation.DSFactory) Well19937a(org.hipparchus.random.Well19937a) RandomGenerator(org.hipparchus.random.RandomGenerator) FiniteDifferencesDifferentiator(org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator) Test(org.junit.Test)

Aggregations

DSFactory (org.hipparchus.analysis.differentiation.DSFactory)76 DerivativeStructure (org.hipparchus.analysis.differentiation.DerivativeStructure)64 Test (org.junit.Test)41 FieldAbsoluteDate (org.orekit.time.FieldAbsoluteDate)36 FiniteDifferencesDifferentiator (org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator)25 SpacecraftState (org.orekit.propagation.SpacecraftState)24 Frame (org.orekit.frames.Frame)23 AbsoluteDate (org.orekit.time.AbsoluteDate)20 UnivariateFunction (org.hipparchus.analysis.UnivariateFunction)18 UnivariateDifferentiableFunction (org.hipparchus.analysis.differentiation.UnivariateDifferentiableFunction)17 FieldSpacecraftState (org.orekit.propagation.FieldSpacecraftState)17 PVCoordinates (org.orekit.utils.PVCoordinates)17 FieldVector3D (org.hipparchus.geometry.euclidean.threed.FieldVector3D)16 Vector3D (org.hipparchus.geometry.euclidean.threed.Vector3D)15 OrbitType (org.orekit.orbits.OrbitType)15 RandomGenerator (org.hipparchus.random.RandomGenerator)14 FieldKeplerianOrbit (org.orekit.orbits.FieldKeplerianOrbit)14 FieldNumericalPropagator (org.orekit.propagation.numerical.FieldNumericalPropagator)14 NumericalPropagator (org.orekit.propagation.numerical.NumericalPropagator)14 FieldPVCoordinates (org.orekit.utils.FieldPVCoordinates)14