Search in sources :

Example 11 with DSFactory

use of org.hipparchus.analysis.differentiation.DSFactory 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 12 with DSFactory

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

the class IERSConventionsTest method checkVectorFunctionConsistency.

private void checkVectorFunctionConsistency(final TimeVectorFunction function, final int dimension, final AbsoluteDate date, final double span, final double sampleStep, final double h, final double valueTolerance, final double derivativeTolerance) {
    UnivariateDifferentiableVectorFunction differentiated = new FiniteDifferencesDifferentiator(4, h).differentiate(new UnivariateVectorFunction() {

        @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));
        Assert.assertEquals(dimension, yRef.length);
        Assert.assertEquals(dimension, y.length);
        for (int i = 0; i < dimension; ++i) {
            maxValueError = FastMath.max(maxValueError, FastMath.abs(yRef[i].getValue() - y[i].getValue()));
            maxDerivativeError = FastMath.max(maxDerivativeError, FastMath.abs(yRef[i].getPartialDerivative(1) - y[i].getPartialDerivative(1)));
        }
    }
    Assert.assertEquals(0, maxValueError, valueTolerance);
    Assert.assertEquals(0, maxDerivativeError, derivativeTolerance);
}
Also used : UnivariateVectorFunction(org.hipparchus.analysis.UnivariateVectorFunction) DerivativeStructure(org.hipparchus.analysis.differentiation.DerivativeStructure) DSFactory(org.hipparchus.analysis.differentiation.DSFactory) FieldAbsoluteDate(org.orekit.time.FieldAbsoluteDate) FiniteDifferencesDifferentiator(org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator) UnivariateDifferentiableVectorFunction(org.hipparchus.analysis.differentiation.UnivariateDifferentiableVectorFunction)

Example 13 with DSFactory

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

the class TimeStampedFieldAngularCoordinatesTest method testInterpolationAroundPI.

@Test
public void testInterpolationAroundPI() throws OrekitException {
    DSFactory factory = new DSFactory(4, 1);
    List<TimeStampedFieldAngularCoordinates<DerivativeStructure>> sample = new ArrayList<TimeStampedFieldAngularCoordinates<DerivativeStructure>>();
    // add angular coordinates at t0: 179.999 degrees rotation along X axis
    AbsoluteDate t0 = new AbsoluteDate("2012-01-01T00:00:00.000", TimeScalesFactory.getTAI());
    TimeStampedFieldAngularCoordinates<DerivativeStructure> ac0 = new TimeStampedFieldAngularCoordinates<>(t0, new FieldRotation<>(createVector(1, 0, 0, 4), factory.variable(3, FastMath.toRadians(179.999)), RotationConvention.VECTOR_OPERATOR), createVector(FastMath.toRadians(0), 0, 0, 4), createVector(0, 0, 0, 4));
    sample.add(ac0);
    // add angular coordinates at t1: -179.999 degrees rotation (= 180.001 degrees) along X axis
    AbsoluteDate t1 = new AbsoluteDate("2012-01-01T00:00:02.000", TimeScalesFactory.getTAI());
    TimeStampedFieldAngularCoordinates<DerivativeStructure> ac1 = new TimeStampedFieldAngularCoordinates<>(t1, new FieldRotation<>(createVector(1, 0, 0, 4), factory.variable(3, FastMath.toRadians(-179.999)), RotationConvention.VECTOR_OPERATOR), createVector(FastMath.toRadians(0), 0, 0, 4), createVector(0, 0, 0, 4));
    sample.add(ac1);
    // get interpolated angular coordinates at mid time between t0 and t1
    AbsoluteDate t = new AbsoluteDate("2012-01-01T00:00:01.000", TimeScalesFactory.getTAI());
    TimeStampedFieldAngularCoordinates<DerivativeStructure> interpolated = TimeStampedFieldAngularCoordinates.interpolate(t, AngularDerivativesFilter.USE_R, sample);
    Assert.assertEquals(FastMath.toRadians(180), interpolated.getRotation().getAngle().getReal(), 1.0e-12);
}
Also used : ArrayList(java.util.ArrayList) DerivativeStructure(org.hipparchus.analysis.differentiation.DerivativeStructure) DSFactory(org.hipparchus.analysis.differentiation.DSFactory) AbsoluteDate(org.orekit.time.AbsoluteDate) Test(org.junit.Test)

Example 14 with DSFactory

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

the class FieldAngularCoordinatesTest method testRodriguesSpecialCases.

@Test
public void testRodriguesSpecialCases() {
    // identity
    DerivativeStructure[][] identity = FieldAngularCoordinates.getIdentity(new DSFactory(2, 2).getDerivativeField()).getModifiedRodrigues(1.0);
    for (DerivativeStructure[] row : identity) {
        for (DerivativeStructure element : row) {
            Assert.assertEquals(0.0, element.getReal(), Precision.SAFE_MIN);
        }
    }
    FieldAngularCoordinates<DerivativeStructure> acId = FieldAngularCoordinates.createFromModifiedRodrigues(identity);
    Assert.assertEquals(0.0, acId.getRotation().getAngle().getReal(), Precision.SAFE_MIN);
    Assert.assertEquals(0.0, acId.getRotationRate().getNorm().getReal(), Precision.SAFE_MIN);
    // PI angle rotation (which is singular for non-modified Rodrigues vector)
    RandomGenerator random = new Well1024a(0x4923ec495bca9fb4l);
    for (int i = 0; i < 100; ++i) {
        FieldVector3D<DerivativeStructure> axis = randomVector(random, 1.0);
        final Field<DerivativeStructure> field = axis.getX().getField();
        FieldAngularCoordinates<DerivativeStructure> original = new FieldAngularCoordinates<>(new FieldRotation<>(axis, field.getZero().add(FastMath.PI), RotationConvention.VECTOR_OPERATOR), FieldVector3D.getZero(field), FieldVector3D.getZero(field));
        FieldAngularCoordinates<DerivativeStructure> rebuilt = FieldAngularCoordinates.createFromModifiedRodrigues(original.getModifiedRodrigues(1.0));
        Assert.assertEquals(FastMath.PI, rebuilt.getRotation().getAngle().getReal(), 1.0e-15);
        Assert.assertEquals(0.0, FieldVector3D.angle(axis, rebuilt.getRotation().getAxis(RotationConvention.VECTOR_OPERATOR)).sin().getReal(), 1.0e-15);
        Assert.assertEquals(0.0, rebuilt.getRotationRate().getNorm().getReal(), 1.0e-16);
    }
}
Also used : DerivativeStructure(org.hipparchus.analysis.differentiation.DerivativeStructure) DSFactory(org.hipparchus.analysis.differentiation.DSFactory) RandomGenerator(org.hipparchus.random.RandomGenerator) Well1024a(org.hipparchus.random.Well1024a) Test(org.junit.Test)

Example 15 with DSFactory

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

the class PVCoordinatesTest method testNormalize.

@Test
public void testNormalize() {
    DSFactory factory = new DSFactory(1, 2);
    RandomGenerator generator = new Well19937a(0xb2011ffd25412067l);
    FiniteDifferencesDifferentiator differentiator = new FiniteDifferencesDifferentiator(5, 1.0e-3);
    for (int i = 0; i < 200; ++i) {
        final PVCoordinates 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();
            }
        }).value(factory.variable(0, 0.0));
        DerivativeStructure y = differentiator.differentiate(new UnivariateFunction() {

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

            public double value(double t) {
                return pv.shiftedBy(t).getPosition().normalize().getZ();
            }
        }).value(factory.variable(0, 0.0));
        PVCoordinates normalized = pv.normalize();
        Assert.assertEquals(x.getValue(), normalized.getPosition().getX(), 1.0e-16);
        Assert.assertEquals(y.getValue(), normalized.getPosition().getY(), 1.0e-16);
        Assert.assertEquals(z.getValue(), normalized.getPosition().getZ(), 1.0e-16);
        Assert.assertEquals(x.getPartialDerivative(1), normalized.getVelocity().getX(), 3.0e-13);
        Assert.assertEquals(y.getPartialDerivative(1), normalized.getVelocity().getY(), 3.0e-13);
        Assert.assertEquals(z.getPartialDerivative(1), normalized.getVelocity().getZ(), 3.0e-13);
        Assert.assertEquals(x.getPartialDerivative(2), normalized.getAcceleration().getX(), 6.0e-10);
        Assert.assertEquals(y.getPartialDerivative(2), normalized.getAcceleration().getY(), 6.0e-10);
        Assert.assertEquals(z.getPartialDerivative(2), normalized.getAcceleration().getZ(), 6.0e-10);
    }
}
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)

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