org.opensourcephysics.numerics
Class ODEMultistepSolver

java.lang.Object
  extended by org.opensourcephysics.numerics.ODEMultistepSolver
All Implemented Interfaces:
ODEAdaptiveSolver, ODESolver

public class ODEMultistepSolver
extends java.lang.Object
implements ODEAdaptiveSolver

ODEMultistepSolver performs multiple ODE steps so that a uniform step size is maintained.

Version:
1.0
Author:
Wolfgang Christian

Nested Class Summary
protected  class ODEMultistepSolver.InternalODE
          A class that saves an internal state that may be different from the orginal ODE.
 
Field Summary
protected  boolean enableExceptions
           
protected  int err_code
           
protected  java.lang.String err_msg
           
protected  double fixedStepSize
           
protected  ODEMultistepSolver.InternalODE internalODE
           
protected  int maxIterations
           
protected  ODEAdaptiveSolver odeEngine
           
 
Fields inherited from interface org.opensourcephysics.numerics.ODEAdaptiveSolver
BISECTION_EVENT_NOT_FOUND, DID_NOT_CONVERGE, NO_ERROR
 
Constructor Summary
protected ODEMultistepSolver()
          Constructs a ODEMultistepSolver without an ODE so that a factory method can create a custom solver.
  ODEMultistepSolver(ODE ode)
          Constructs an ODEMultiStep ODE solver for a system of ordinary differential equations.
 
Method Summary
 void enableRuntimeExpecptions(boolean enable)
          Enables runtime exceptions if the solver does not converge.
 int getErrorCode()
          Gets the error code.
 double getStepSize()
          Gets the step size.
 double getTolerance()
          Gets the tolerance of the adaptive ODE solver.
 void initialize(double stepSize)
          Initializes the ODE solver.
static ODEAdaptiveSolver MultistepRK45(ODE ode)
          A factory method that creates a multisetp solver using the RK45 engine.
 void setMaximumNumberOfErrorMessages(int n)
          Sets the number of error messages if ODE solver did not converge.
 void setMaxIterations(int n)
          Sets the maximum number of iterations.
protected  ODEMultistepSolver.InternalODE setODE(ODE ode)
          Sets the ODE for this solver.
 void setStepSize(double stepSize)
          Sets the fixed step size.
 void setTolerance(double tol)
          Sets the tolerance of the adaptive ODE solver.
 double step()
          Steps (advances) the differential equations by the stepSize.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

err_code

protected int err_code

maxIterations

protected int maxIterations

enableExceptions

protected boolean enableExceptions

err_msg

protected java.lang.String err_msg

odeEngine

protected ODEAdaptiveSolver odeEngine

fixedStepSize

protected double fixedStepSize

internalODE

protected ODEMultistepSolver.InternalODE internalODE
Constructor Detail

ODEMultistepSolver

public ODEMultistepSolver(ODE ode)
Constructs an ODEMultiStep ODE solver for a system of ordinary differential equations. The default ODESolver is DormandPrince45. Other solvers can be selected using factory methods.

Parameters:
ode -

ODEMultistepSolver

protected ODEMultistepSolver()
Constructs a ODEMultistepSolver without an ODE so that a factory method can create a custom solver.

Method Detail

setODE

protected ODEMultistepSolver.InternalODE setODE(ODE ode)
Sets the ODE for this solver.

Parameters:
ode - ODE
Returns:
MyODE

MultistepRK45

public static ODEAdaptiveSolver MultistepRK45(ODE ode)
A factory method that creates a multisetp solver using the RK45 engine.

Parameters:
ode - ODE
Returns:
ODESolver

enableRuntimeExpecptions

public void enableRuntimeExpecptions(boolean enable)
Enables runtime exceptions if the solver does not converge.

Parameters:
enable - boolean

setMaxIterations

public void setMaxIterations(int n)
Sets the maximum number of iterations.

Parameters:
n - maximum

setTolerance

public void setTolerance(double tol)
Sets the tolerance of the adaptive ODE solver.

Specified by:
setTolerance in interface ODEAdaptiveSolver
Parameters:
tol - the tolerance

getTolerance

public double getTolerance()
Gets the tolerance of the adaptive ODE solver.

Specified by:
getTolerance in interface ODEAdaptiveSolver
Returns:

getErrorCode

public int getErrorCode()
Gets the error code. Error codes: ODEAdaptiveSolver.NO_ERROR ODEAdaptiveSolver.DID_NOT_CONVERGE ODEAdaptiveSolver.BISECTION_EVENT_NOT_FOUND=2;

Specified by:
getErrorCode in interface ODEAdaptiveSolver
Returns:
int

step

public double step()
Steps (advances) the differential equations by the stepSize. The ODESolver invokes the ODE's getRate method to obtain the initial state of the system. The ODESolver then advances the solution and copies the new state into the state array at the end of the solution step if desired tolerance was reached.

Specified by:
step in interface ODESolver
Returns:
the actual step

initialize

public void initialize(double stepSize)
Initializes the ODE solver. Temporary arrays may be allocated within the ODE solver.

Specified by:
initialize in interface ODESolver
Parameters:
stepSize -

setStepSize

public void setStepSize(double stepSize)
Sets the fixed step size. Multi-step solvers will perform one or more internal steps in order to perform a step with the given size.

Specified by:
setStepSize in interface ODESolver
Parameters:
stepSize -

setMaximumNumberOfErrorMessages

public void setMaximumNumberOfErrorMessages(int n)
Sets the number of error messages if ODE solver did not converge.

Parameters:
n - int

getStepSize

public double getStepSize()
Gets the step size. The step size is the fixed step size, not the size of the ODEAdaptiveSolver steps that are combined into a single step.

Specified by:
getStepSize in interface ODESolver
Returns:
the step size