Search in sources :

Example 91 with RandomGenerator

use of org.hipparchus.random.RandomGenerator 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 92 with RandomGenerator

use of org.hipparchus.random.RandomGenerator in project Orekit by CS-SI.

the class TimeStampedAngularCoordinatesTest method testOnePair.

@Test
public void testOnePair() throws OrekitException, java.io.IOException {
    RandomGenerator random = new Well1024a(0xed7dd911a44c5197l);
    for (int i = 0; i < 20; ++i) {
        Rotation r = randomRotation(random);
        Vector3D o = randomVector(random, 1.0e-2);
        Vector3D a = randomVector(random, 1.0e-2);
        TimeStampedAngularCoordinates reference = new TimeStampedAngularCoordinates(AbsoluteDate.J2000_EPOCH, r, o, a);
        PVCoordinates u = randomPVCoordinates(random, 1000, 1.0, 0.001);
        PVCoordinates v = reference.applyTo(u);
        TimeStampedAngularCoordinates ac = new TimeStampedAngularCoordinates(AbsoluteDate.J2000_EPOCH, u, v);
        Assert.assertEquals(0, Vector3D.distance(v.getPosition().normalize(), ac.applyTo(u).getPosition().normalize()), 1.0e-14);
        Assert.assertEquals(0, Vector3D.distance(v.getVelocity().normalize(), ac.applyTo(u).getVelocity().normalize()), 4.0e-14);
        Assert.assertEquals(0, Vector3D.distance(v.getAcceleration().normalize(), ac.applyTo(u).getAcceleration().normalize()), 1.0e-14);
    }
}
Also used : Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) Rotation(org.hipparchus.geometry.euclidean.threed.Rotation) RandomGenerator(org.hipparchus.random.RandomGenerator) Well1024a(org.hipparchus.random.Well1024a) Test(org.junit.Test)

Example 93 with RandomGenerator

use of org.hipparchus.random.RandomGenerator in project Orekit by CS-SI.

the class TimeStampedAngularCoordinatesTest method testTwoPairs.

@Test
public void testTwoPairs() throws OrekitException, java.io.IOException {
    RandomGenerator random = new Well1024a(0x976ad943966c9f00l);
    for (int i = 0; i < 20; ++i) {
        Rotation r = randomRotation(random);
        Vector3D o = randomVector(random, 1.0e-2);
        Vector3D a = randomVector(random, 1.0e-2);
        TimeStampedAngularCoordinates reference = new TimeStampedAngularCoordinates(AbsoluteDate.J2000_EPOCH, r, o, a);
        PVCoordinates u1 = randomPVCoordinates(random, 1000, 1.0, 0.001);
        PVCoordinates u2 = randomPVCoordinates(random, 1000, 1.0, 0.001);
        PVCoordinates v1 = reference.applyTo(u1);
        PVCoordinates v2 = reference.applyTo(u2);
        TimeStampedAngularCoordinates ac = new TimeStampedAngularCoordinates(AbsoluteDate.J2000_EPOCH, u1, u2, v1, v2, 1.0e-9);
        Assert.assertEquals(0, Vector3D.distance(v1.getPosition().normalize(), ac.applyTo(u1).getPosition().normalize()), 1.0e-14);
        Assert.assertEquals(0, Vector3D.distance(v1.getVelocity().normalize(), ac.applyTo(u1).getVelocity().normalize()), 1.0e-14);
        Assert.assertEquals(0, Vector3D.distance(v1.getAcceleration().normalize(), ac.applyTo(u1).getAcceleration().normalize()), 1.0e-14);
        Assert.assertEquals(0, Vector3D.distance(v2.getPosition().normalize(), ac.applyTo(u2).getPosition().normalize()), 1.0e-14);
        Assert.assertEquals(0, Vector3D.distance(v2.getVelocity().normalize(), ac.applyTo(u2).getVelocity().normalize()), 1.0e-14);
        Assert.assertEquals(0, Vector3D.distance(v2.getAcceleration().normalize(), ac.applyTo(u2).getAcceleration().normalize()), 1.0e-14);
    }
}
Also used : Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) Rotation(org.hipparchus.geometry.euclidean.threed.Rotation) RandomGenerator(org.hipparchus.random.RandomGenerator) Well1024a(org.hipparchus.random.Well1024a) Test(org.junit.Test)

Example 94 with RandomGenerator

use of org.hipparchus.random.RandomGenerator in project Orekit by CS-SI.

the class TimeStampedAngularCoordinatesTest method testReverseOffset.

@Test
public void testReverseOffset() {
    RandomGenerator random = new Well1024a(0x4ecca9d57a8f1611l);
    for (int i = 0; i < 100; ++i) {
        Rotation r = randomRotation(random);
        Vector3D o = randomVector(random, 1.0e-3);
        Vector3D a = randomVector(random, 1.0e-3);
        TimeStampedAngularCoordinates ac = new TimeStampedAngularCoordinates(AbsoluteDate.J2000_EPOCH, r, o, a);
        TimeStampedAngularCoordinates sum = ac.addOffset(ac.revert());
        Assert.assertEquals(0.0, sum.getRotation().getAngle(), 1.0e-15);
        Assert.assertEquals(0.0, sum.getRotationRate().getNorm(), 1.0e-15);
        Assert.assertEquals(0.0, sum.getRotationAcceleration().getNorm(), 1.0e-15);
    }
}
Also used : Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) Rotation(org.hipparchus.geometry.euclidean.threed.Rotation) RandomGenerator(org.hipparchus.random.RandomGenerator) Well1024a(org.hipparchus.random.Well1024a) Test(org.junit.Test)

Example 95 with RandomGenerator

use of org.hipparchus.random.RandomGenerator in project Orekit by CS-SI.

the class UTCScaleTest method testMultithreading.

@Test
public void testMultithreading() {
    // generate reference offsets using a single thread
    RandomGenerator random = new Well1024a(6392073424l);
    List<AbsoluteDate> datesList = new ArrayList<AbsoluteDate>();
    List<Double> offsetsList = new ArrayList<Double>();
    AbsoluteDate reference = utc.getFirstKnownLeapSecond().shiftedBy(-Constants.JULIAN_YEAR);
    double testRange = utc.getLastKnownLeapSecond().durationFrom(reference) + Constants.JULIAN_YEAR;
    for (int i = 0; i < 10000; ++i) {
        AbsoluteDate randomDate = reference.shiftedBy(random.nextDouble() * testRange);
        datesList.add(randomDate);
        offsetsList.add(utc.offsetFromTAI(randomDate));
    }
    // check the offsets in multi-threaded mode
    ExecutorService executorService = Executors.newFixedThreadPool(100);
    for (int i = 0; i < datesList.size(); ++i) {
        final AbsoluteDate date = datesList.get(i);
        final double offset = offsetsList.get(i);
        executorService.execute(new Runnable() {

            public void run() {
                Assert.assertEquals(offset, utc.offsetFromTAI(date), 1.0e-12);
            }
        });
    }
    try {
        executorService.shutdown();
        executorService.awaitTermination(3, TimeUnit.SECONDS);
    } catch (InterruptedException ie) {
        Assert.fail(ie.getLocalizedMessage());
    }
}
Also used : ArrayList(java.util.ArrayList) ExecutorService(java.util.concurrent.ExecutorService) RandomGenerator(org.hipparchus.random.RandomGenerator) Well1024a(org.hipparchus.random.Well1024a) Test(org.junit.Test)

Aggregations

RandomGenerator (org.hipparchus.random.RandomGenerator)100 Test (org.junit.Test)78 Well19937a (org.hipparchus.random.Well19937a)73 Vector3D (org.hipparchus.geometry.euclidean.threed.Vector3D)33 Well1024a (org.hipparchus.random.Well1024a)27 DerivativeStructure (org.hipparchus.analysis.differentiation.DerivativeStructure)22 FieldPVCoordinates (org.orekit.utils.FieldPVCoordinates)22 GeodeticPoint (org.orekit.bodies.GeodeticPoint)20 Rotation (org.hipparchus.geometry.euclidean.threed.Rotation)19 PVCoordinates (org.orekit.utils.PVCoordinates)15 TimeStampedFieldPVCoordinates (org.orekit.utils.TimeStampedFieldPVCoordinates)15 DSFactory (org.hipparchus.analysis.differentiation.DSFactory)14 FieldVector3D (org.hipparchus.geometry.euclidean.threed.FieldVector3D)14 FieldAbsoluteDate (org.orekit.time.FieldAbsoluteDate)14 Frame (org.orekit.frames.Frame)10 GaussianRandomGenerator (org.hipparchus.random.GaussianRandomGenerator)8 UncorrelatedRandomVectorGenerator (org.hipparchus.random.UncorrelatedRandomVectorGenerator)8 FieldKeplerianOrbit (org.orekit.orbits.FieldKeplerianOrbit)8 OrbitType (org.orekit.orbits.OrbitType)8 FieldSpacecraftState (org.orekit.propagation.FieldSpacecraftState)8