## org.apache.commons.math.ode.jacobians
Class FirstOrderIntegratorWithJacobians

    java.lang.Object
      org.apache.commons.math.ode.jacobians.FirstOrderIntegratorWithJacobians

    public class FirstOrderIntegratorWithJacobians

extends java.lang.Object

This class enhances a first order integrator for differential equations to compute also partial derivatives of the solution with respect to initial state and parameters.

In order to compute both the state and its derivatives, the ODE problem is extended with jacobians of the raw ODE and the variational equations are added to form a new compound problem of higher dimension. If the original ODE problem has dimension n and there are p parameters, the compound problem will have dimension n × (1 + n + p).

Since:
  2.1
Version:
  $Revision: 927342 $ $Date: 2010-03-25 06:55:55 -0400 (Thu, 25 Mar 2010) $
See Also:
  `ParameterizedODE`, `ODEWithJacobians`

Nested Class Summary
`private static class` `FirstOrderIntegratorWithJacobians.EventHandlerWrapper` Wrapper for event handlers.
`private class` `FirstOrderIntegratorWithJacobians.FiniteDifferencesWrapper` Wrapper class to compute jacobians by finite differences for ODE which do not compute them themselves.
`private class` `FirstOrderIntegratorWithJacobians.MappingWrapper` Wrapper class used to map state and jacobians into compound state.
`private static class` `FirstOrderIntegratorWithJacobians.StepHandlerWrapper` Wrapper for step handlers.
`private static class` `FirstOrderIntegratorWithJacobians.StepInterpolatorWrapper` Wrapper for step interpolators.

Field Summary
`private int` `evaluations` Number of evaluations already performed.
`private FirstOrderIntegrator` `integrator` Underlying integrator for compound problem.
`private int` `maxEvaluations` Maximal number of evaluations allowed.
`private ODEWithJacobians` `ode` Raw equations to integrate.

Constructor Summary
`FirstOrderIntegratorWithJacobians(FirstOrderIntegrator integrator, ODEWithJacobians ode)` Build an enhanced integrator using ODE builtin jacobian computation features.
`FirstOrderIntegratorWithJacobians(FirstOrderIntegrator integrator, ParameterizedODE ode, double[] p, double[] hY, double[] hP)` Build an enhanced integrator using internal differentiation to compute jacobians.

Method Summary
`void` `addEventHandler(EventHandlerWithJacobians handler, double maxCheckInterval, double convergence, int maxIterationCount)` Add an event handler to the integrator.
`void` `addStepHandler(StepHandlerWithJacobians handler)` Add a step handler to this integrator.
`private void` `checkDimension(int expected, java.lang.Object array)` Check array dimensions.
`void` `clearEventHandlers()` Remove all the event handlers that have been added to the integrator.
`void` `clearStepHandlers()` Remove all the step handlers that have been added to the integrator.
`private static void` `dispatchCompoundState(double[] z, double[] y, double[][] dydy0, double[][] dydp)` Dispatch a compound state array into state and jacobians arrays.
`double` `getCurrentSignedStepsize()` Get the current signed value of the integration stepsize.
`double` `getCurrentStepStart()` Get the current value of the step start time ti.
`int` `getEvaluations()` Get the number of evaluations of the differential equations function.
`java.util.Collection<EventHandlerWithJacobians>` `getEventHandlers()` Get all the event handlers that have been added to the integrator.
`int` `getMaxEvaluations()` Get the maximal number of functions evaluations.
`java.util.Collection<StepHandlerWithJacobians>` `getStepHandlers()` Get all the step handlers that have been added to the integrator.
`double` `integrate(double t0, double[] y0, double[][] dY0dP, double t, double[] y, double[][] dYdY0, double[][] dYdP)` Integrate the differential equations and the variational equations up to the given time.
`void` `setMaxEvaluations(int maxEvaluations)` Set the maximal number of differential equations function evaluations.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### integrator

    private final FirstOrderIntegrator integrator

  Underlying integrator for compound problem.

### ode

    private final ODEWithJacobians ode

  Raw equations to integrate.

### maxEvaluations

    private int maxEvaluations

  Maximal number of evaluations allowed.

### evaluations

    private int evaluations

  Number of evaluations already performed.

Constructor Detail

### FirstOrderIntegratorWithJacobians

    public FirstOrderIntegratorWithJacobians(FirstOrderIntegrator integrator,
                                             ParameterizedODE ode,
                                             double[] p,
                                             double[] hY,
                                             double[] hP)

  Build an enhanced integrator using internal differentiation to compute jacobians.

  Parameters:
    `integrator` - underlying integrator to solve the compound problem
    `ode` - original problem (f in the equation y' = f(t, y))
    `p` - parameters array (may be null if `getParametersDimension()` from original problem is zero)
    `hY` - step sizes to use for computing the jacobian df/dy, must have the same dimension as the original problem
    `hP` - step sizes to use for computing the jacobian df/dp, must have the same dimension as the original problem parameters dimension
  See Also:
    `FirstOrderIntegratorWithJacobians(FirstOrderIntegrator, ODEWithJacobians)`

### FirstOrderIntegratorWithJacobians

    public FirstOrderIntegratorWithJacobians(FirstOrderIntegrator integrator,
                                             ODEWithJacobians ode)

  Build an enhanced integrator using ODE builtin jacobian computation features.

  Parameters:
    `integrator` - underlying integrator to solve the compound problem
    `ode` - original problem, which can compute the jacobians by itself
  See Also:
    `FirstOrderIntegratorWithJacobians(FirstOrderIntegrator, ParameterizedODE, double[], double[], double[])`

Method Detail

### addStepHandler

    public void addStepHandler(StepHandlerWithJacobians handler)

  Add a step handler to this integrator.

  The handler will be called by the integrator for each accepted step.

  Parameters:
    `handler` - handler for the accepted steps
  See Also:
    `getStepHandlers()`, `clearStepHandlers()`

### getStepHandlers

    public java.util.Collection<StepHandlerWithJacobians> getStepHandlers()

  Get all the step handlers that have been added to the integrator.

  Returns:
    an unmodifiable collection of the added events handlers
  See Also:
    `addStepHandler(StepHandlerWithJacobians)`, `clearStepHandlers()`

### clearStepHandlers

    public void clearStepHandlers()

  Remove all the step handlers that have been added to the integrator.

  See Also:
    `addStepHandler(StepHandlerWithJacobians)`, `getStepHandlers()`

### addEventHandler

    public void addEventHandler(EventHandlerWithJacobians handler,
                                double maxCheckInterval,
                                double convergence,
                                int maxIterationCount)

  Add an event handler to the integrator.

  Parameters:
    `handler` - event handler
    `maxCheckInterval` - maximal time interval between switching function checks (this interval prevents missing sign changes in case the integration steps becomes very large)
    `convergence` - convergence threshold in the event time search
    `maxIterationCount` - upper limit of the iteration count in the event time search
  See Also:
    `getEventHandlers()`, `clearEventHandlers()`

### getEventHandlers

    public java.util.Collection<EventHandlerWithJacobians> getEventHandlers()

  Get all the event handlers that have been added to the integrator.

  Returns:
    an unmodifiable collection of the added events handlers
  See Also:
    `addEventHandler(EventHandlerWithJacobians, double, double, int)`, `clearEventHandlers()`

### clearEventHandlers

    public void clearEventHandlers()

  Remove all the event handlers that have been added to the integrator.

  See Also:
    `addEventHandler(EventHandlerWithJacobians, double, double, int)`, `getEventHandlers()`

### integrate

    public double integrate(double t0,
                            double[] y0,
                            double[][] dY0dP,
                            double t,
                            double[] y,
                            double[][] dYdY0,
                            double[][] dYdP)
                     throws DerivativeException,
                            IntegratorException

  Integrate the differential equations and the variational equations up to the given time.

  This method solves an Initial Value Problem (IVP) and also computes the derivatives of the solution with respect to initial state and parameters. This can be used as a basis to solve Boundary Value Problems (BVP).

  Since this method stores some internal state variables made available in its public interface during integration (`getCurrentSignedStepsize()`), it is not thread-safe.

  Parameters:
    `t0` - initial time
    `y0` - initial value of the state vector at t0
    `dY0dP` - initial value of the state vector derivative with respect to the parameters at t0
    `t` - target time for the integration (can be set to a value smaller than `t0` for backward integration)
    `y` - placeholder where to put the state vector at each successful step (and hence at the end of integration), can be the same object as y0
    `dYdY0` - placeholder where to put the state vector derivative with respect to the initial state (dy[i]/dy0[j] is in element array dYdY0[i][j]) at each successful step (and hence at the end of integration)
    `dYdP` - placeholder where to put the state vector derivative with respect to the parameters (dy[i]/dp[j] is in element array dYdP[i][j]) at each successful step (and hence at the end of integration)
  Returns:
    stop time, will be the same as target time if integration reached its target, but may be different if some event handler stops it at some point.
  Throws:
    `IntegratorException` - if the integrator cannot perform integration
    `DerivativeException` - this exception is propagated to the caller if the underlying user function triggers one

### dispatchCompoundState

    private static void dispatchCompoundState(double[] z,
                                              double[] y,
                                              double[][] dydy0,
                                              double[][] dydp)

  Dispatch a compound state array into state and jacobians arrays.

  Parameters:
    `z` - compound state
    `y` - raw state array to fill
    `dydy0` - jacobian array to fill
    `dydp` - jacobian array to fill

### getCurrentStepStart

    public double getCurrentStepStart()

  Get the current value of the step start time ti.

  This method can be called during integration (typically by the object implementing the `differential equations` problem) if the value of the current step that is attempted is needed.

  The result is undefined if the method is called outside of calls to `integrate`.

  Returns:
    current value of the step start time ti

### getCurrentSignedStepsize

    public double getCurrentSignedStepsize()

  Get the current signed value of the integration stepsize.

  This method can be called during integration (typically by the object implementing the `differential equations` problem) if the signed value of the current stepsize that is tried is needed.

  The result is undefined if the method is called outside of calls to `integrate`.

  Returns:
    current signed value of the stepsize

### setMaxEvaluations

    public void setMaxEvaluations(int maxEvaluations)

  Set the maximal number of differential equations function evaluations.

  The purpose of this method is to avoid infinite loops which can occur for example when stringent error constraints are set or when lots of discrete events are triggered, thus leading to many rejected steps.

  Parameters:
    `maxEvaluations` - maximal number of function evaluations (negative values are silently converted to maximal integer value, thus representing almost unlimited evaluations)

### getMaxEvaluations

    public int getMaxEvaluations()

  Get the maximal number of functions evaluations.

  Returns:
    maximal number of functions evaluations

### getEvaluations

    public int getEvaluations()

  Get the number of evaluations of the differential equations function.

  The number of evaluations corresponds to the last call to the `integrate` method. It is 0 if the method has not been called yet.

  Returns:
    number of evaluations of the differential equations function

### checkDimension

    private void checkDimension(int expected,
                                java.lang.Object array)
                         throws java.lang.IllegalArgumentException

  Check array dimensions.

  Parameters:
    `expected` - expected dimension
    `array` - (may be null if expected is 0)
  Throws:
    `java.lang.IllegalArgumentException` - if the array dimension does not match the expected one

Copyright (c) 2003-2011 Apache Software Foundation