Package org.opensourcephysics.numerics
Class ODEBisectionEventSolver
java.lang.Object
org.opensourcephysics.numerics.ODEBisectionEventSolver
- All Implemented Interfaces:
ODEAdaptiveSolver,ODEEventSolver,ODESolver
ODEBisectionEventSolver is an ODEEventSolver that uses
the bisection method for root finding.
- Author:
- Francisco Esquembre (March 2004)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected booleanprotected Vector<StateEvent>protected Vector<StateEvent>static final intMaximum number of bisections allowedprotected intprotected ODESolverprotected double[]protected org.opensourcephysics.numerics.TriggerODEFields inherited from interface org.opensourcephysics.numerics.ODEAdaptiveSolver
BISECTION_EVENT_NOT_FOUND, DID_NOT_CONVERGE, NO_ERROR -
Constructor Summary
ConstructorsConstructorDescriptionODEBisectionEventSolver(ODE ode, Class<?> solverClass) Creates a new solver that uses the bisection method for finding the events. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddEvent(StateEvent event) Adds a StateEvent to the list of eventsintGets the error code.booleanGets the eventHappend flag.doubleGets the step size.doubleGets the tolerance of the adaptive ODE sovler.voidinitialize(double stepSize) Initializes the ODE solver.voidremoveEvent(StateEvent event) Removes a StateEvent from the list of eventsvoidsetStepSize(double stepSize) Sets the initial step size.voidsetTolerance(double tol) Sets the tolerance of the adaptive ODE sovler.doublestep()Advances the ODE as usual, except if an event takes place.
-
Field Details
-
MAX
public static final int MAXMaximum number of bisections allowed- See Also:
-
size
protected int size -
statea
protected double[] statea -
solver
-
triggerOde
protected org.opensourcephysics.numerics.TriggerODE triggerOde -
eventList
-
happened
-
errorCode
protected int errorCode -
eventHappened
protected boolean eventHappened
-
-
Constructor Details
-
ODEBisectionEventSolver
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 solvesolverClass- The ODESolver class to use.
-
-
Method Details
-
addEvent
Adds a StateEvent to the list of events- Specified by:
addEventin interfaceODEEventSolver- Parameters:
event- The event to be added
-
removeEvent
Removes a StateEvent from the list of events- Specified by:
removeEventin interfaceODEEventSolver- Parameters:
event- The event to be removed
-
initialize
public void initialize(double stepSize) Description copied from interface:ODESolverInitializes 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:
initializein interfaceODESolver
-
setStepSize
public void setStepSize(double stepSize) Description copied from interface:ODESolverSets 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:
setStepSizein interfaceODESolver
-
getStepSize
public double getStepSize()Description copied from interface:ODESolverGets the step size.- Specified by:
getStepSizein interfaceODESolver- Returns:
- the step size
-
setTolerance
public void setTolerance(double tol) Description copied from interface:ODEAdaptiveSolverSets the tolerance of the adaptive ODE sovler.- Specified by:
setTolerancein interfaceODEAdaptiveSolver- Parameters:
tol- the tolerance
-
getTolerance
public double getTolerance()Description copied from interface:ODEAdaptiveSolverGets the tolerance of the adaptive ODE sovler.- Specified by:
getTolerancein interfaceODEAdaptiveSolver- 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 -
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:
getErrorCodein interfaceODEAdaptiveSolver- Returns:
- int
-