Search in sources :

Example 71 with FieldAbsoluteDate

use of org.orekit.time.FieldAbsoluteDate in project Orekit by CS-SI.

the class FieldTransformGenerator method generate.

/**
 * {@inheritDoc}
 */
public List<FieldTransform<T>> generate(final AbsoluteDate existingDate, final AbsoluteDate date) {
    try {
        final FieldAbsoluteDate<T> fieldDate = new FieldAbsoluteDate<>(field, date);
        final List<FieldTransform<T>> generated = new ArrayList<>();
        if (existingDate == null) {
            // no prior existing transforms, just generate a first set
            for (int i = 0; i < neighborsSize; ++i) {
                generated.add(provider.getTransform(fieldDate.shiftedBy(i * step)));
            }
        } else {
            // some transforms have already been generated
            // add the missing ones up to specified date
            FieldAbsoluteDate<T> t = new FieldAbsoluteDate<>(field, existingDate);
            if (date.compareTo(t.toAbsoluteDate()) > 0) {
                // forward generation
                do {
                    t = t.shiftedBy(step);
                    generated.add(generated.size(), provider.getTransform(t));
                } while (t.compareTo(fieldDate) <= 0);
            } else {
                // backward generation
                do {
                    t = t.shiftedBy(-step);
                    generated.add(0, provider.getTransform(t));
                } while (t.compareTo(fieldDate) >= 0);
            }
        }
        // return the generated transforms
        return generated;
    } catch (OrekitException oe) {
        throw new OrekitExceptionWrapper(oe);
    }
}
Also used : OrekitExceptionWrapper(org.orekit.errors.OrekitExceptionWrapper) ArrayList(java.util.ArrayList) OrekitException(org.orekit.errors.OrekitException) FieldAbsoluteDate(org.orekit.time.FieldAbsoluteDate)

Example 72 with FieldAbsoluteDate

use of org.orekit.time.FieldAbsoluteDate in project Orekit by CS-SI.

the class GroundStationTest method doTestCartesianDerivatives.

private void doTestCartesianDerivatives(double latitude, double longitude, double altitude, double stepFactor, double relativeTolerancePositionValue, double relativeTolerancePositionDerivative, double relativeToleranceVelocityValue, double relativeToleranceVelocityDerivative, String... parameterPattern) throws OrekitException {
    Utils.setDataRoot("regular-data");
    final Frame eme2000 = FramesFactory.getEME2000();
    final AbsoluteDate date = AbsoluteDate.J2000_EPOCH;
    final AbsoluteDate date0 = date.shiftedBy(50000);
    final OneAxisEllipsoid earth = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS, Constants.WGS84_EARTH_FLATTENING, FramesFactory.getITRF(IERSConventions.IERS_2010, true));
    final GroundStation station = new GroundStation(new TopocentricFrame(earth, new GeodeticPoint(latitude, longitude, altitude), "dummy"));
    final DSFactory factory = new DSFactory(parameterPattern.length, 1);
    final FieldAbsoluteDate<DerivativeStructure> dateDS = new FieldAbsoluteDate<>(factory.getDerivativeField(), date);
    ParameterDriver[] selectedDrivers = new ParameterDriver[parameterPattern.length];
    UnivariateDifferentiableVectorFunction[] dFCartesian = new UnivariateDifferentiableVectorFunction[parameterPattern.length];
    final ParameterDriver[] allDrivers = selectAllDrivers(station);
    for (ParameterDriver driver : allDrivers) {
        driver.setReferenceDate(date0);
    }
    Map<String, Integer> indices = new HashMap<>();
    for (int k = 0; k < dFCartesian.length; ++k) {
        for (int i = 0; i < allDrivers.length; ++i) {
            if (allDrivers[i].getName().matches(parameterPattern[k])) {
                selectedDrivers[k] = allDrivers[i];
                dFCartesian[k] = differentiatedStationPV(station, eme2000, date, selectedDrivers[k], stepFactor);
                indices.put(selectedDrivers[k].getName(), k);
            }
        }
    }
    ;
    DSFactory factory11 = new DSFactory(1, 1);
    RandomGenerator generator = new Well19937a(0x084d58a19c498a54l);
    double maxPositionValueRelativeError = 0;
    double maxPositionDerivativeRelativeError = 0;
    double maxVelocityValueRelativeError = 0;
    double maxVelocityDerivativeRelativeError = 0;
    for (int i = 0; i < 1000; ++i) {
        // randomly change one parameter
        ParameterDriver changed = allDrivers[generator.nextInt(allDrivers.length)];
        changed.setNormalizedValue(2 * generator.nextDouble() - 1);
        // transform to check
        FieldTransform<DerivativeStructure> t = station.getOffsetToInertial(eme2000, dateDS, factory, indices);
        FieldPVCoordinates<DerivativeStructure> pv = t.transformPVCoordinates(FieldPVCoordinates.getZero(factory.getDerivativeField()));
        for (int k = 0; k < dFCartesian.length; ++k) {
            // reference values and derivatives computed using finite differences
            DerivativeStructure[] refCartesian = dFCartesian[k].value(factory11.variable(0, selectedDrivers[k].getValue()));
            // position
            final Vector3D refP = new Vector3D(refCartesian[0].getValue(), refCartesian[1].getValue(), refCartesian[2].getValue());
            final Vector3D resP = new Vector3D(pv.getPosition().getX().getValue(), pv.getPosition().getY().getValue(), pv.getPosition().getZ().getValue());
            maxPositionValueRelativeError = FastMath.max(maxPositionValueRelativeError, Vector3D.distance(refP, resP) / refP.getNorm());
            final Vector3D refPD = new Vector3D(refCartesian[0].getPartialDerivative(1), refCartesian[1].getPartialDerivative(1), refCartesian[2].getPartialDerivative(1));
            final Vector3D resPD = new Vector3D(pv.getPosition().getX().getAllDerivatives()[k + 1], pv.getPosition().getY().getAllDerivatives()[k + 1], pv.getPosition().getZ().getAllDerivatives()[k + 1]);
            maxPositionDerivativeRelativeError = FastMath.max(maxPositionDerivativeRelativeError, Vector3D.distance(refPD, resPD) / refPD.getNorm());
            // velocity
            final Vector3D refV = new Vector3D(refCartesian[3].getValue(), refCartesian[4].getValue(), refCartesian[5].getValue());
            final Vector3D resV = new Vector3D(pv.getVelocity().getX().getValue(), pv.getVelocity().getY().getValue(), pv.getVelocity().getZ().getValue());
            maxVelocityValueRelativeError = FastMath.max(maxVelocityValueRelativeError, Vector3D.distance(refV, resV) / refV.getNorm());
            final Vector3D refVD = new Vector3D(refCartesian[3].getPartialDerivative(1), refCartesian[4].getPartialDerivative(1), refCartesian[5].getPartialDerivative(1));
            final Vector3D resVD = new Vector3D(pv.getVelocity().getX().getAllDerivatives()[k + 1], pv.getVelocity().getY().getAllDerivatives()[k + 1], pv.getVelocity().getZ().getAllDerivatives()[k + 1]);
            maxVelocityDerivativeRelativeError = FastMath.max(maxVelocityDerivativeRelativeError, Vector3D.distance(refVD, resVD) / refVD.getNorm());
        }
    }
    Assert.assertEquals(0.0, maxPositionValueRelativeError, relativeTolerancePositionValue);
    Assert.assertEquals(0.0, maxPositionDerivativeRelativeError, relativeTolerancePositionDerivative);
    Assert.assertEquals(0.0, maxVelocityValueRelativeError, relativeToleranceVelocityValue);
    Assert.assertEquals(0.0, maxVelocityDerivativeRelativeError, relativeToleranceVelocityDerivative);
}
Also used : Frame(org.orekit.frames.Frame) TopocentricFrame(org.orekit.frames.TopocentricFrame) OneAxisEllipsoid(org.orekit.bodies.OneAxisEllipsoid) HashMap(java.util.HashMap) TopocentricFrame(org.orekit.frames.TopocentricFrame) Well19937a(org.hipparchus.random.Well19937a) FieldAbsoluteDate(org.orekit.time.FieldAbsoluteDate) AbsoluteDate(org.orekit.time.AbsoluteDate) RandomGenerator(org.hipparchus.random.RandomGenerator) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) GeodeticPoint(org.orekit.bodies.GeodeticPoint) DerivativeStructure(org.hipparchus.analysis.differentiation.DerivativeStructure) DSFactory(org.hipparchus.analysis.differentiation.DSFactory) ParameterDriver(org.orekit.utils.ParameterDriver) GeodeticPoint(org.orekit.bodies.GeodeticPoint) UnivariateDifferentiableVectorFunction(org.hipparchus.analysis.differentiation.UnivariateDifferentiableVectorFunction) FieldAbsoluteDate(org.orekit.time.FieldAbsoluteDate)

Example 73 with FieldAbsoluteDate

use of org.orekit.time.FieldAbsoluteDate in project Orekit by CS-SI.

the class GroundStationTest method testNoReferenceDate.

@Test
public void testNoReferenceDate() throws OrekitException {
    Utils.setDataRoot("regular-data");
    final Frame eme2000 = FramesFactory.getEME2000();
    final AbsoluteDate date = AbsoluteDate.J2000_EPOCH;
    final OneAxisEllipsoid earth = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS, Constants.WGS84_EARTH_FLATTENING, FramesFactory.getITRF(IERSConventions.IERS_2010, true));
    final GroundStation station = new GroundStation(new TopocentricFrame(earth, new GeodeticPoint(0.1, 0.2, 100), "dummy"));
    try {
        station.getOffsetToInertial(eme2000, date);
        Assert.fail("an exception should have been thrown");
    } catch (OrekitException oe) {
        Assert.assertEquals(OrekitMessages.NO_REFERENCE_DATE_FOR_PARAMETER, oe.getSpecifier());
        Assert.assertEquals("prime-meridian-offset", (String) oe.getParts()[0]);
    }
    try {
        DSFactory factory = new DSFactory(9, 1);
        Map<String, Integer> indices = new HashMap<>();
        for (final ParameterDriver driver : Arrays.asList(station.getPrimeMeridianOffsetDriver(), station.getPrimeMeridianDriftDriver(), station.getPolarOffsetXDriver(), station.getPolarDriftXDriver(), station.getPolarOffsetYDriver(), station.getPolarDriftYDriver(), station.getEastOffsetDriver(), station.getNorthOffsetDriver(), station.getZenithOffsetDriver())) {
            indices.put(driver.getName(), indices.size());
        }
        station.getOffsetToInertial(eme2000, new FieldAbsoluteDate<>(factory.getDerivativeField(), date), factory, indices);
        Assert.fail("an exception should have been thrown");
    } catch (OrekitException oe) {
        Assert.assertEquals(OrekitMessages.NO_REFERENCE_DATE_FOR_PARAMETER, oe.getSpecifier());
        Assert.assertEquals("prime-meridian-offset", (String) oe.getParts()[0]);
    }
}
Also used : Frame(org.orekit.frames.Frame) TopocentricFrame(org.orekit.frames.TopocentricFrame) OneAxisEllipsoid(org.orekit.bodies.OneAxisEllipsoid) HashMap(java.util.HashMap) TopocentricFrame(org.orekit.frames.TopocentricFrame) DSFactory(org.hipparchus.analysis.differentiation.DSFactory) ParameterDriver(org.orekit.utils.ParameterDriver) FieldAbsoluteDate(org.orekit.time.FieldAbsoluteDate) AbsoluteDate(org.orekit.time.AbsoluteDate) OrekitException(org.orekit.errors.OrekitException) GeodeticPoint(org.orekit.bodies.GeodeticPoint) Test(org.junit.Test)

Example 74 with FieldAbsoluteDate

use of org.orekit.time.FieldAbsoluteDate in project Orekit by CS-SI.

the class GroundStationTest method doTestAngularDerivatives.

private void doTestAngularDerivatives(double latitude, double longitude, double altitude, double stepFactor, double toleranceRotationValue, double toleranceRotationDerivative, double toleranceRotationRateValue, double toleranceRotationRateDerivative, String... parameterPattern) throws OrekitException {
    Utils.setDataRoot("regular-data");
    final Frame eme2000 = FramesFactory.getEME2000();
    final AbsoluteDate date = AbsoluteDate.J2000_EPOCH;
    final AbsoluteDate date0 = date.shiftedBy(50000);
    final OneAxisEllipsoid earth = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS, Constants.WGS84_EARTH_FLATTENING, FramesFactory.getITRF(IERSConventions.IERS_2010, true));
    final GroundStation station = new GroundStation(new TopocentricFrame(earth, new GeodeticPoint(latitude, longitude, altitude), "dummy"));
    final DSFactory factory = new DSFactory(parameterPattern.length, 1);
    final FieldAbsoluteDate<DerivativeStructure> dateDS = new FieldAbsoluteDate<>(factory.getDerivativeField(), date);
    ParameterDriver[] selectedDrivers = new ParameterDriver[parameterPattern.length];
    UnivariateDifferentiableVectorFunction[] dFAngular = new UnivariateDifferentiableVectorFunction[parameterPattern.length];
    final ParameterDriver[] allDrivers = selectAllDrivers(station);
    for (ParameterDriver driver : allDrivers) {
        driver.setReferenceDate(date0);
    }
    Map<String, Integer> indices = new HashMap<>();
    for (int k = 0; k < dFAngular.length; ++k) {
        for (int i = 0; i < allDrivers.length; ++i) {
            if (allDrivers[i].getName().matches(parameterPattern[k])) {
                selectedDrivers[k] = allDrivers[i];
                dFAngular[k] = differentiatedTransformAngular(station, eme2000, date, selectedDrivers[k], stepFactor);
                indices.put(selectedDrivers[k].getName(), k);
            }
        }
    }
    ;
    DSFactory factory11 = new DSFactory(1, 1);
    RandomGenerator generator = new Well19937a(0xa01a1d8fe5d80af7l);
    double maxRotationValueError = 0;
    double maxRotationDerivativeError = 0;
    double maxRotationRateValueError = 0;
    double maxRotationRateDerivativeError = 0;
    for (int i = 0; i < 1000; ++i) {
        // randomly change one parameter
        ParameterDriver changed = allDrivers[generator.nextInt(allDrivers.length)];
        changed.setNormalizedValue(2 * generator.nextDouble() - 1);
        // transform to check
        FieldTransform<DerivativeStructure> t = station.getOffsetToInertial(eme2000, dateDS, factory, indices);
        for (int k = 0; k < dFAngular.length; ++k) {
            // reference values and derivatives computed using finite differences
            DerivativeStructure[] refAngular = dFAngular[k].value(factory11.variable(0, selectedDrivers[k].getValue()));
            // rotation
            final Rotation refQ = new Rotation(refAngular[0].getValue(), refAngular[1].getValue(), refAngular[2].getValue(), refAngular[3].getValue(), true);
            final Rotation resQ = t.getRotation().toRotation();
            maxRotationValueError = FastMath.max(maxRotationValueError, Rotation.distance(refQ, resQ));
            double sign = FastMath.copySign(1.0, refAngular[0].getValue() * t.getRotation().getQ0().getValue() + refAngular[1].getValue() * t.getRotation().getQ1().getValue() + refAngular[2].getValue() * t.getRotation().getQ2().getValue() + refAngular[3].getValue() * t.getRotation().getQ3().getValue());
            maxRotationDerivativeError = FastMath.max(maxRotationDerivativeError, FastMath.abs(sign * refAngular[0].getPartialDerivative(1) - t.getRotation().getQ0().getAllDerivatives()[k + 1]));
            maxRotationDerivativeError = FastMath.max(maxRotationDerivativeError, FastMath.abs(sign * refAngular[1].getPartialDerivative(1) - t.getRotation().getQ1().getAllDerivatives()[k + 1]));
            maxRotationDerivativeError = FastMath.max(maxRotationDerivativeError, FastMath.abs(sign * refAngular[2].getPartialDerivative(1) - t.getRotation().getQ2().getAllDerivatives()[k + 1]));
            maxRotationDerivativeError = FastMath.max(maxRotationDerivativeError, FastMath.abs(sign * refAngular[3].getPartialDerivative(1) - t.getRotation().getQ3().getAllDerivatives()[k + 1]));
            // rotation rate
            final Vector3D refRate = new Vector3D(refAngular[4].getValue(), refAngular[5].getValue(), refAngular[6].getValue());
            final Vector3D resRate = t.getRotationRate().toVector3D();
            final Vector3D refRateD = new Vector3D(refAngular[4].getPartialDerivative(1), refAngular[5].getPartialDerivative(1), refAngular[6].getPartialDerivative(1));
            final Vector3D resRateD = new Vector3D(t.getRotationRate().getX().getAllDerivatives()[k + 1], t.getRotationRate().getY().getAllDerivatives()[k + 1], t.getRotationRate().getZ().getAllDerivatives()[k + 1]);
            maxRotationRateValueError = FastMath.max(maxRotationRateValueError, Vector3D.distance(refRate, resRate));
            maxRotationRateDerivativeError = FastMath.max(maxRotationRateDerivativeError, Vector3D.distance(refRateD, resRateD));
        }
    }
    Assert.assertEquals(0.0, maxRotationValueError, toleranceRotationValue);
    Assert.assertEquals(0.0, maxRotationDerivativeError, toleranceRotationDerivative);
    Assert.assertEquals(0.0, maxRotationRateValueError, toleranceRotationRateValue);
    Assert.assertEquals(0.0, maxRotationRateDerivativeError, toleranceRotationRateDerivative);
}
Also used : Frame(org.orekit.frames.Frame) TopocentricFrame(org.orekit.frames.TopocentricFrame) OneAxisEllipsoid(org.orekit.bodies.OneAxisEllipsoid) HashMap(java.util.HashMap) TopocentricFrame(org.orekit.frames.TopocentricFrame) Well19937a(org.hipparchus.random.Well19937a) FieldAbsoluteDate(org.orekit.time.FieldAbsoluteDate) AbsoluteDate(org.orekit.time.AbsoluteDate) RandomGenerator(org.hipparchus.random.RandomGenerator) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) GeodeticPoint(org.orekit.bodies.GeodeticPoint) DerivativeStructure(org.hipparchus.analysis.differentiation.DerivativeStructure) DSFactory(org.hipparchus.analysis.differentiation.DSFactory) ParameterDriver(org.orekit.utils.ParameterDriver) Rotation(org.hipparchus.geometry.euclidean.threed.Rotation) GeodeticPoint(org.orekit.bodies.GeodeticPoint) UnivariateDifferentiableVectorFunction(org.hipparchus.analysis.differentiation.UnivariateDifferentiableVectorFunction) FieldAbsoluteDate(org.orekit.time.FieldAbsoluteDate)

Example 75 with FieldAbsoluteDate

use of org.orekit.time.FieldAbsoluteDate in project Orekit by CS-SI.

the class SolarRadiationPressureTest method testLightingInterplanetary.

@Test
public void testLightingInterplanetary() throws OrekitException, ParseException {
    // Initialization
    AbsoluteDate date = new AbsoluteDate(new DateComponents(1970, 3, 21), new TimeComponents(13, 59, 27.816), TimeScalesFactory.getUTC());
    Orbit orbit = new KeplerianOrbit(1.0e11, 0.1, 0.2, 0.3, 0.4, 0.5, PositionAngle.TRUE, CelestialBodyFactory.getSolarSystemBarycenter().getInertiallyOrientedFrame(), date, Constants.JPL_SSD_SUN_GM);
    PVCoordinatesProvider sun = CelestialBodyFactory.getSun();
    SolarRadiationPressure srp = new SolarRadiationPressure(sun, Constants.SUN_RADIUS, (RadiationSensitive) new IsotropicRadiationClassicalConvention(50.0, 0.5, 0.5));
    Assert.assertFalse(srp.dependsOnPositionOnly());
    Vector3D position = orbit.getPVCoordinates().getPosition();
    Frame frame = orbit.getFrame();
    Assert.assertEquals(1.0, srp.getLightingRatio(position, frame, date), 1.0e-15);
    Assert.assertEquals(1.0, srp.getLightingRatio(new FieldVector3D<>(Decimal64Field.getInstance(), position), frame, new FieldAbsoluteDate<>(Decimal64Field.getInstance(), date)).getReal(), 1.0e-15);
}
Also used : Frame(org.orekit.frames.Frame) EquinoctialOrbit(org.orekit.orbits.EquinoctialOrbit) CartesianOrbit(org.orekit.orbits.CartesianOrbit) FieldKeplerianOrbit(org.orekit.orbits.FieldKeplerianOrbit) KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) Orbit(org.orekit.orbits.Orbit) FieldVector3D(org.hipparchus.geometry.euclidean.threed.FieldVector3D) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) PVCoordinatesProvider(org.orekit.utils.PVCoordinatesProvider) DateComponents(org.orekit.time.DateComponents) FieldKeplerianOrbit(org.orekit.orbits.FieldKeplerianOrbit) KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) TimeComponents(org.orekit.time.TimeComponents) FieldAbsoluteDate(org.orekit.time.FieldAbsoluteDate) AbsoluteDate(org.orekit.time.AbsoluteDate) AbstractLegacyForceModelTest(org.orekit.forces.AbstractLegacyForceModelTest) Test(org.junit.Test)

Aggregations

FieldAbsoluteDate (org.orekit.time.FieldAbsoluteDate)138 Frame (org.orekit.frames.Frame)57 FieldVector3D (org.hipparchus.geometry.euclidean.threed.FieldVector3D)53 AbsoluteDate (org.orekit.time.AbsoluteDate)52 Test (org.junit.Test)51 FieldKeplerianOrbit (org.orekit.orbits.FieldKeplerianOrbit)40 DSFactory (org.hipparchus.analysis.differentiation.DSFactory)37 DerivativeStructure (org.hipparchus.analysis.differentiation.DerivativeStructure)37 FieldPVCoordinates (org.orekit.utils.FieldPVCoordinates)29 OrekitException (org.orekit.errors.OrekitException)28 SpacecraftState (org.orekit.propagation.SpacecraftState)28 Vector3D (org.hipparchus.geometry.euclidean.threed.Vector3D)27 FieldSpacecraftState (org.orekit.propagation.FieldSpacecraftState)25 TimeStampedFieldPVCoordinates (org.orekit.utils.TimeStampedFieldPVCoordinates)24 PVCoordinates (org.orekit.utils.PVCoordinates)20 Decimal64 (org.hipparchus.util.Decimal64)18 RealFieldElement (org.hipparchus.RealFieldElement)17 OrbitType (org.orekit.orbits.OrbitType)17 DateComponents (org.orekit.time.DateComponents)17 FieldNumericalPropagator (org.orekit.propagation.numerical.FieldNumericalPropagator)14