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 int
protected boolean
protected Vector<StateEvent>
protected Vector<StateEvent>
static final int
Maximum number of bisections allowedprotected int
protected ODESolver
protected double[]
protected org.opensourcephysics.numerics.TriggerODE
Fields 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 TypeMethodDescriptionvoid
addEvent
(StateEvent event) Adds a StateEvent to the list of eventsint
Gets the error code.boolean
Gets the eventHappend flag.double
Gets the step size.double
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 eventsvoid
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.
-
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:
addEvent
in interfaceODEEventSolver
- Parameters:
event
- The event to be added
-
removeEvent
Removes a StateEvent from the list of events- Specified by:
removeEvent
in interfaceODEEventSolver
- 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 interfaceODESolver
-
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 interfaceODESolver
-
getStepSize
public double getStepSize()Description copied from interface:ODESolver
Gets the step size.- Specified by:
getStepSize
in interfaceODESolver
- 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 interfaceODEAdaptiveSolver
- 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 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:
getErrorCode
in interfaceODEAdaptiveSolver
- Returns:
- int
-