diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java index 3e63c341c..0ca38aaa5 100644 --- a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java +++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java @@ -95,37 +95,7 @@ public abstract class AbstractRungeKuttaFieldStepInterpolatorTest { RungeKuttaFieldStepInterpolator interpolator = createInterpolator(field, t1 > t0, new FieldExpandableODE(eqn).getMapper()); // get the Butcher arrays from the field integrator - String interpolatorName = interpolator.getClass().getName(); - String integratorName = interpolatorName.replaceAll("StepInterpolator", "Integrator"); - - RungeKuttaFieldIntegrator fieldIntegrator = null; - try { - @SuppressWarnings("unchecked") - Class> clz = (Class>) 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 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 > RungeKuttaFieldIntegrator + createFieldIntegrator(final Field field, final RungeKuttaFieldStepInterpolator interpolator) { + RungeKuttaFieldIntegrator integrator = null; + try { + String interpolatorName = interpolator.getClass().getName(); + String integratorName = interpolatorName.replaceAll("StepInterpolator", "Integrator"); + @SuppressWarnings("unchecked") + Class> clz = (Class>) 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> implements FieldFirstOrderDifferentialEquations { private final Field field; protected SinCos(final Field field) {