diff --git a/src/main/java/org/orekit/rugged/api/Rugged.java b/src/main/java/org/orekit/rugged/api/Rugged.java index 7335cf55501f11eb49604c02846a0e4a224f299e..b4862fa4a8d54124729e994912b4895329c2ff74 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 d10e035b487507b8622a95e7b5b4b128403b1c10..c66268d2af12e51436b3149af21c5a621c4ea7a5 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 487de5b10d38b43ed932ef0b7fb9a86b25a7d55f..c2add3720c5d14120005a9121e8f3e9ee189c338 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 c4923fbcfe1143e675c63b238c0a78d01b1417c6..1ef53b19c5515e3a4fc023c40b7e1835855074a4 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 18043694437be6c7b7b5a023a1d369b18c141d5c..89bfcd540bc767208b6545c1354db62df4db384f 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 6df709c1a7fa71a2434ee3a3e3275086d51bad7b..93f57c8935e4ea46c4efbc18360c5a1c4588548f 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 787a4e3526b772e15159a88f01f882eb09dde8ea..c50cec98fac26b27bd0904016d8f2cc5bbfa84a7 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 23145b9a548b46092ea24473c048e5f1eb778192..7b576febcad2339b2dc4e55eaff7b6eaec468817 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,