separated ODEWithJacobians from ParameterizedODE:
when jacobians are already available, there is no need to have a setParameter method git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@919963 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
484fc6330b
commit
7a7eb1dccc
|
@ -112,7 +112,7 @@ public interface EventHandlerWithJacobians {
|
|||
* the step handler itself is called (see below for scheduling). It
|
||||
* allows the user to update his internal data to acknowledge the fact
|
||||
* the event has been handled (for example setting a flag in the {@link
|
||||
* org.apache.commons.math.ode.jacobians.ParameterizedODEWithJacobians
|
||||
* org.apache.commons.math.ode.jacobians.ODEWithJacobians
|
||||
* differential equations} to switch the derivatives computation in
|
||||
* case of discontinuity), or to direct the integrator to either stop
|
||||
* or continue integration, possibly with a reset state or derivatives.</p>
|
||||
|
|
|
@ -44,7 +44,7 @@ import org.apache.commons.math.ode.sampling.StepInterpolator;
|
|||
* problem has dimension n and there are p parameters, the compound problem will
|
||||
* have dimension n × (1 + n + k).</p>
|
||||
* @see ParameterizedODE
|
||||
* @see ParameterizedODEWithJacobians
|
||||
* @see ODEWithJacobians
|
||||
* @version $Revision$ $Date$
|
||||
* @since 2.1
|
||||
*/
|
||||
|
@ -54,7 +54,7 @@ public class FirstOrderIntegratorWithJacobians {
|
|||
private final FirstOrderIntegrator integrator;
|
||||
|
||||
/** Raw equations to integrate. */
|
||||
private final ParameterizedODEWithJacobians ode;
|
||||
private final ODEWithJacobians ode;
|
||||
|
||||
/** Maximal number of evaluations allowed. */
|
||||
private int maxEvaluations;
|
||||
|
@ -73,7 +73,7 @@ public class FirstOrderIntegratorWithJacobians {
|
|||
* @param hP step sizes to use for computing the jacobian df/dp, must have the
|
||||
* same dimension as the original problem parameters dimension
|
||||
* @see #FirstOrderIntegratorWithJacobians(FirstOrderIntegrator,
|
||||
* ParameterizedODEWithJacobians)
|
||||
* ODEWithJacobians)
|
||||
*/
|
||||
public FirstOrderIntegratorWithJacobians(final FirstOrderIntegrator integrator,
|
||||
final ParameterizedODE ode,
|
||||
|
@ -93,7 +93,7 @@ public class FirstOrderIntegratorWithJacobians {
|
|||
* ParameterizedODE, double[], double[], double[])
|
||||
*/
|
||||
public FirstOrderIntegratorWithJacobians(final FirstOrderIntegrator integrator,
|
||||
final ParameterizedODEWithJacobians ode) {
|
||||
final ODEWithJacobians ode) {
|
||||
this.integrator = integrator;
|
||||
this.ode = ode;
|
||||
setMaxEvaluations(-1);
|
||||
|
@ -107,7 +107,9 @@ public class FirstOrderIntegratorWithJacobians {
|
|||
* @see #clearStepHandlers()
|
||||
*/
|
||||
public void addStepHandler(StepHandlerWithJacobians handler) {
|
||||
integrator.addStepHandler(new StepHandlerWrapper(handler));
|
||||
final int n = ode.getDimension();
|
||||
final int k = ode.getParametersDimension();
|
||||
integrator.addStepHandler(new StepHandlerWrapper(handler, n, k));
|
||||
}
|
||||
|
||||
/** Get all the step handlers that have been added to the integrator.
|
||||
|
@ -149,7 +151,9 @@ public class FirstOrderIntegratorWithJacobians {
|
|||
double maxCheckInterval,
|
||||
double convergence,
|
||||
int maxIterationCount) {
|
||||
integrator.addEventHandler(new EventHandlerWrapper(handler),
|
||||
final int n = ode.getDimension();
|
||||
final int k = ode.getParametersDimension();
|
||||
integrator.addEventHandler(new EventHandlerWrapper(handler, n, k),
|
||||
maxCheckInterval, convergence, maxIterationCount);
|
||||
}
|
||||
|
||||
|
@ -438,7 +442,7 @@ public class FirstOrderIntegratorWithJacobians {
|
|||
|
||||
/** Wrapper class to compute jacobians by finite differences for ODE which do not compute them themselves. */
|
||||
private class FiniteDifferencesWrapper
|
||||
implements ParameterizedODEWithJacobians {
|
||||
implements ODEWithJacobians {
|
||||
|
||||
/** Raw ODE without jacobians computation. */
|
||||
private final ParameterizedODE ode;
|
||||
|
@ -487,18 +491,13 @@ public class FirstOrderIntegratorWithJacobians {
|
|||
return ode.getParametersDimension();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void setParameter(int i, double value) {
|
||||
ode.setParameter(i, value);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void computeJacobians(double t, double[] y, double[] yDot,
|
||||
double[][] dFdY, double[][] dFdP)
|
||||
throws DerivativeException {
|
||||
|
||||
final int n = ode.getDimension();
|
||||
final int k = ode.getParametersDimension();
|
||||
final int n = hY.length;
|
||||
final int k = hP.length;
|
||||
|
||||
evaluations += n + k;
|
||||
if (evaluations > maxEvaluations) {
|
||||
|
@ -531,16 +530,27 @@ public class FirstOrderIntegratorWithJacobians {
|
|||
}
|
||||
|
||||
/** Wrapper for step handlers. */
|
||||
private class StepHandlerWrapper implements StepHandler {
|
||||
private static class StepHandlerWrapper implements StepHandler {
|
||||
|
||||
/** Underlying step handler with jacobians. */
|
||||
private final StepHandlerWithJacobians handler;
|
||||
|
||||
/** Dimension of the original ODE. */
|
||||
private final int n;
|
||||
|
||||
/** Number of parameters. */
|
||||
private final int k;
|
||||
|
||||
/** Simple constructor.
|
||||
* @param handler underlying step handler with jacobians
|
||||
* @param n dimension of the original ODE
|
||||
* @param k number of parameters
|
||||
*/
|
||||
public StepHandlerWrapper(final StepHandlerWithJacobians handler) {
|
||||
public StepHandlerWrapper(final StepHandlerWithJacobians handler,
|
||||
final int n, final int k) {
|
||||
this.handler = handler;
|
||||
this.n = n;
|
||||
this.k = k;
|
||||
}
|
||||
|
||||
/** Get the underlying step handler with jacobians.
|
||||
|
@ -553,10 +563,7 @@ public class FirstOrderIntegratorWithJacobians {
|
|||
/** {@inheritDoc} */
|
||||
public void handleStep(StepInterpolator interpolator, boolean isLast)
|
||||
throws DerivativeException {
|
||||
handler.handleStep(new StepInterpolatorWrapper(interpolator,
|
||||
ode.getDimension(),
|
||||
ode.getParametersDimension()),
|
||||
isLast);
|
||||
handler.handleStep(new StepInterpolatorWrapper(interpolator, n, k), isLast);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
|
@ -824,7 +831,7 @@ public class FirstOrderIntegratorWithJacobians {
|
|||
}
|
||||
|
||||
/** Wrapper for event handlers. */
|
||||
private class EventHandlerWrapper implements EventHandler {
|
||||
private static class EventHandlerWrapper implements EventHandler {
|
||||
|
||||
/** Underlying event handler with jacobians. */
|
||||
private final EventHandlerWithJacobians handler;
|
||||
|
@ -840,11 +847,12 @@ public class FirstOrderIntegratorWithJacobians {
|
|||
|
||||
/** Simple constructor.
|
||||
* @param handler underlying event handler with jacobians
|
||||
* @param n dimension of the original ODE
|
||||
* @param k number of parameters
|
||||
*/
|
||||
public EventHandlerWrapper(final EventHandlerWithJacobians handler) {
|
||||
public EventHandlerWrapper(final EventHandlerWithJacobians handler,
|
||||
final int n, final int k) {
|
||||
this.handler = handler;
|
||||
final int n = ode.getDimension();
|
||||
final int k = ode.getParametersDimension();
|
||||
y = new double[n];
|
||||
dydy0 = new double[n][n];
|
||||
dydp = new double[n][k];
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
package org.apache.commons.math.ode.jacobians;
|
||||
|
||||
import org.apache.commons.math.ode.DerivativeException;
|
||||
import org.apache.commons.math.ode.FirstOrderDifferentialEquations;
|
||||
|
||||
|
||||
/** This interface represents {@link ParameterizedODE
|
||||
|
@ -29,8 +30,12 @@ import org.apache.commons.math.ode.DerivativeException;
|
|||
* @since 2.1
|
||||
*/
|
||||
|
||||
public interface ParameterizedODEWithJacobians
|
||||
extends ParameterizedODE {
|
||||
public interface ODEWithJacobians extends FirstOrderDifferentialEquations {
|
||||
|
||||
/** Get the number of parameters.
|
||||
* @return number of parameters
|
||||
*/
|
||||
int getParametersDimension();
|
||||
|
||||
/** Compute the partial derivatives of ODE with respect to state.
|
||||
* @param t current value of the independent <I>time</I> variable
|
|
@ -275,7 +275,7 @@ public class FirstOrderIntegratorWithJacobiansTest {
|
|||
Assert.assertTrue(stopTime < 5.0 * Math.PI);
|
||||
}
|
||||
|
||||
private static class Brusselator implements ParameterizedODEWithJacobians {
|
||||
private static class Brusselator implements ParameterizedODE, ODEWithJacobians {
|
||||
|
||||
private double b;
|
||||
|
||||
|
@ -323,7 +323,7 @@ public class FirstOrderIntegratorWithJacobiansTest {
|
|||
};
|
||||
|
||||
/** ODE representing a point moving on a circle with provided center and angular rate. */
|
||||
private static class Circle implements ParameterizedODEWithJacobians {
|
||||
private static class Circle implements ODEWithJacobians {
|
||||
|
||||
private final double[] y0;
|
||||
private double cx;
|
||||
|
@ -341,16 +341,6 @@ public class FirstOrderIntegratorWithJacobiansTest {
|
|||
return 2;
|
||||
}
|
||||
|
||||
public void setParameter(int i, double p) {
|
||||
if (i == 0) {
|
||||
cx = p;
|
||||
} else if (i == 1) {
|
||||
cy = p;
|
||||
} else {
|
||||
omega = p;
|
||||
}
|
||||
}
|
||||
|
||||
public int getParametersDimension() {
|
||||
return 3;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue