Package org.opensourcephysics.numerics
Class ODEMultistepSolver
java.lang.Object
org.opensourcephysics.numerics.ODEMultistepSolver
- All Implemented Interfaces:
ODEAdaptiveSolver
,ODESolver
ODEMultistepSolver performs multiple ODE steps so that a uniform step size is maintained.
- Version:
- 1.0
- Author:
- Wolfgang Christian
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected final class
A class that saves an internal state that may be different from the orginal ODE. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
protected int
protected String
protected double
protected ODEMultistepSolver.InternalODE
protected int
protected ODEAdaptiveSolver
Fields inherited from interface org.opensourcephysics.numerics.ODEAdaptiveSolver
BISECTION_EVENT_NOT_FOUND, DID_NOT_CONVERGE, NO_ERROR
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
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
Modifier and TypeMethodDescriptionvoid
enableRuntimeExpecptions
(boolean enable) Enables runtime exceptions if the solver does not converge.int
Gets the error code.double
Gets the step size.double
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
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
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.
-
Field Details
-
err_code
protected int err_code -
maxIterations
protected int maxIterations -
enableExceptions
protected boolean enableExceptions -
err_msg
-
odeEngine
-
fixedStepSize
protected double fixedStepSize -
internalODE
-
-
Constructor Details
-
ODEMultistepSolver
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 Details
-
setODE
Sets the ODE for this solver.- Parameters:
ode
- ODE- Returns:
- MyODE
-
MultistepRK45
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 interfaceODEAdaptiveSolver
- Parameters:
tol
- the tolerance
-
getTolerance
public double getTolerance()Gets the tolerance of the adaptive ODE solver.- Specified by:
getTolerance
in interfaceODEAdaptiveSolver
- 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 interfaceODEAdaptiveSolver
- 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. -
initialize
public void initialize(double stepSize) Initializes the ODE solver. Temporary arrays may be allocated within the ODE solver.- Specified by:
initialize
in interfaceODESolver
- 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 interfaceODESolver
- 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 interfaceODESolver
- Returns:
- the step size
-