use of org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator in project Orekit by CS-SI.
the class HarrisPriesterTest method gradientComponent.
private double gradientComponent(final Atmosphere atm, final Vector3D position, final Vector3D direction, final double dP, final Frame frame, final ComponentGetter getter) {
FiniteDifferencesDifferentiator differentiator = new FiniteDifferencesDifferentiator(5, dP);
UnivariateFunction f = delta -> {
try {
return getter.get(atm.getVelocity(date, new Vector3D(1, position, delta, direction), frame));
} catch (OrekitException oe) {
return Double.NaN;
}
};
return differentiator.differentiate(f).value(new DSFactory(1, 1).variable(0, 0.0)).getPartialDerivative(1);
}
use of org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator in project Orekit by CS-SI.
the class PoissonSeriesParserTest method testDerivativesFromDoubleAPI.
@Test
public void testDerivativesFromDoubleAPI() 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);
InputStream xStream = getClass().getResourceAsStream(directory + "2010/tab5.2a.txt");
PoissonSeries xSeries = parser.parse(xStream, "2010/tab5.2a.txt");
InputStream yStream = getClass().getResourceAsStream(directory + "2010/tab5.2b.txt");
PoissonSeries ySeries = parser.parse(yStream, "2010/tab5.2b.txt");
InputStream zStream = getClass().getResourceAsStream(directory + "2010/tab5.2d.txt");
PoissonSeries zSeries = parser.parse(zStream, "2010/tab5.2d.txt");
final PoissonSeries.CompiledSeries compiled = PoissonSeries.compile(xSeries, ySeries, zSeries);
TimeScale ut1 = TimeScalesFactory.getUT1(FramesFactory.getEOPHistory(IERSConventions.IERS_2010, true));
final FundamentalNutationArguments arguments = IERSConventions.IERS_2010.getNutationArguments(ut1);
UnivariateDifferentiableVectorFunction finite = new FiniteDifferencesDifferentiator(4, 0.4).differentiate((double t) -> compiled.value(arguments.evaluateAll(AbsoluteDate.J2000_EPOCH.shiftedBy(t))));
DSFactory factory = new DSFactory(1, 1);
for (double t = 0; t < Constants.JULIAN_DAY; t += 120) {
// computation of derivatives from API
double[] dAPI = compiled.derivative(arguments.evaluateAll(AbsoluteDate.J2000_EPOCH.shiftedBy(t)));
// finite differences computation of derivatives
DerivativeStructure[] d = finite.value(factory.variable(0, t));
Assert.assertEquals(d.length, dAPI.length);
for (int i = 0; i < d.length; ++i) {
Assert.assertEquals(d[i].getPartialDerivative(1), dAPI[i], FastMath.abs(2.0e-7 * d[i].getPartialDerivative(1)));
}
}
}
use of org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator 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.FiniteDifferencesDifferentiator 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.FiniteDifferencesDifferentiator in project Orekit by CS-SI.
the class IERSConventionsTest method checkVectorFunctionConsistency.
private void checkVectorFunctionConsistency(final TimeVectorFunction function, final int dimension, final AbsoluteDate date, final double span, final double sampleStep, final double h, final double valueTolerance, final double derivativeTolerance) {
UnivariateDifferentiableVectorFunction differentiated = new FiniteDifferencesDifferentiator(4, h).differentiate(new UnivariateVectorFunction() {
@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));
Assert.assertEquals(dimension, yRef.length);
Assert.assertEquals(dimension, y.length);
for (int i = 0; i < dimension; ++i) {
maxValueError = FastMath.max(maxValueError, FastMath.abs(yRef[i].getValue() - y[i].getValue()));
maxDerivativeError = FastMath.max(maxDerivativeError, FastMath.abs(yRef[i].getPartialDerivative(1) - y[i].getPartialDerivative(1)));
}
}
Assert.assertEquals(0, maxValueError, valueTolerance);
Assert.assertEquals(0, maxDerivativeError, derivativeTolerance);
}
Aggregations