You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2016/01/06 14:50:21 UTC
[05/50] [abbrv] [math] Fixed single integration step in step.
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/5246aa05
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/5246aa05
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/5246aa05
Branch: refs/heads/master
Commit: 5246aa0529add36a2fba243dc23a8edb0ff61094
Parents: 548dfd8
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 12:41:11 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 12:41:11 2016 +0100
----------------------------------------------------------------------
...ractRungeKuttaFieldStepInterpolatorTest.java | 74 +++++++++++---------
1 file changed, 41 insertions(+), 33 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-math/blob/5246aa05/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
----------------------------------------------------------------------
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 3e63c34..0ca38aa 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<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) {