Search in sources :

Example 71 with FieldVector3D

use of org.hipparchus.geometry.euclidean.threed.FieldVector3D in project Orekit by CS-SI.

the class AbstractForceModelTest method checkStateJacobianVsFiniteDifferences.

protected void checkStateJacobianVsFiniteDifferences(final SpacecraftState state0, final ForceModel forceModel, final AttitudeProvider provider, final double dP, final double checkTolerance, final boolean print) throws OrekitException {
    double[][] finiteDifferencesJacobian = Differentiation.differentiate(state -> forceModel.acceleration(state, forceModel.getParameters()).toArray(), 3, provider, OrbitType.CARTESIAN, PositionAngle.MEAN, dP, 5).value(state0);
    DSFactory factory = new DSFactory(6, 1);
    Field<DerivativeStructure> field = factory.getDerivativeField();
    final FieldAbsoluteDate<DerivativeStructure> fDate = new FieldAbsoluteDate<>(field, state0.getDate());
    final Vector3D p = state0.getPVCoordinates().getPosition();
    final Vector3D v = state0.getPVCoordinates().getVelocity();
    final Vector3D a = state0.getPVCoordinates().getAcceleration();
    final TimeStampedFieldPVCoordinates<DerivativeStructure> fPVA = new TimeStampedFieldPVCoordinates<>(fDate, new FieldVector3D<>(factory.variable(0, p.getX()), factory.variable(1, p.getY()), factory.variable(2, p.getZ())), new FieldVector3D<>(factory.variable(3, v.getX()), factory.variable(4, v.getY()), factory.variable(5, v.getZ())), new FieldVector3D<>(factory.constant(a.getX()), factory.constant(a.getY()), factory.constant(a.getZ())));
    final TimeStampedFieldAngularCoordinates<DerivativeStructure> fAC = new TimeStampedFieldAngularCoordinates<>(fDate, new FieldRotation<>(field, state0.getAttitude().getRotation()), new FieldVector3D<>(field, state0.getAttitude().getSpin()), new FieldVector3D<>(field, state0.getAttitude().getRotationAcceleration()));
    final FieldSpacecraftState<DerivativeStructure> fState = new FieldSpacecraftState<>(new FieldCartesianOrbit<>(fPVA, state0.getFrame(), state0.getMu()), new FieldAttitude<>(state0.getFrame(), fAC), field.getZero().add(state0.getMass()));
    FieldVector3D<DerivativeStructure> dsJacobian = forceModel.acceleration(fState, forceModel.getParameters(fState.getDate().getField()));
    Vector3D dFdPXRef = new Vector3D(finiteDifferencesJacobian[0][0], finiteDifferencesJacobian[1][0], finiteDifferencesJacobian[2][0]);
    Vector3D dFdPXRes = new Vector3D(dsJacobian.getX().getPartialDerivative(1, 0, 0, 0, 0, 0), dsJacobian.getY().getPartialDerivative(1, 0, 0, 0, 0, 0), dsJacobian.getZ().getPartialDerivative(1, 0, 0, 0, 0, 0));
    Vector3D dFdPYRef = new Vector3D(finiteDifferencesJacobian[0][1], finiteDifferencesJacobian[1][1], finiteDifferencesJacobian[2][1]);
    Vector3D dFdPYRes = new Vector3D(dsJacobian.getX().getPartialDerivative(0, 1, 0, 0, 0, 0), dsJacobian.getY().getPartialDerivative(0, 1, 0, 0, 0, 0), dsJacobian.getZ().getPartialDerivative(0, 1, 0, 0, 0, 0));
    Vector3D dFdPZRef = new Vector3D(finiteDifferencesJacobian[0][2], finiteDifferencesJacobian[1][2], finiteDifferencesJacobian[2][2]);
    Vector3D dFdPZRes = new Vector3D(dsJacobian.getX().getPartialDerivative(0, 0, 1, 0, 0, 0), dsJacobian.getY().getPartialDerivative(0, 0, 1, 0, 0, 0), dsJacobian.getZ().getPartialDerivative(0, 0, 1, 0, 0, 0));
    Vector3D dFdVXRef = new Vector3D(finiteDifferencesJacobian[0][3], finiteDifferencesJacobian[1][3], finiteDifferencesJacobian[2][3]);
    Vector3D dFdVXRes = new Vector3D(dsJacobian.getX().getPartialDerivative(0, 0, 0, 1, 0, 0), dsJacobian.getY().getPartialDerivative(0, 0, 0, 1, 0, 0), dsJacobian.getZ().getPartialDerivative(0, 0, 0, 1, 0, 0));
    Vector3D dFdVYRef = new Vector3D(finiteDifferencesJacobian[0][4], finiteDifferencesJacobian[1][4], finiteDifferencesJacobian[2][4]);
    Vector3D dFdVYRes = new Vector3D(dsJacobian.getX().getPartialDerivative(0, 0, 0, 0, 1, 0), dsJacobian.getY().getPartialDerivative(0, 0, 0, 0, 1, 0), dsJacobian.getZ().getPartialDerivative(0, 0, 0, 0, 1, 0));
    Vector3D dFdVZRef = new Vector3D(finiteDifferencesJacobian[0][5], finiteDifferencesJacobian[1][5], finiteDifferencesJacobian[2][5]);
    Vector3D dFdVZRes = new Vector3D(dsJacobian.getX().getPartialDerivative(0, 0, 0, 0, 0, 1), dsJacobian.getY().getPartialDerivative(0, 0, 0, 0, 0, 1), dsJacobian.getZ().getPartialDerivative(0, 0, 0, 0, 0, 1));
    if (print) {
        System.out.println("dF/dPX ref: " + dFdPXRef.getX() + " " + dFdPXRef.getY() + " " + dFdPXRef.getZ());
        System.out.println("dF/dPX res: " + dFdPXRes.getX() + " " + dFdPXRes.getY() + " " + dFdPXRes.getZ());
        System.out.println("dF/dPY ref: " + dFdPYRef.getX() + " " + dFdPYRef.getY() + " " + dFdPYRef.getZ());
        System.out.println("dF/dPY res: " + dFdPYRes.getX() + " " + dFdPYRes.getY() + " " + dFdPYRes.getZ());
        System.out.println("dF/dPZ ref: " + dFdPZRef.getX() + " " + dFdPZRef.getY() + " " + dFdPZRef.getZ());
        System.out.println("dF/dPZ res: " + dFdPZRes.getX() + " " + dFdPZRes.getY() + " " + dFdPZRes.getZ());
        System.out.println("dF/dPX ref norm: " + dFdPXRef.getNorm() + ", abs error: " + Vector3D.distance(dFdPXRef, dFdPXRes) + ", rel error: " + (Vector3D.distance(dFdPXRef, dFdPXRes) / dFdPXRef.getNorm()));
        System.out.println("dF/dPY ref norm: " + dFdPYRef.getNorm() + ", abs error: " + Vector3D.distance(dFdPYRef, dFdPYRes) + ", rel error: " + (Vector3D.distance(dFdPYRef, dFdPYRes) / dFdPYRef.getNorm()));
        System.out.println("dF/dPZ ref norm: " + dFdPZRef.getNorm() + ", abs error: " + Vector3D.distance(dFdPZRef, dFdPZRes) + ", rel error: " + (Vector3D.distance(dFdPZRef, dFdPZRes) / dFdPZRef.getNorm()));
        System.out.println("dF/dVX ref norm: " + dFdVXRef.getNorm() + ", abs error: " + Vector3D.distance(dFdVXRef, dFdVXRes) + ", rel error: " + (Vector3D.distance(dFdVXRef, dFdVXRes) / dFdVXRef.getNorm()));
        System.out.println("dF/dVY ref norm: " + dFdVYRef.getNorm() + ", abs error: " + Vector3D.distance(dFdVYRef, dFdVYRes) + ", rel error: " + (Vector3D.distance(dFdVYRef, dFdVYRes) / dFdVYRef.getNorm()));
        System.out.println("dF/dVZ ref norm: " + dFdVZRef.getNorm() + ", abs error: " + Vector3D.distance(dFdVZRef, dFdVZRes) + ", rel error: " + (Vector3D.distance(dFdVZRef, dFdVZRes) / dFdVZRef.getNorm()));
    }
    checkdFdP(dFdPXRef, dFdPXRes, checkTolerance);
    checkdFdP(dFdPYRef, dFdPYRes, checkTolerance);
    checkdFdP(dFdPZRef, dFdPZRes, checkTolerance);
    checkdFdP(dFdVXRef, dFdVXRes, checkTolerance);
    checkdFdP(dFdVYRef, dFdVYRes, checkTolerance);
    checkdFdP(dFdVZRef, dFdVZRes, checkTolerance);
}
Also used : ParameterDriver(org.orekit.utils.ParameterDriver) OrekitStepHandler(org.orekit.propagation.sampling.OrekitStepHandler) FieldRotation(org.hipparchus.geometry.euclidean.threed.FieldRotation) Differentiation(org.orekit.utils.Differentiation) FieldAttitude(org.orekit.attitudes.FieldAttitude) AttitudeProvider(org.orekit.attitudes.AttitudeProvider) FieldSpacecraftState(org.orekit.propagation.FieldSpacecraftState) DSFactory(org.hipparchus.analysis.differentiation.DSFactory) Precision(org.hipparchus.util.Precision) FieldAbsoluteDate(org.orekit.time.FieldAbsoluteDate) SpacecraftState(org.orekit.propagation.SpacecraftState) OrbitType(org.orekit.orbits.OrbitType) DerivativeStructure(org.hipparchus.analysis.differentiation.DerivativeStructure) PositionAngle(org.orekit.orbits.PositionAngle) FieldVector3D(org.hipparchus.geometry.euclidean.threed.FieldVector3D) OrekitStepInterpolator(org.orekit.propagation.sampling.OrekitStepInterpolator) JacobiansMapper(org.orekit.propagation.numerical.JacobiansMapper) TimeStampedFieldAngularCoordinates(org.orekit.utils.TimeStampedFieldAngularCoordinates) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) PartialDerivativesEquations(org.orekit.propagation.numerical.PartialDerivativesEquations) FieldCartesianOrbit(org.orekit.orbits.FieldCartesianOrbit) Field(org.hipparchus.Field) OrekitException(org.orekit.errors.OrekitException) TimeStampedFieldPVCoordinates(org.orekit.utils.TimeStampedFieldPVCoordinates) NumericalPropagator(org.orekit.propagation.numerical.NumericalPropagator) Assert(org.junit.Assert) AbsoluteDate(org.orekit.time.AbsoluteDate) FieldSpacecraftState(org.orekit.propagation.FieldSpacecraftState) DerivativeStructure(org.hipparchus.analysis.differentiation.DerivativeStructure) DSFactory(org.hipparchus.analysis.differentiation.DSFactory) TimeStampedFieldAngularCoordinates(org.orekit.utils.TimeStampedFieldAngularCoordinates) FieldVector3D(org.hipparchus.geometry.euclidean.threed.FieldVector3D) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) FieldAbsoluteDate(org.orekit.time.FieldAbsoluteDate) TimeStampedFieldPVCoordinates(org.orekit.utils.TimeStampedFieldPVCoordinates)

Example 72 with FieldVector3D

use of org.hipparchus.geometry.euclidean.threed.FieldVector3D in project Orekit by CS-SI.

the class BoxAndSolarArraySpacecraftTest method testNullIllumination.

@Test
public void testNullIllumination() throws OrekitException {
    SpacecraftState state = propagator.getInitialState();
    CelestialBody sun = CelestialBodyFactory.getSun();
    BoxAndSolarArraySpacecraft s = new BoxAndSolarArraySpacecraft(0, 0, 0, sun, 20.0, Vector3D.PLUS_J, 0.0, 1.0, 0.0);
    FieldVector3D<DerivativeStructure> a = s.radiationPressureAcceleration(state.getDate(), state.getFrame(), state.getPVCoordinates().getPosition(), state.getAttitude().getRotation(), state.getMass(), new Vector3D(Precision.SAFE_MIN / 2, Vector3D.PLUS_I), getRadiationParameters(s), RadiationSensitive.ABSORPTION_COEFFICIENT);
    Assert.assertEquals(0.0, a.getNorm().getReal(), Double.MIN_VALUE);
}
Also used : SpacecraftState(org.orekit.propagation.SpacecraftState) FieldVector3D(org.hipparchus.geometry.euclidean.threed.FieldVector3D) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) CelestialBody(org.orekit.bodies.CelestialBody) DerivativeStructure(org.hipparchus.analysis.differentiation.DerivativeStructure) Test(org.junit.Test)

Example 73 with FieldVector3D

use of org.hipparchus.geometry.euclidean.threed.FieldVector3D in project Orekit by CS-SI.

the class NRLMSISE00Test method testDensityGradient.

@Test
public void testDensityGradient() throws OrekitException {
    // Build the input params provider
    final InputParams ip = new InputParams();
    // Get Sun
    final PVCoordinatesProvider sun = CelestialBodyFactory.getSun();
    // Get Earth body shape
    final Frame itrf = FramesFactory.getITRF(IERSConventions.IERS_2010, true);
    final OneAxisEllipsoid earth = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS, Constants.WGS84_EARTH_FLATTENING, itrf);
    // Build the model
    final NRLMSISE00 atm = new NRLMSISE00(ip, sun, earth);
    // Build the date
    final AbsoluteDate date = new AbsoluteDate(new DateComponents(2003, 172), new TimeComponents(29000.), TimeScalesFactory.getUT1(IERSConventions.IERS_2010, true));
    // Build the position
    final double alt = 400.;
    final double lat = 60.;
    final double lon = -70.;
    final GeodeticPoint point = new GeodeticPoint(FastMath.toRadians(lat), FastMath.toRadians(lon), alt * 1000.);
    final Vector3D pos = earth.transform(point);
    // Run
    DerivativeStructure zero = new DSFactory(1, 1).variable(0, 0.0);
    FiniteDifferencesDifferentiator differentiator = new FiniteDifferencesDifferentiator(5, 10.0);
    DerivativeStructure rhoX = differentiator.differentiate((double x) -> {
        try {
            return atm.getDensity(date, new Vector3D(1, pos, x, Vector3D.PLUS_I), itrf);
        } catch (OrekitException oe) {
            return Double.NaN;
        }
    }).value(zero);
    DerivativeStructure rhoY = differentiator.differentiate((double y) -> {
        try {
            return atm.getDensity(date, new Vector3D(1, pos, y, Vector3D.PLUS_J), itrf);
        } catch (OrekitException oe) {
            return Double.NaN;
        }
    }).value(zero);
    DerivativeStructure rhoZ = differentiator.differentiate((double z) -> {
        try {
            return atm.getDensity(date, new Vector3D(1, pos, z, Vector3D.PLUS_K), itrf);
        } catch (OrekitException oe) {
            return Double.NaN;
        }
    }).value(zero);
    DSFactory factory3 = new DSFactory(3, 1);
    Field<DerivativeStructure> field = factory3.getDerivativeField();
    final DerivativeStructure rhoDS = atm.getDensity(new FieldAbsoluteDate<>(field, date), new FieldVector3D<>(factory3.variable(0, pos.getX()), factory3.variable(1, pos.getY()), factory3.variable(2, pos.getZ())), itrf);
    Assert.assertEquals(rhoX.getValue(), rhoDS.getReal(), rhoX.getValue() * 2.0e-13);
    Assert.assertEquals(rhoY.getValue(), rhoDS.getReal(), rhoY.getValue() * 2.0e-13);
    Assert.assertEquals(rhoZ.getValue(), rhoDS.getReal(), rhoZ.getValue() * 2.0e-13);
    Assert.assertEquals(rhoX.getPartialDerivative(1), rhoDS.getPartialDerivative(1, 0, 0), FastMath.abs(2.0e-10 * rhoX.getPartialDerivative(1)));
    Assert.assertEquals(rhoY.getPartialDerivative(1), rhoDS.getPartialDerivative(0, 1, 0), FastMath.abs(2.0e-10 * rhoY.getPartialDerivative(1)));
    Assert.assertEquals(rhoZ.getPartialDerivative(1), rhoDS.getPartialDerivative(0, 0, 1), FastMath.abs(2.0e-10 * rhoY.getPartialDerivative(1)));
}
Also used : Frame(org.orekit.frames.Frame) OneAxisEllipsoid(org.orekit.bodies.OneAxisEllipsoid) DerivativeStructure(org.hipparchus.analysis.differentiation.DerivativeStructure) DSFactory(org.hipparchus.analysis.differentiation.DSFactory) DateComponents(org.orekit.time.DateComponents) TimeComponents(org.orekit.time.TimeComponents) FieldAbsoluteDate(org.orekit.time.FieldAbsoluteDate) AbsoluteDate(org.orekit.time.AbsoluteDate) FieldVector3D(org.hipparchus.geometry.euclidean.threed.FieldVector3D) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) PVCoordinatesProvider(org.orekit.utils.PVCoordinatesProvider) OrekitException(org.orekit.errors.OrekitException) GeodeticPoint(org.orekit.bodies.GeodeticPoint) FiniteDifferencesDifferentiator(org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator) Test(org.junit.Test)

Example 74 with FieldVector3D

use of org.hipparchus.geometry.euclidean.threed.FieldVector3D in project Orekit by CS-SI.

the class NRLMSISE00Test method testDensityField.

@Test
public void testDensityField() throws OrekitException {
    // Build the input params provider
    final InputParams ip = new InputParams();
    // Get Sun
    final PVCoordinatesProvider sun = CelestialBodyFactory.getSun();
    // Get Earth body shape
    final Frame itrf = FramesFactory.getITRF(IERSConventions.IERS_2010, true);
    final OneAxisEllipsoid earth = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS, Constants.WGS84_EARTH_FLATTENING, itrf);
    // Build the model
    final NRLMSISE00 atm = new NRLMSISE00(ip, sun, earth);
    // Build the date
    final AbsoluteDate date = new AbsoluteDate(new DateComponents(2003, 172), new TimeComponents(29000.), TimeScalesFactory.getUT1(IERSConventions.IERS_2010, true));
    // Build the position
    final double alt = 400.;
    final double lat = 60.;
    final double lon = -70.;
    final GeodeticPoint point = new GeodeticPoint(FastMath.toRadians(lat), FastMath.toRadians(lon), alt * 1000.);
    final Vector3D pos = earth.transform(point);
    Field<Decimal64> field = Decimal64Field.getInstance();
    // Run
    final double rho = atm.getDensity(date, pos, itrf);
    final Decimal64 rho64 = atm.getDensity(new FieldAbsoluteDate<>(field, date), new FieldVector3D<>(field.getOne(), pos), itrf);
    Assert.assertEquals(rho, rho64.getReal(), rho * 2.0e-13);
}
Also used : Frame(org.orekit.frames.Frame) OneAxisEllipsoid(org.orekit.bodies.OneAxisEllipsoid) Decimal64(org.hipparchus.util.Decimal64) DateComponents(org.orekit.time.DateComponents) TimeComponents(org.orekit.time.TimeComponents) FieldAbsoluteDate(org.orekit.time.FieldAbsoluteDate) AbsoluteDate(org.orekit.time.AbsoluteDate) FieldVector3D(org.hipparchus.geometry.euclidean.threed.FieldVector3D) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) PVCoordinatesProvider(org.orekit.utils.PVCoordinatesProvider) GeodeticPoint(org.orekit.bodies.GeodeticPoint) Test(org.junit.Test)

Example 75 with FieldVector3D

use of org.hipparchus.geometry.euclidean.threed.FieldVector3D in project Orekit by CS-SI.

the class HolmesFeatherstoneAttractionModelTest method accelerationDerivatives.

@Override
protected FieldVector3D<DerivativeStructure> accelerationDerivatives(final ForceModel forceModel, final AbsoluteDate date, final Frame frame, final FieldVector3D<DerivativeStructure> position, final FieldVector3D<DerivativeStructure> velocity, final FieldRotation<DerivativeStructure> rotation, final DerivativeStructure mass) throws OrekitException {
    try {
        java.lang.reflect.Field bodyFrameField = HolmesFeatherstoneAttractionModel.class.getDeclaredField("bodyFrame");
        bodyFrameField.setAccessible(true);
        Frame bodyFrame = (Frame) bodyFrameField.get(forceModel);
        // get the position in body frame
        final Transform fromBodyFrame = bodyFrame.getTransformTo(frame, date);
        final Transform toBodyFrame = fromBodyFrame.getInverse();
        final Vector3D positionBody = toBodyFrame.transformPosition(position.toVector3D());
        // compute gradient and Hessian
        final GradientHessian gh = gradientHessian((HolmesFeatherstoneAttractionModel) forceModel, date, positionBody);
        // gradient of the non-central part of the gravity field
        final double[] gInertial = fromBodyFrame.transformVector(new Vector3D(gh.getGradient())).toArray();
        // Hessian of the non-central part of the gravity field
        final RealMatrix hBody = new Array2DRowRealMatrix(gh.getHessian(), false);
        final RealMatrix rot = new Array2DRowRealMatrix(toBodyFrame.getRotation().getMatrix());
        final RealMatrix hInertial = rot.transpose().multiply(hBody).multiply(rot);
        // distribute all partial derivatives in a compact acceleration vector
        final double[] derivatives = new double[1 + mass.getFreeParameters()];
        final DerivativeStructure[] accDer = new DerivativeStructure[3];
        for (int i = 0; i < 3; ++i) {
            // first element is value of acceleration (i.e. gradient of field)
            derivatives[0] = gInertial[i];
            // next three elements are one row of the Jacobian of acceleration (i.e. Hessian of field)
            derivatives[1] = hInertial.getEntry(i, 0);
            derivatives[2] = hInertial.getEntry(i, 1);
            derivatives[3] = hInertial.getEntry(i, 2);
            // next elements (three or four depending on mass being used or not) are left as 0
            accDer[i] = mass.getFactory().build(derivatives);
        }
        return new FieldVector3D<>(accDer);
    } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
        return null;
    }
}
Also used : Frame(org.orekit.frames.Frame) DerivativeStructure(org.hipparchus.analysis.differentiation.DerivativeStructure) FieldVector3D(org.hipparchus.geometry.euclidean.threed.FieldVector3D) RealMatrix(org.hipparchus.linear.RealMatrix) Array2DRowRealMatrix(org.hipparchus.linear.Array2DRowRealMatrix) Array2DRowRealMatrix(org.hipparchus.linear.Array2DRowRealMatrix) FieldVector3D(org.hipparchus.geometry.euclidean.threed.FieldVector3D) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) Transform(org.orekit.frames.Transform)

Aggregations

FieldVector3D (org.hipparchus.geometry.euclidean.threed.FieldVector3D)124 Vector3D (org.hipparchus.geometry.euclidean.threed.Vector3D)53 FieldAbsoluteDate (org.orekit.time.FieldAbsoluteDate)49 DerivativeStructure (org.hipparchus.analysis.differentiation.DerivativeStructure)38 Test (org.junit.Test)38 Frame (org.orekit.frames.Frame)36 TimeStampedFieldPVCoordinates (org.orekit.utils.TimeStampedFieldPVCoordinates)31 OrekitException (org.orekit.errors.OrekitException)23 DSFactory (org.hipparchus.analysis.differentiation.DSFactory)20 FieldPVCoordinates (org.orekit.utils.FieldPVCoordinates)20 Decimal64 (org.hipparchus.util.Decimal64)18 FieldEquinoctialOrbit (org.orekit.orbits.FieldEquinoctialOrbit)15 OrbitType (org.orekit.orbits.OrbitType)15 AbsoluteDate (org.orekit.time.AbsoluteDate)15 DormandPrince853FieldIntegrator (org.hipparchus.ode.nonstiff.DormandPrince853FieldIntegrator)14 Transform (org.orekit.frames.Transform)14 FieldDerivativeStructure (org.hipparchus.analysis.differentiation.FieldDerivativeStructure)12 FieldEcksteinHechlerPropagator (org.orekit.propagation.analytical.FieldEcksteinHechlerPropagator)10 TimeStampedPVCoordinates (org.orekit.utils.TimeStampedPVCoordinates)9 ArrayList (java.util.ArrayList)8