commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject [25/50] [abbrv] [math] Fixed single integration step in step.
Date Wed, 09 Dec 2015 16:17:05 GMT
Fixed single integration step in step.

Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/6d8c6369
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/6d8c6369
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/6d8c6369

Branch: refs/heads/MATH_3_X
Commit: 6d8c6369595afd421c5c487388cabe96e78c0170
Parents: dfdaea2
Author: Luc Maisonobe <luc@apache.org>
Authored: Fri Dec 4 11:31:26 2015 +0100
Committer: Luc Maisonobe <luc@apache.org>
Committed: Fri Dec 4 11:31:26 2015 +0100

----------------------------------------------------------------------
 ...ractRungeKuttaFieldStepInterpolatorTest.java | 74 +++++++++++---------
 1 file changed, 41 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/6d8c6369/src/test/java/org/apache/commons/math3/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math3/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
b/src/test/java/org/apache/commons/math3/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
index 43dfddf..e088434 100644
--- a/src/test/java/org/apache/commons/math3/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math3/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
@@ -95,37 +95,7 @@ public abstract class AbstractRungeKuttaFieldStepInterpolatorTest {
         RungeKuttaFieldStepInterpolator<T> interpolator = createInterpolator(field,
t1 > t0,
                                                                              new FieldExpandableODE<T>(eqn).getMapper());
         // get the Butcher arrays from the field integrator
-        String interpolatorName = interpolator.getClass().getName();
-        String integratorName = interpolatorName.replaceAll("StepInterpolator", "Integrator");
-
-        RungeKuttaFieldIntegrator<T> fieldIntegrator = null;
-        try {
-            @SuppressWarnings("unchecked")
-            Class<RungeKuttaFieldIntegrator<T>> clz = (Class<RungeKuttaFieldIntegrator<T>>)
Class.forName(integratorName);
-            try {
-                fieldIntegrator = clz.getConstructor(Field.class, RealFieldElement.class).newInstance(field,
-                                                                                        
             field.getOne());
-            } catch (NoSuchMethodException nsme) {
-                try {
-                    fieldIntegrator = clz.getConstructor(Field.class, RealFieldElement.class,
-                                                         RealFieldElement.class, RealFieldElement.class).newInstance(field,
-                                                                                        
                            field.getZero().add(0.001),
-                                                                                        
                            field.getOne(),
-                                                                                        
                            field.getOne(),
-                                                                                        
                            field.getOne());
-                } catch (NoSuchMethodException e) {
-                    Assert.fail(e.getLocalizedMessage());
-                }
-            }
-        } catch (InvocationTargetException ite) {
-            Assert.fail(ite.getLocalizedMessage());
-        } catch (IllegalAccessException iae) {
-            Assert.fail(iae.getLocalizedMessage());
-        } catch (InstantiationException ie) {
-            Assert.fail(ie.getLocalizedMessage());
-        } catch (ClassNotFoundException cnfe) {
-            Assert.fail(cnfe.getLocalizedMessage());
-        }
+        RungeKuttaFieldIntegrator<T> fieldIntegrator = createFieldIntegrator(field,
interpolator);
         T[][] a = fieldIntegrator.getA();
         T[]   b = fieldIntegrator.getB();
         T[]   c = fieldIntegrator.getC();
@@ -146,8 +116,8 @@ public abstract class AbstractRungeKuttaFieldStepInterpolatorTest {
         for (int k = 0; k < a.length; ++k) {
             for (int i = 0; i < y0.length; ++i) {
                 fieldY[i] = field.getZero().add(y0[i]);
-                for (int s = 0; s < k; ++s) {
-                    fieldY[i] = fieldY[i].add(h.multiply(a[s][i].multiply(fieldYDotK[s][i])));
+                for (int s = 0; s <= k; ++s) {
+                    fieldY[i] = fieldY[i].add(h.multiply(a[k][s].multiply(fieldYDotK[s][i])));
                 }
             }
             fieldYDotK[k + 1] = eqn.computeDerivatives(h.multiply(c[k]).add(t0), fieldY);
@@ -169,6 +139,44 @@ public abstract class AbstractRungeKuttaFieldStepInterpolatorTest {
 
     }
 
+    private <T extends RealFieldElement<T>> RungeKuttaFieldIntegrator<T>
+    createFieldIntegrator(final Field<T> field, final RungeKuttaFieldStepInterpolator<T>
interpolator) {
+        RungeKuttaFieldIntegrator<T> integrator = null;
+        try {
+        String interpolatorName = interpolator.getClass().getName();
+        String integratorName = interpolatorName.replaceAll("StepInterpolator", "Integrator");
+            @SuppressWarnings("unchecked")
+            Class<RungeKuttaFieldIntegrator<T>> clz = (Class<RungeKuttaFieldIntegrator<T>>)
Class.forName(integratorName);
+            try {
+                integrator = clz.getConstructor(Field.class, RealFieldElement.class).newInstance(field,
+                                                                                        
             field.getOne());
+            } catch (NoSuchMethodException nsme) {
+                try {
+                    integrator = clz.getConstructor(Field.class,
+                                                    RealFieldElement.class,
+                                                    RealFieldElement.class,
+                                                    RealFieldElement.class).
+                                 newInstance(field, field.getZero().add(0.001),
+                                             field.getOne(), field.getOne(), field.getOne());
+                } catch (NoSuchMethodException e) {
+                    Assert.fail(e.getLocalizedMessage());
+                }
+            }
+
+        } catch (InvocationTargetException ite) {
+            Assert.fail(ite.getLocalizedMessage());
+        } catch (IllegalAccessException iae) {
+            Assert.fail(iae.getLocalizedMessage());
+        } catch (InstantiationException ie) {
+            Assert.fail(ie.getLocalizedMessage());
+        } catch (ClassNotFoundException cnfe) {
+            Assert.fail(cnfe.getLocalizedMessage());
+        }
+
+        return integrator;
+
+    }
+
     private static class SinCos<T extends RealFieldElement<T>> implements FieldFirstOrderDifferentialEquations<T>
{
         private final Field<T> field;
         protected SinCos(final Field<T> field) {


Mime
View raw message