Search in sources :

Example 16 with DerivativeStructure

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

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

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

the class TimeStampedFieldAngularCoordinatesTest method testInterpolationNeedOffsetWrongRate.

@Test
public void testInterpolationNeedOffsetWrongRate() throws OrekitException {
    AbsoluteDate date = AbsoluteDate.GALILEO_EPOCH;
    double omega = 2.0 * FastMath.PI;
    TimeStampedFieldAngularCoordinates<DerivativeStructure> reference = new TimeStampedFieldAngularCoordinates<>(date, createRotation(1, 0, 0, 0, false), createVector(0, 0, -omega, 4), createVector(0, 0, 0, 4));
    List<TimeStampedFieldAngularCoordinates<DerivativeStructure>> sample = new ArrayList<TimeStampedFieldAngularCoordinates<DerivativeStructure>>();
    for (double dt : new double[] { 0.0, 0.25, 0.5, 0.75, 1.0 }) {
        TimeStampedFieldAngularCoordinates<DerivativeStructure> shifted = reference.shiftedBy(dt);
        sample.add(new TimeStampedFieldAngularCoordinates<>(shifted.getDate(), shifted.getRotation(), createVector(0, 0, 0, 4), createVector(0, 0, 0, 4)));
    }
    for (TimeStampedFieldAngularCoordinates<DerivativeStructure> s : sample) {
        TimeStampedFieldAngularCoordinates<DerivativeStructure> interpolated = TimeStampedFieldAngularCoordinates.interpolate(s.getDate(), AngularDerivativesFilter.USE_RR, sample);
        FieldRotation<DerivativeStructure> r = interpolated.getRotation();
        FieldVector3D<DerivativeStructure> rate = interpolated.getRotationRate();
        Assert.assertEquals(0.0, FieldRotation.distance(s.getRotation(), r).getReal(), 2.0e-14);
        Assert.assertEquals(0.0, FieldVector3D.distance(s.getRotationRate(), rate).getReal(), 2.0e-13);
    }
}
Also used : DerivativeStructure(org.hipparchus.analysis.differentiation.DerivativeStructure) ArrayList(java.util.ArrayList) AbsoluteDate(org.orekit.time.AbsoluteDate) Test(org.junit.Test)

Example 19 with DerivativeStructure

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

the class TimeStampedPVCoordinatesTest method testToDerivativeStructureVector2.

@Test
public void testToDerivativeStructureVector2() throws OrekitException {
    FieldVector3D<DerivativeStructure> fv = new TimeStampedPVCoordinates(AbsoluteDate.GALILEO_EPOCH, new Vector3D(1, 0.1, 10), new Vector3D(-1, -0.1, -10), new Vector3D(10, -1.0, -100)).toDerivativeStructureVector(2);
    Assert.assertEquals(1, fv.getX().getFreeParameters());
    Assert.assertEquals(2, fv.getX().getOrder());
    Assert.assertEquals(1.0, fv.getX().getReal(), 1.0e-10);
    Assert.assertEquals(0.1, fv.getY().getReal(), 1.0e-10);
    Assert.assertEquals(10.0, fv.getZ().getReal(), 1.0e-10);
    Assert.assertEquals(-1.0, fv.getX().getPartialDerivative(1), 1.0e-15);
    Assert.assertEquals(-0.1, fv.getY().getPartialDerivative(1), 1.0e-15);
    Assert.assertEquals(-10.0, fv.getZ().getPartialDerivative(1), 1.0e-15);
    Assert.assertEquals(10.0, fv.getX().getPartialDerivative(2), 1.0e-15);
    Assert.assertEquals(-1.0, fv.getY().getPartialDerivative(2), 1.0e-15);
    Assert.assertEquals(-100.0, fv.getZ().getPartialDerivative(2), 1.0e-15);
    checkPV(new TimeStampedPVCoordinates(AbsoluteDate.GALILEO_EPOCH, new Vector3D(1, 0.1, 10), new Vector3D(-1, -0.1, -10), new Vector3D(10, -1.0, -100)), new TimeStampedPVCoordinates(AbsoluteDate.GALILEO_EPOCH, fv), 1.0e-15);
    for (double dt = 0; dt < 10; dt += 0.125) {
        Vector3D p = new PVCoordinates(new Vector3D(1, 0.1, 10), new Vector3D(-1, -0.1, -10), new Vector3D(10, -1.0, -100)).shiftedBy(dt).getPosition();
        Assert.assertEquals(p.getX(), fv.getX().taylor(dt), 1.0e-14);
        Assert.assertEquals(p.getY(), fv.getY().taylor(dt), 1.0e-14);
        Assert.assertEquals(p.getZ(), fv.getZ().taylor(dt), 1.0e-14);
    }
}
Also used : Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) FieldVector3D(org.hipparchus.geometry.euclidean.threed.FieldVector3D) DerivativeStructure(org.hipparchus.analysis.differentiation.DerivativeStructure) Test(org.junit.Test)

Example 20 with DerivativeStructure

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

the class FieldAngularCoordinatesTest method testRoundTripNoOp.

@Test
public void testRoundTripNoOp() {
    RandomGenerator random = new Well1024a(0x1e610cfe89306669l);
    for (int i = 0; i < 100; ++i) {
        FieldRotation<DerivativeStructure> r1 = randomRotation(random);
        FieldVector3D<DerivativeStructure> o1 = randomVector(random, 1.0e-2);
        FieldVector3D<DerivativeStructure> a1 = randomVector(random, 1.0e-2);
        FieldAngularCoordinates<DerivativeStructure> ac1 = new FieldAngularCoordinates<>(r1, o1, a1);
        FieldRotation<DerivativeStructure> r2 = randomRotation(random);
        FieldVector3D<DerivativeStructure> o2 = randomVector(random, 1.0e-2);
        FieldVector3D<DerivativeStructure> a2 = randomVector(random, 1.0e-2);
        FieldAngularCoordinates<DerivativeStructure> ac2 = new FieldAngularCoordinates<>(r2, o2, a2);
        FieldAngularCoordinates<DerivativeStructure> roundTripSA = ac1.subtractOffset(ac2).addOffset(ac2);
        Assert.assertEquals(0.0, FieldRotation.distance(ac1.getRotation(), roundTripSA.getRotation()).getReal(), 1.0e-15);
        Assert.assertEquals(0.0, FieldVector3D.distance(ac1.getRotationRate(), roundTripSA.getRotationRate()).getReal(), 2.0e-17);
        Assert.assertEquals(0.0, FieldVector3D.distance(ac1.getRotationAcceleration(), roundTripSA.getRotationAcceleration()).getReal(), 2.0e-17);
        FieldAngularCoordinates<DerivativeStructure> roundTripAS = ac1.addOffset(ac2).subtractOffset(ac2);
        Assert.assertEquals(0.0, FieldRotation.distance(ac1.getRotation(), roundTripAS.getRotation()).getReal(), 1.0e-15);
        Assert.assertEquals(0.0, FieldVector3D.distance(ac1.getRotationRate(), roundTripAS.getRotationRate()).getReal(), 2.0e-17);
        Assert.assertEquals(0.0, FieldVector3D.distance(ac1.getRotationAcceleration(), roundTripAS.getRotationAcceleration()).getReal(), 2.0e-17);
    }
}
Also used : DerivativeStructure(org.hipparchus.analysis.differentiation.DerivativeStructure) RandomGenerator(org.hipparchus.random.RandomGenerator) Well1024a(org.hipparchus.random.Well1024a) Test(org.junit.Test)

Aggregations

DerivativeStructure (org.hipparchus.analysis.differentiation.DerivativeStructure)140 Test (org.junit.Test)69 DSFactory (org.hipparchus.analysis.differentiation.DSFactory)63 FieldVector3D (org.hipparchus.geometry.euclidean.threed.FieldVector3D)42 FieldAbsoluteDate (org.orekit.time.FieldAbsoluteDate)40 Vector3D (org.hipparchus.geometry.euclidean.threed.Vector3D)33 SpacecraftState (org.orekit.propagation.SpacecraftState)30 AbsoluteDate (org.orekit.time.AbsoluteDate)25 RandomGenerator (org.hipparchus.random.RandomGenerator)22 Frame (org.orekit.frames.Frame)22 PVCoordinates (org.orekit.utils.PVCoordinates)21 FieldSpacecraftState (org.orekit.propagation.FieldSpacecraftState)20 FieldPVCoordinates (org.orekit.utils.FieldPVCoordinates)18 OrekitException (org.orekit.errors.OrekitException)16 FiniteDifferencesDifferentiator (org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator)15 AbstractLegacyForceModelTest (org.orekit.forces.AbstractLegacyForceModelTest)15 OrbitType (org.orekit.orbits.OrbitType)15 ParameterDriver (org.orekit.utils.ParameterDriver)15 FieldKeplerianOrbit (org.orekit.orbits.FieldKeplerianOrbit)14 FieldNumericalPropagator (org.orekit.propagation.numerical.FieldNumericalPropagator)14