use of org.hipparchus.analysis.differentiation.UnivariateDifferentiableFunction in project Orekit by CS-SI.
the class PoissonSeriesParserTest method testDerivativesAsField.
@Test
public void testDerivativesAsField() throws OrekitException {
Utils.setDataRoot("regular-data");
String directory = "/assets/org/orekit/IERS-conventions/";
PoissonSeriesParser parser = new PoissonSeriesParser(17).withPolynomialPart('t', PolynomialParser.Unit.NO_UNITS).withFirstDelaunay(4).withFirstPlanetary(9).withSinCos(0, 2, 1.0, 3, 1.0);
PoissonSeries xSeries = parser.parse(getClass().getResourceAsStream(directory + "2010/tab5.2a.txt"), "2010/tab5.2a.txt");
PoissonSeries ySeries = parser.parse(getClass().getResourceAsStream(directory + "2010/tab5.2b.txt"), "2010/tab5.2b.txt");
PoissonSeries zSeries = parser.parse(getClass().getResourceAsStream(directory + "2010/tab5.2d.txt"), "2010/tab5.2d.txt");
TimeScale ut1 = TimeScalesFactory.getUT1(FramesFactory.getEOPHistory(IERSConventions.IERS_2010, true));
FundamentalNutationArguments arguments = IERSConventions.IERS_2010.getNutationArguments(ut1);
Coordinate xCoordinate = new Coordinate(xSeries, arguments);
Coordinate yCoordinate = new Coordinate(ySeries, arguments);
Coordinate zCoordinate = new Coordinate(zSeries, arguments);
UnivariateDifferentiableFunction dx = new FiniteDifferencesDifferentiator(4, 0.4).differentiate(xCoordinate);
UnivariateDifferentiableFunction dy = new FiniteDifferencesDifferentiator(4, 0.4).differentiate(yCoordinate);
UnivariateDifferentiableFunction dz = new FiniteDifferencesDifferentiator(4, 0.4).differentiate(zCoordinate);
DSFactory factory = new DSFactory(1, 1);
FieldAbsoluteDate<DerivativeStructure> ds2000 = FieldAbsoluteDate.getJ2000Epoch(factory.getDerivativeField());
for (double t = 0; t < Constants.JULIAN_DAY; t += 120) {
final FieldAbsoluteDate<DerivativeStructure> date = ds2000.shiftedBy(factory.variable(0, t));
// direct computation of derivatives
FieldBodiesElements<DerivativeStructure> elements = arguments.evaluateAll(date);
Assert.assertEquals(0.0, elements.getDate().durationFrom(date).getValue(), 1.0e-15);
DerivativeStructure xDirect = xSeries.value(elements);
DerivativeStructure yDirect = ySeries.value(elements);
DerivativeStructure zDirect = zSeries.value(elements);
// finite differences computation of derivatives
DerivativeStructure zero = factory.variable(0, 0.0);
xCoordinate.setDate(date.toAbsoluteDate());
DerivativeStructure xFinite = dx.value(zero);
yCoordinate.setDate(date.toAbsoluteDate());
DerivativeStructure yFinite = dy.value(zero);
zCoordinate.setDate(date.toAbsoluteDate());
DerivativeStructure zFinite = dz.value(zero);
Assert.assertEquals(xFinite.getValue(), xDirect.getValue(), FastMath.abs(7.0e-15 * xFinite.getValue()));
Assert.assertEquals(xFinite.getPartialDerivative(1), xDirect.getPartialDerivative(1), FastMath.abs(2.0e-07 * xFinite.getPartialDerivative(1)));
Assert.assertEquals(yFinite.getValue(), yDirect.getValue(), FastMath.abs(7.0e-15 * yFinite.getValue()));
Assert.assertEquals(yFinite.getPartialDerivative(1), yDirect.getPartialDerivative(1), FastMath.abs(2.0e-07 * yFinite.getPartialDerivative(1)));
Assert.assertEquals(zFinite.getValue(), zDirect.getValue(), FastMath.abs(7.0e-15 * zFinite.getValue()));
Assert.assertEquals(zFinite.getPartialDerivative(1), zDirect.getPartialDerivative(1), FastMath.abs(2.0e-07 * zFinite.getPartialDerivative(1)));
}
}
use of org.hipparchus.analysis.differentiation.UnivariateDifferentiableFunction in project Orekit by CS-SI.
the class IERSConventionsTest method checkScalarFunctionConsistency.
private void checkScalarFunctionConsistency(final TimeScalarFunction function, final AbsoluteDate date, final double span, final double sampleStep, final double h, final double valueTolerance, final double derivativeTolerance) {
UnivariateDifferentiableFunction differentiated = new FiniteDifferencesDifferentiator(4, h).differentiate(new UnivariateFunction() {
@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));
maxValueError = FastMath.max(maxValueError, FastMath.abs(yRef.getValue() - y.getValue()));
maxDerivativeError = FastMath.max(maxDerivativeError, FastMath.abs(yRef.getPartialDerivative(1) - y.getPartialDerivative(1)));
}
Assert.assertEquals(0, maxValueError, valueTolerance);
Assert.assertEquals(0, maxDerivativeError, derivativeTolerance);
}
use of org.hipparchus.analysis.differentiation.UnivariateDifferentiableFunction in project Orekit by CS-SI.
the class IERSConventionsTest method checkGMSTRate.
private void checkGMSTRate(final TimeScalarFunction gmst, final TimeScalarFunction gmstRate, final AbsoluteDate date, final double span, final double sampleStep, final double h, final double tolerance) throws OrekitException {
UnivariateDifferentiableFunction differentiated = new FiniteDifferencesDifferentiator(4, h).differentiate(new UnivariateFunction() {
@Override
public double value(final double dt) {
return gmst.value(date.shiftedBy(dt));
}
});
DSFactory factory = new DSFactory(1, 1);
double maxRateError = 0;
for (double dt = 0; dt < span; dt += sampleStep) {
double rateRef = differentiated.value(factory.variable(0, dt)).getPartialDerivative(1);
double rate = gmstRate.value(date.shiftedBy(dt));
maxRateError = FastMath.max(maxRateError, FastMath.abs(rateRef - rate));
}
Assert.assertEquals(0, maxRateError, tolerance);
}
use of org.hipparchus.analysis.differentiation.UnivariateDifferentiableFunction in project Orekit by CS-SI.
the class CartesianOrbitTest method differentiate.
private <S extends Function<CartesianOrbit, Double>> double differentiate(TimeStampedPVCoordinates pv, Frame frame, double mu, S picker) {
final DSFactory factory = new DSFactory(1, 1);
FiniteDifferencesDifferentiator differentiator = new FiniteDifferencesDifferentiator(8, 0.1);
UnivariateDifferentiableFunction diff = differentiator.differentiate(new UnivariateFunction() {
public double value(double dt) {
return picker.apply(new CartesianOrbit(pv.shiftedBy(dt), frame, mu));
}
});
return diff.value(factory.variable(0, 0.0)).getPartialDerivative(1);
}
use of org.hipparchus.analysis.differentiation.UnivariateDifferentiableFunction in project Orekit by CS-SI.
the class CircularOrbitTest method differentiate.
private <S extends Function<CircularOrbit, Double>> double differentiate(TimeStampedPVCoordinates pv, Frame frame, double mu, S picker) {
final DSFactory factory = new DSFactory(1, 1);
FiniteDifferencesDifferentiator differentiator = new FiniteDifferencesDifferentiator(8, 0.1);
UnivariateDifferentiableFunction diff = differentiator.differentiate(new UnivariateFunction() {
public double value(double dt) {
return picker.apply(new CircularOrbit(pv.shiftedBy(dt), frame, mu));
}
});
return diff.value(factory.variable(0, 0.0)).getPartialDerivative(1);
}
Aggregations