Author: luc Date: Thu Jan 28 15:01:55 2010 New Revision: 904112 URL: http://svn.apache.org/viewvc?rev=904112&view=rev Log: Fixed automatic step initialization in embedded Runge-Kutta integrators. The relative tolerance setting was never used, only the absolute tolerance was used. JIRA: MATH-338
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java commons/proper/math/trunk/src/site/xdoc/changes.xml commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegratorTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/HighamHall54IntegratorTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/HighamHall54StepInterpolatorTest.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java?rev=904112&r1=904111&r2=904112&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java Thu Jan 28 15:01:55 2010 @@ -17,8 +17,6 @@ package org.apache.commons.math.ode.nonstiff; -import java.util.Arrays; - import org.apache.commons.math.ode.DerivativeException; import org.apache.commons.math.ode.FirstOrderDifferentialEquations; import org.apache.commons.math.ode.IntegratorException; @@ -244,13 +242,16 @@ } if (firstTime) { - final double[] scale; - if (vecAbsoluteTolerance != null) { - scale = vecAbsoluteTolerance; - } else { - scale = new double[y0.length]; - Arrays.fill(scale, scalAbsoluteTolerance); - } + final double[] scale = new double[y0.length]; + if (vecAbsoluteTolerance == null) { + for (int i = 0; i < scale.length; ++i) { + scale[i] = scalAbsoluteTolerance + scalRelativeTolerance * Math.abs(y[i]); + } + } else { + for (int i = 0; i < scale.length; ++i) { + scale[i] = vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * Math.abs(y[i]); + } + } hNew = initializeStep(equations, forward, getOrder(), scale, stepStart, y, yDotK[0], yTmp, yDotK[1]); firstTime = false; Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=904112&r1=904111&r2=904112&view=diff ============================================================================== --- commons/proper/math/trunk/src/site/xdoc/changes.xml (original) +++ commons/proper/math/trunk/src/site/xdoc/changes.xml Thu Jan 28 15:01:55 2010 @@ -39,6 +39,11 @@ </properties> <body> <release version="2.1" date="TBD" description="TBD"> + <action dev="luc" type="fix" issue="MATH-338" due-to="Vincent Morand"> + Fixed automatic step initialization in embedded Runge-Kutta integrators. + The relative tolerance setting was never used, only the absolute tolerance + was used. + </action> <action dev="psteitz" type="fix" issue="MATH-329"> Fixed regression in Frequency.getPct(Object) introduced in 2.0. Cumulative percent was being returned for Object arguments in place of percent. Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegratorTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegratorTest.java?rev=904112&r1=904111&r2=904112&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegratorTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegratorTest.java Thu Jan 28 15:01:55 2010 @@ -145,9 +145,9 @@ integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); if (nSteps < 4) { - assertTrue(integ.getEvaluations() > 150); + assertTrue(integ.getEvaluations() > 140); } else { - assertTrue(integ.getEvaluations() < 100); + assertTrue(integ.getEvaluations() < 90); } } Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java?rev=904112&r1=904111&r2=904112&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java Thu Jan 28 15:01:55 2010 @@ -147,8 +147,8 @@ integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); - assertTrue(handler.getLastError() < 8.0e-8); - assertTrue(handler.getMaximalValueError() < 2.0e-7); + assertTrue(handler.getLastError() < 8.1e-8); + assertTrue(handler.getMaximalValueError() < 1.1e-7); assertEquals(0, handler.getMaximalTimeError(), 1.0e-12); assertEquals("Dormand-Prince 8 (5, 3)", integ.getName()); } Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/HighamHall54IntegratorTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/HighamHall54IntegratorTest.java?rev=904112&r1=904111&r2=904112&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/HighamHall54IntegratorTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/HighamHall54IntegratorTest.java Thu Jan 28 15:01:55 2010 @@ -387,7 +387,7 @@ maxError = error; } if (isLast) { - assertTrue(maxError < 4e-11); + assertTrue(maxError < 4.2e-11); assertTrue(nbSteps < 670); } } Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/HighamHall54StepInterpolatorTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/HighamHall54StepInterpolatorTest.java?rev=904112&r1=904111&r2=904112&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/HighamHall54StepInterpolatorTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/HighamHall54StepInterpolatorTest.java Thu Jan 28 15:01:55 2010 @@ -49,7 +49,7 @@ HighamHall54Integrator integ = new HighamHall54Integrator(minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance); - StepInterpolatorTestUtils.checkDerivativesConsistency(integ, pb, 1.0e-10); + StepInterpolatorTestUtils.checkDerivativesConsistency(integ, pb, 1.1e-10); } @Test