From d094fd0c7ffec61cada2f5acc9fef92bf577630f Mon Sep 17 00:00:00 2001 From: Luc Maisonobe <luc@orekit.org> Date: Fri, 23 Dec 2016 19:14:19 +0100 Subject: [PATCH] Use new factory for DerivativeStructure instances. --- src/main/java/org/orekit/rugged/api/Rugged.java | 7 +++++-- src/test/java/org/orekit/rugged/api/RuggedTest.java | 12 +++++++----- .../orekit/rugged/linesensor/FixedRotationTest.java | 9 ++++++--- .../rugged/linesensor/PolynomialRotationTest.java | 9 ++++++--- .../linesensor/SensorMeanPlaneCrossingTest.java | 4 ++-- .../rugged/refraction/MultiLayerModelTest.java | 4 ++-- .../orekit/rugged/utils/ExtendedEllipsoidTest.java | 2 +- .../rugged/utils/SpacecraftToObservedBodyTest.java | 2 +- 8 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/orekit/rugged/api/Rugged.java b/src/main/java/org/orekit/rugged/api/Rugged.java index 7335cf55..b4862fa4 100644 --- a/src/main/java/org/orekit/rugged/api/Rugged.java +++ b/src/main/java/org/orekit/rugged/api/Rugged.java @@ -24,6 +24,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.hipparchus.analysis.differentiation.DSFactory; import org.hipparchus.analysis.differentiation.DerivativeStructure; import org.hipparchus.geometry.euclidean.threed.FieldVector3D; import org.hipparchus.geometry.euclidean.threed.Vector3D; @@ -961,6 +962,8 @@ public class Rugged { }); } + final DSFactory factory = new DSFactory(map.size(), 1); + return new DSGenerator() { /** {@inheritDoc} */ @@ -972,7 +975,7 @@ public class Rugged { /** {@inheritDoc} */ @Override public DerivativeStructure constant(final double value) { - return new DerivativeStructure(map.size(), 1, value); + return factory.constant(value); } /** {@inheritDoc} */ @@ -982,7 +985,7 @@ public class Rugged { if (index == null) { return constant(driver.getValue()); } else { - return new DerivativeStructure(map.size(), 1, index.intValue(), driver.getValue()); + return factory.variable(index.intValue(), driver.getValue()); } } diff --git a/src/test/java/org/orekit/rugged/api/RuggedTest.java b/src/test/java/org/orekit/rugged/api/RuggedTest.java index d10e035b..c66268d2 100644 --- a/src/test/java/org/orekit/rugged/api/RuggedTest.java +++ b/src/test/java/org/orekit/rugged/api/RuggedTest.java @@ -31,6 +31,7 @@ import java.util.Collections; import java.util.List; import java.util.Locale; +import org.hipparchus.analysis.differentiation.DSFactory; import org.hipparchus.analysis.differentiation.DerivativeStructure; import org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator; import org.hipparchus.analysis.differentiation.UnivariateDifferentiableFunction; @@ -1065,7 +1066,7 @@ public class RuggedTest { public void testInverseLocationDerivativesWithAberrationOfLightCorrection() throws RuggedException, OrekitException { doTestInverseLocationDerivatives(2000, false, true, - 3.0e-10, 3.0e-10, 2.0e-12, 7.0e-8); + 4.2e-10, 3.0e-10, 3.4e-12, 7.0e-8); } @Test @@ -1167,6 +1168,7 @@ public class RuggedTest { Assert.assertEquals(1, result[0].getOrder()); // check the partial derivatives + DSFactory factory = new DSFactory(1, 1); double h = 1.0e-6; FiniteDifferencesDifferentiator differentiator = new FiniteDifferencesDifferentiator(8, h); @@ -1182,7 +1184,7 @@ public class RuggedTest { throw new RuggedExceptionWrapper(e); } }); - double dLdR = lineVSroll.value(new DerivativeStructure(1, 1, 0, 0.0)).getPartialDerivative(1); + double dLdR = lineVSroll.value(factory.variable(0, 0.0)).getPartialDerivative(1); Assert.assertEquals(dLdR, result[0].getPartialDerivative(1, 0), dLdR * lineDerivativeRelativeTolerance); UnivariateDifferentiableFunction lineVSpitch = @@ -1197,7 +1199,7 @@ public class RuggedTest { throw new RuggedExceptionWrapper(e); } }); - double dLdP = lineVSpitch.value(new DerivativeStructure(1, 1, 0, 0.0)).getPartialDerivative(1); + double dLdP = lineVSpitch.value(factory.variable(0, 0.0)).getPartialDerivative(1); Assert.assertEquals(dLdP, result[0].getPartialDerivative(0, 1), dLdP * lineDerivativeRelativeTolerance); UnivariateDifferentiableFunction pixelVSroll = @@ -1212,7 +1214,7 @@ public class RuggedTest { throw new RuggedExceptionWrapper(e); } }); - double dXdR = pixelVSroll.value(new DerivativeStructure(1, 1, 0, 0.0)).getPartialDerivative(1); + double dXdR = pixelVSroll.value(factory.variable(0, 0.0)).getPartialDerivative(1); Assert.assertEquals(dXdR, result[1].getPartialDerivative(1, 0), dXdR * pixelDerivativeRelativeTolerance); UnivariateDifferentiableFunction pixelVSpitch = @@ -1227,7 +1229,7 @@ public class RuggedTest { throw new RuggedExceptionWrapper(e); } }); - double dXdP = pixelVSpitch.value(new DerivativeStructure(1, 1, 0, 0.0)).getPartialDerivative(1); + double dXdP = pixelVSpitch.value(factory.variable(0, 0.0)).getPartialDerivative(1); Assert.assertEquals(dXdP, result[1].getPartialDerivative(0, 1), dXdP * pixelDerivativeRelativeTolerance); } catch (InvocationTargetException | NoSuchMethodException | diff --git a/src/test/java/org/orekit/rugged/linesensor/FixedRotationTest.java b/src/test/java/org/orekit/rugged/linesensor/FixedRotationTest.java index 487de5b1..c2add372 100644 --- a/src/test/java/org/orekit/rugged/linesensor/FixedRotationTest.java +++ b/src/test/java/org/orekit/rugged/linesensor/FixedRotationTest.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.stream.Collectors; import org.hipparchus.analysis.UnivariateMatrixFunction; +import org.hipparchus.analysis.differentiation.DSFactory; import org.hipparchus.analysis.differentiation.DerivativeStructure; import org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator; import org.hipparchus.analysis.differentiation.UnivariateDifferentiableMatrixFunction; @@ -159,6 +160,7 @@ public class FixedRotationTest { for (final ParameterDriver driver : selected) { driver.setSelected(true); } + final DSFactory factoryS = new DSFactory(selected.size(), 1); DSGenerator generator = new DSGenerator() { /** {@inheritDoc} */ @@ -170,7 +172,7 @@ public class FixedRotationTest { /** {@inheritDoc} */ @Override public DerivativeStructure constant(final double value) { - return new DerivativeStructure(selected.size(), 1, value); + return factoryS.constant(value); } /** {@inheritDoc} */ @@ -179,7 +181,7 @@ public class FixedRotationTest { int index = 0; for (ParameterDriver d : getSelected()) { if (d == driver) { - return new DerivativeStructure(getSelected().size(), 1, index, driver.getValue()); + return factoryS.variable(index, driver.getValue()); } ++index; } @@ -192,6 +194,7 @@ public class FixedRotationTest { FiniteDifferencesDifferentiator differentiator = new FiniteDifferencesDifferentiator(4, 0.001); int index = 0; + DSFactory factory11 = new DSFactory(1, 1); for (final ParameterDriver driver : selected) { int[] orders = new int[selected.size()]; orders[index] = 1; @@ -210,7 +213,7 @@ public class FixedRotationTest { throw new OrekitExceptionWrapper(oe); } }); - DerivativeStructure[][] mDS = f.value(new DerivativeStructure(1, 1, 0, driver.getValue())); + DerivativeStructure[][] mDS = f.value(factory11.variable(0, driver.getValue())); for (int i = 0; i < raw.size(); ++i) { Vector3D los = tdl.getLOS(i, AbsoluteDate.J2000_EPOCH); FieldVector3D<DerivativeStructure> losDS = diff --git a/src/test/java/org/orekit/rugged/linesensor/PolynomialRotationTest.java b/src/test/java/org/orekit/rugged/linesensor/PolynomialRotationTest.java index c4923fbc..1ef53b19 100644 --- a/src/test/java/org/orekit/rugged/linesensor/PolynomialRotationTest.java +++ b/src/test/java/org/orekit/rugged/linesensor/PolynomialRotationTest.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.stream.Collectors; import org.hipparchus.analysis.UnivariateMatrixFunction; +import org.hipparchus.analysis.differentiation.DSFactory; import org.hipparchus.analysis.differentiation.DerivativeStructure; import org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator; import org.hipparchus.analysis.differentiation.UnivariateDifferentiableMatrixFunction; @@ -175,6 +176,7 @@ public class PolynomialRotationTest { for (final ParameterDriver driver : selected) { driver.setSelected(true); } + final DSFactory factoryS = new DSFactory(selected.size(), 1); DSGenerator generator = new DSGenerator() { /** {@inheritDoc} */ @@ -186,7 +188,7 @@ public class PolynomialRotationTest { /** {@inheritDoc} */ @Override public DerivativeStructure constant(final double value) { - return new DerivativeStructure(selected.size(), 1, value); + return factoryS.constant(value); } /** {@inheritDoc} */ @@ -195,7 +197,7 @@ public class PolynomialRotationTest { int index = 0; for (ParameterDriver d : getSelected()) { if (d == driver) { - return new DerivativeStructure(getSelected().size(), 1, index, driver.getValue()); + return factoryS.variable(index, driver.getValue()); } ++index; } @@ -208,6 +210,7 @@ public class PolynomialRotationTest { FiniteDifferencesDifferentiator differentiator = new FiniteDifferencesDifferentiator(4, 0.0001); int index = 0; + DSFactory factory11 = new DSFactory(1, 1); final AbsoluteDate date = AbsoluteDate.J2000_EPOCH.shiftedBy(7.0); for (final ParameterDriver driver : selected) { int[] orders = new int[selected.size()]; @@ -227,7 +230,7 @@ public class PolynomialRotationTest { throw new OrekitExceptionWrapper(oe); } }); - DerivativeStructure[][] mDS = f.value(new DerivativeStructure(1, 1, 0, driver.getValue())); + DerivativeStructure[][] mDS = f.value(factory11.variable(0, driver.getValue())); for (int i = 0; i < raw.size(); ++i) { Vector3D los = tdl.getLOS(i, date); FieldVector3D<DerivativeStructure> losDS = tdl.getLOSDerivatives(i, date, generator); diff --git a/src/test/java/org/orekit/rugged/linesensor/SensorMeanPlaneCrossingTest.java b/src/test/java/org/orekit/rugged/linesensor/SensorMeanPlaneCrossingTest.java index 18043694..89bfcd54 100644 --- a/src/test/java/org/orekit/rugged/linesensor/SensorMeanPlaneCrossingTest.java +++ b/src/test/java/org/orekit/rugged/linesensor/SensorMeanPlaneCrossingTest.java @@ -129,7 +129,7 @@ public class SensorMeanPlaneCrossingTest { @Test public void testDerivativeWithoutCorrections() throws RuggedException, OrekitException { - doTestDerivative(false, false, 2.2e-11); + doTestDerivative(false, false, 3.1e-11); } @Test @@ -205,7 +205,7 @@ public class SensorMeanPlaneCrossingTest { // the simple model from which reference results have been compute applies here Assert.assertEquals(refLine, result.getLine(), 7.0e-14 * refLine); Assert.assertEquals(0.0, result.getDate().durationFrom(refDate), 2.0e-13); - Assert.assertEquals(0.0, Vector3D.angle(los.get(refPixel), result.getTargetDirection()), 5.1e-15); + Assert.assertEquals(0.0, Vector3D.angle(los.get(refPixel), result.getTargetDirection()), 5.4e-15); } double deltaL = 0.5; diff --git a/src/test/java/org/orekit/rugged/refraction/MultiLayerModelTest.java b/src/test/java/org/orekit/rugged/refraction/MultiLayerModelTest.java index 6df709c1..93f57c89 100644 --- a/src/test/java/org/orekit/rugged/refraction/MultiLayerModelTest.java +++ b/src/test/java/org/orekit/rugged/refraction/MultiLayerModelTest.java @@ -83,7 +83,7 @@ public class MultiLayerModelTest extends AbstractAlgorithmTest { model = new MultiLayerModel(earth, refractionLayers); correctedIntersection = model.applyCorrection(position, los, rawIntersection, algorithm); distance = Vector3D.distance(earth.transform(rawIntersection), earth.transform(correctedIntersection)); - Assert.assertEquals(0.0, distance, 1.0e-20); + Assert.assertEquals(0.0, distance, 1.7e-9); } @@ -220,7 +220,7 @@ public class MultiLayerModelTest extends AbstractAlgorithmTest { 1.5))); NormalizedGeodeticPoint correctedIntersection = model.applyCorrection(position, los, rawIntersection, algorithm); double distance = Vector3D.distance(earth.transform(rawIntersection), earth.transform(correctedIntersection)); - Assert.assertEquals(0.0, distance, 1.0e-20); + Assert.assertEquals(0.0, distance, 1.3e-9); } diff --git a/src/test/java/org/orekit/rugged/utils/ExtendedEllipsoidTest.java b/src/test/java/org/orekit/rugged/utils/ExtendedEllipsoidTest.java index 787a4e35..c50cec98 100644 --- a/src/test/java/org/orekit/rugged/utils/ExtendedEllipsoidTest.java +++ b/src/test/java/org/orekit/rugged/utils/ExtendedEllipsoidTest.java @@ -132,7 +132,7 @@ public class ExtendedEllipsoidTest { Vector3D pPlus = ellipsoid.pointAtLatitude(p, d, latitude, new Vector3D(1, p, +2.0e7, d)); GeodeticPoint gpPlus = ellipsoid.transform(pPlus, ellipsoid.getBodyFrame(), null); - Assert.assertEquals(latitude, gpPlus.getLatitude(), 3.0e-16); + Assert.assertEquals(latitude, gpPlus.getLatitude(), 4.0e-16); Assert.assertEquals(20646364.047, Vector3D.dotProduct(d, pPlus.subtract(p)), 0.001); Vector3D pMinus = ellipsoid.pointAtLatitude(p, d, latitude, new Vector3D(1, p, -3.0e7, d)); diff --git a/src/test/java/org/orekit/rugged/utils/SpacecraftToObservedBodyTest.java b/src/test/java/org/orekit/rugged/utils/SpacecraftToObservedBodyTest.java index 23145b9a..7b576feb 100644 --- a/src/test/java/org/orekit/rugged/utils/SpacecraftToObservedBodyTest.java +++ b/src/test/java/org/orekit/rugged/utils/SpacecraftToObservedBodyTest.java @@ -86,7 +86,7 @@ public class SpacecraftToObservedBodyTest { try { - SpacecraftToObservedBody sToOb = new SpacecraftToObservedBody(FramesFactory.getEME2000(), earth.getBodyFrame(), + new SpacecraftToObservedBody(FramesFactory.getEME2000(), earth.getBodyFrame(), minSensorDate, maxSensorDate, 0.01, 5.0, pvList, -- GitLab