use of org.hipparchus.analysis.differentiation.DSFactory in project Orekit by CS-SI.
the class FundamentalNutationArgumentsTest method testDotField.
@Test
public void testDotField() throws OrekitException {
final IERSConventions conventions = IERSConventions.IERS_2010;
final TimeScale ut1 = TimeScalesFactory.getUT1(conventions, false);
final FundamentalNutationArguments fna = conventions.getNutationArguments(ut1);
final FieldAbsoluteDate<Decimal64> t0 = new FieldAbsoluteDate<>(Decimal64Field.getInstance(), 2002, 4, 7, 12, 34, 22.5, TimeScalesFactory.getUTC());
final UnivariateDifferentiableFunction gamma = differentiate(fna, t0, b -> b.getGamma());
final UnivariateDifferentiableFunction l = differentiate(fna, t0, b -> b.getL());
final UnivariateDifferentiableFunction lPrime = differentiate(fna, t0, b -> b.getLPrime());
final UnivariateDifferentiableFunction f = differentiate(fna, t0, b -> b.getF());
final UnivariateDifferentiableFunction d = differentiate(fna, t0, b -> b.getD());
final UnivariateDifferentiableFunction lMe = differentiate(fna, t0, b -> b.getLMe());
final UnivariateDifferentiableFunction lVe = differentiate(fna, t0, b -> b.getLVe());
final UnivariateDifferentiableFunction lE = differentiate(fna, t0, b -> b.getLE());
final UnivariateDifferentiableFunction lMa = differentiate(fna, t0, b -> b.getLMa());
final UnivariateDifferentiableFunction lJu = differentiate(fna, t0, b -> b.getLJu());
final UnivariateDifferentiableFunction lSa = differentiate(fna, t0, b -> b.getLSa());
final UnivariateDifferentiableFunction lUr = differentiate(fna, t0, b -> b.getLUr());
final UnivariateDifferentiableFunction lNe = differentiate(fna, t0, b -> b.getLNe());
final UnivariateDifferentiableFunction pa = differentiate(fna, t0, b -> b.getPa());
final DSFactory factory = new DSFactory(1, 1);
double maxErrorGamma = 0;
double maxErrorL = 0;
double maxErrorLPrime = 0;
double maxErrorF = 0;
double maxErrorD = 0;
double maxErrorLMe = 0;
double maxErrorLVe = 0;
double maxErrorLE = 0;
double maxErrorLMa = 0;
double maxErrorLJu = 0;
double maxErrorLSa = 0;
double maxErrorLUr = 0;
double maxErrorLNe = 0;
double maxErrorPa = 0;
for (double dt = 0; dt < Constants.JULIAN_DAY; dt += 60.0) {
FieldBodiesElements<Decimal64> be = fna.evaluateAll(t0.shiftedBy(dt));
DerivativeStructure dtDS = factory.variable(0, dt);
maxErrorGamma = FastMath.max(maxErrorGamma, FastMath.abs(gamma.value(dtDS).getPartialDerivative(1) - be.getGammaDot().getReal()));
maxErrorL = FastMath.max(maxErrorL, FastMath.abs(l.value(dtDS).getPartialDerivative(1) - be.getLDot().getReal()));
maxErrorLPrime = FastMath.max(maxErrorLPrime, FastMath.abs(lPrime.value(dtDS).getPartialDerivative(1) - be.getLPrimeDot().getReal()));
maxErrorF = FastMath.max(maxErrorF, FastMath.abs(f.value(dtDS).getPartialDerivative(1) - be.getFDot().getReal()));
maxErrorD = FastMath.max(maxErrorD, FastMath.abs(d.value(dtDS).getPartialDerivative(1) - be.getDDot().getReal()));
maxErrorLMe = FastMath.max(maxErrorLMe, FastMath.abs(lMe.value(dtDS).getPartialDerivative(1) - be.getLMeDot().getReal()));
maxErrorLVe = FastMath.max(maxErrorLVe, FastMath.abs(lVe.value(dtDS).getPartialDerivative(1) - be.getLVeDot().getReal()));
maxErrorLE = FastMath.max(maxErrorLE, FastMath.abs(lE.value(dtDS).getPartialDerivative(1) - be.getLEDot().getReal()));
maxErrorLMa = FastMath.max(maxErrorLMa, FastMath.abs(lMa.value(dtDS).getPartialDerivative(1) - be.getLMaDot().getReal()));
maxErrorLJu = FastMath.max(maxErrorLJu, FastMath.abs(lJu.value(dtDS).getPartialDerivative(1) - be.getLJuDot().getReal()));
maxErrorLSa = FastMath.max(maxErrorLSa, FastMath.abs(lSa.value(dtDS).getPartialDerivative(1) - be.getLSaDot().getReal()));
maxErrorLUr = FastMath.max(maxErrorLUr, FastMath.abs(lUr.value(dtDS).getPartialDerivative(1) - be.getLUrDot().getReal()));
maxErrorLNe = FastMath.max(maxErrorLNe, FastMath.abs(lNe.value(dtDS).getPartialDerivative(1) - be.getLNeDot().getReal()));
maxErrorPa = FastMath.max(maxErrorPa, FastMath.abs(pa.value(dtDS).getPartialDerivative(1) - be.getPaDot().getReal()));
}
Assert.assertEquals(0, maxErrorGamma, 8.0e-13);
Assert.assertEquals(0, maxErrorL, 1.0e-14);
Assert.assertEquals(0, maxErrorLPrime, 6.0e-16);
Assert.assertEquals(0, maxErrorF, 6.0e-15);
Assert.assertEquals(0, maxErrorD, 6.0e-15);
Assert.assertEquals(0, maxErrorLMe, 2.0e-15);
Assert.assertEquals(0, maxErrorLVe, 5.0e-16);
Assert.assertEquals(0, maxErrorLE, 3.0e-16);
Assert.assertEquals(0, maxErrorLMa, 4.0e-16);
Assert.assertEquals(0, maxErrorLJu, 3.0e-17);
Assert.assertEquals(0, maxErrorLSa, 4.0e-17);
Assert.assertEquals(0, maxErrorLUr, 1.0e-16);
Assert.assertEquals(0, maxErrorLNe, 8.0e-17);
Assert.assertEquals(0, maxErrorPa, 3.0e-20);
}
use of org.hipparchus.analysis.differentiation.DSFactory in project Orekit by CS-SI.
the class FundamentalNutationArgumentsTest method testDotDouble.
@Test
public void testDotDouble() throws OrekitException {
final IERSConventions conventions = IERSConventions.IERS_2010;
final TimeScale ut1 = TimeScalesFactory.getUT1(conventions, false);
final FundamentalNutationArguments fna = conventions.getNutationArguments(ut1);
final AbsoluteDate t0 = new AbsoluteDate(2002, 4, 7, 12, 34, 22.5, TimeScalesFactory.getUTC());
final UnivariateDifferentiableFunction gamma = differentiate(fna, t0, b -> b.getGamma());
final UnivariateDifferentiableFunction l = differentiate(fna, t0, b -> b.getL());
final UnivariateDifferentiableFunction lPrime = differentiate(fna, t0, b -> b.getLPrime());
final UnivariateDifferentiableFunction f = differentiate(fna, t0, b -> b.getF());
final UnivariateDifferentiableFunction d = differentiate(fna, t0, b -> b.getD());
final UnivariateDifferentiableFunction lMe = differentiate(fna, t0, b -> b.getLMe());
final UnivariateDifferentiableFunction lVe = differentiate(fna, t0, b -> b.getLVe());
final UnivariateDifferentiableFunction lE = differentiate(fna, t0, b -> b.getLE());
final UnivariateDifferentiableFunction lMa = differentiate(fna, t0, b -> b.getLMa());
final UnivariateDifferentiableFunction lJu = differentiate(fna, t0, b -> b.getLJu());
final UnivariateDifferentiableFunction lSa = differentiate(fna, t0, b -> b.getLSa());
final UnivariateDifferentiableFunction lUr = differentiate(fna, t0, b -> b.getLUr());
final UnivariateDifferentiableFunction lNe = differentiate(fna, t0, b -> b.getLNe());
final UnivariateDifferentiableFunction pa = differentiate(fna, t0, b -> b.getPa());
final DSFactory factory = new DSFactory(1, 1);
double maxErrorGamma = 0;
double maxErrorL = 0;
double maxErrorLPrime = 0;
double maxErrorF = 0;
double maxErrorD = 0;
double maxErrorLMe = 0;
double maxErrorLVe = 0;
double maxErrorLE = 0;
double maxErrorLMa = 0;
double maxErrorLJu = 0;
double maxErrorLSa = 0;
double maxErrorLUr = 0;
double maxErrorLNe = 0;
double maxErrorPa = 0;
for (double dt = 0; dt < Constants.JULIAN_DAY; dt += 60.0) {
BodiesElements be = fna.evaluateAll(t0.shiftedBy(dt));
DerivativeStructure dtDS = factory.variable(0, dt);
maxErrorGamma = FastMath.max(maxErrorGamma, FastMath.abs(gamma.value(dtDS).getPartialDerivative(1) - be.getGammaDot()));
maxErrorL = FastMath.max(maxErrorL, FastMath.abs(l.value(dtDS).getPartialDerivative(1) - be.getLDot()));
maxErrorLPrime = FastMath.max(maxErrorLPrime, FastMath.abs(lPrime.value(dtDS).getPartialDerivative(1) - be.getLPrimeDot()));
maxErrorF = FastMath.max(maxErrorF, FastMath.abs(f.value(dtDS).getPartialDerivative(1) - be.getFDot()));
maxErrorD = FastMath.max(maxErrorD, FastMath.abs(d.value(dtDS).getPartialDerivative(1) - be.getDDot()));
maxErrorLMe = FastMath.max(maxErrorLMe, FastMath.abs(lMe.value(dtDS).getPartialDerivative(1) - be.getLMeDot()));
maxErrorLVe = FastMath.max(maxErrorLVe, FastMath.abs(lVe.value(dtDS).getPartialDerivative(1) - be.getLVeDot()));
maxErrorLE = FastMath.max(maxErrorLE, FastMath.abs(lE.value(dtDS).getPartialDerivative(1) - be.getLEDot()));
maxErrorLMa = FastMath.max(maxErrorLMa, FastMath.abs(lMa.value(dtDS).getPartialDerivative(1) - be.getLMaDot()));
maxErrorLJu = FastMath.max(maxErrorLJu, FastMath.abs(lJu.value(dtDS).getPartialDerivative(1) - be.getLJuDot()));
maxErrorLSa = FastMath.max(maxErrorLSa, FastMath.abs(lSa.value(dtDS).getPartialDerivative(1) - be.getLSaDot()));
maxErrorLUr = FastMath.max(maxErrorLUr, FastMath.abs(lUr.value(dtDS).getPartialDerivative(1) - be.getLUrDot()));
maxErrorLNe = FastMath.max(maxErrorLNe, FastMath.abs(lNe.value(dtDS).getPartialDerivative(1) - be.getLNeDot()));
maxErrorPa = FastMath.max(maxErrorPa, FastMath.abs(pa.value(dtDS).getPartialDerivative(1) - be.getPaDot()));
}
Assert.assertEquals(0, maxErrorGamma, 8.0e-13);
Assert.assertEquals(0, maxErrorL, 1.0e-14);
Assert.assertEquals(0, maxErrorLPrime, 6.0e-16);
Assert.assertEquals(0, maxErrorF, 6.0e-15);
Assert.assertEquals(0, maxErrorD, 6.0e-15);
Assert.assertEquals(0, maxErrorLMe, 2.0e-15);
Assert.assertEquals(0, maxErrorLVe, 5.0e-16);
Assert.assertEquals(0, maxErrorLE, 3.0e-16);
Assert.assertEquals(0, maxErrorLMa, 4.0e-16);
Assert.assertEquals(0, maxErrorLJu, 3.0e-17);
Assert.assertEquals(0, maxErrorLSa, 4.0e-17);
Assert.assertEquals(0, maxErrorLUr, 1.0e-16);
Assert.assertEquals(0, maxErrorLNe, 8.0e-17);
Assert.assertEquals(0, maxErrorPa, 3.0e-20);
}
use of org.hipparchus.analysis.differentiation.DSFactory in project Orekit by CS-SI.
the class PVCoordinates method toDerivativeStructureVector.
/**
* Transform the instance to a {@link FieldVector3D}<{@link DerivativeStructure}>.
* <p>
* The {@link DerivativeStructure} coordinates correspond to time-derivatives up
* to the user-specified order.
* </p>
* @param order derivation order for the vector components (must be either 0, 1 or 2)
* @return vector with time-derivatives embedded within the coordinates
* @exception OrekitException if the user specified order is too large
*/
public FieldVector3D<DerivativeStructure> toDerivativeStructureVector(final int order) throws OrekitException {
final DSFactory factory;
final DerivativeStructure x;
final DerivativeStructure y;
final DerivativeStructure z;
switch(order) {
case 0:
factory = new DSFactory(1, order);
x = factory.build(position.getX());
y = factory.build(position.getY());
z = factory.build(position.getZ());
break;
case 1:
factory = new DSFactory(1, order);
x = factory.build(position.getX(), velocity.getX());
y = factory.build(position.getY(), velocity.getY());
z = factory.build(position.getZ(), velocity.getZ());
break;
case 2:
factory = new DSFactory(1, order);
x = factory.build(position.getX(), velocity.getX(), acceleration.getX());
y = factory.build(position.getY(), velocity.getY(), acceleration.getY());
z = factory.build(position.getZ(), velocity.getZ(), acceleration.getZ());
break;
default:
throw new OrekitException(OrekitMessages.OUT_OF_RANGE_DERIVATION_ORDER, order);
}
return new FieldVector3D<>(x, y, z);
}
use of org.hipparchus.analysis.differentiation.DSFactory 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);
}
use of org.hipparchus.analysis.differentiation.DSFactory 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]);
}
}
Aggregations