org.opensourcephysics.numerics
Class ODEBisectionEventSolver

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

public class ODEBisectionEventSolver
extends java.lang.Object
implements ODEEventSolver, ODEAdaptiveSolver

ODEBisectionEventSolver is an ODEEventSolver that uses the bisection method for root finding.

Author:
Francisco Esquembre (March 2004)

Field Summary
protected  int errorCode
           
protected  boolean eventHappened
           
protected  java.util.Vector<StateEvent> eventList
           
protected  java.util.Vector<StateEvent> happened
           
static int MAX
          Maximum number of bisections allowed
protected  int size
           
protected  ODESolver solver
           
protected  double[] statea
           
protected  org.opensourcephysics.numerics.TriggerODE triggerOde
           
 
Fields inherited from interface org.opensourcephysics.numerics.ODEAdaptiveSolver
BISECTION_EVENT_NOT_FOUND, DID_NOT_CONVERGE, NO_ERROR
 
Constructor Summary
ODEBisectionEventSolver(ODE ode, java.lang.Class<?> solverClass)
          Creates a new solver that uses the bisection method for finding the events.
 
Method Summary
 void addEvent(StateEvent event)
          Adds a StateEvent to the list of events
 int getErrorCode()
          Gets the error code.
 boolean getEventHappened()
          Gets the eventHappend flag.
 double getStepSize()
          Gets the step size.
 double getTolerance()
          Gets the tolerance of the adaptive ODE sovler.
 void initialize(double stepSize)
          Initializes the ODE solver.
 void removeEvent(StateEvent event)
          Removes a StateEvent from the list of events
 void setStepSize(double stepSize)
          Sets the initial step size.
 void setTolerance(double tol)
          Sets the tolerance of the adaptive ODE sovler.
 double step()
          Advances the ODE as usual, except if an event takes place.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX

public static final int MAX
Maximum number of bisections allowed

See Also:
Constant Field Values

size

protected int size

statea

protected double[] statea

solver

protected ODESolver solver

triggerOde

protected org.opensourcephysics.numerics.TriggerODE triggerOde

eventList

protected java.util.Vector<StateEvent> eventList

happened

protected java.util.Vector<StateEvent> happened

errorCode

protected int errorCode

eventHappened

protected boolean eventHappened
Constructor Detail

ODEBisectionEventSolver

public ODEBisectionEventSolver(ODE ode,
                               java.lang.Class<?> solverClass)
Creates a new solver that uses the bisection method for finding the events. Example of use: solver = new BisectionEventSolver (anOde,org.opensourcephysics.numerics.RK4.class); solver.addEvent(aStateEvent); // for the rest it works as any other ODESolver. Tested status: Tested with fixed step solvers. Tested with adaptive algorithms. Tested with interpolation algorithms. (See the checks for ODEInterpolationSolver!) Thought it could probably be improved a bit by changing initialize() to a (non-yet-existing) synchronize()... Performance is quite good in examples, though. Fails with Zeno-type problems (as most others :-)

Parameters:
ode - The ode to solve
solverClass - The ODESolver class to use.
Method Detail

addEvent

public void addEvent(StateEvent event)
Adds a StateEvent to the list of events

Specified by:
addEvent in interface ODEEventSolver
Parameters:
event - The event to be added

removeEvent

public void removeEvent(StateEvent event)
Removes a StateEvent from the list of events

Specified by:
removeEvent in interface ODEEventSolver
Parameters:
event - The event to be removed

initialize

public void initialize(double stepSize)
Description copied from interface: ODESolver
Initializes the ODE solver. ODE solvers use this method to allocate temporary arrays that may be required to carry out the solution. The number of differential equations is determined by invoking getState().length on the ODE.

Specified by:
initialize in interface ODESolver

setStepSize

public void setStepSize(double stepSize)
Description copied from interface: ODESolver
Sets the initial step size. The step size may change if the ODE solver implements an adaptive step size algorithm such as RK4/5.

Specified by:
setStepSize in interface ODESolver

getStepSize

public double getStepSize()
Description copied from interface: ODESolver
Gets the step size.

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

setTolerance

public void setTolerance(double tol)
Description copied from interface: ODEAdaptiveSolver
Sets the tolerance of the adaptive ODE sovler.

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

getTolerance

public double getTolerance()
Description copied from interface: ODEAdaptiveSolver
Gets the tolerance of the adaptive ODE sovler.

Specified by:
getTolerance in interface ODEAdaptiveSolver
Returns:

getEventHappened

public boolean getEventHappened()
Gets the eventHappend flag. The falg is true if an event occured during the last step.

Returns:
boolean

step

public double step()
Advances the ODE as usual, except if an event takes place. Then it finds the event point and applies the actions

Specified by:
step in interface ODESolver
Returns:
The actual step taken

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