Class ODEBisectionEventSolver

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

public class ODEBisectionEventSolver extends Object implements ODEEventSolver, ODEAdaptiveSolver
ODEBisectionEventSolver is an ODEEventSolver that uses the bisection method for root finding.
Author:
Francisco Esquembre (March 2004)
  • Field Details

    • MAX

      public static final int MAX
      Maximum number of bisections allowed
      See Also:
    • size

      protected int size
    • statea

      protected double[] statea
    • solver

      protected ODESolver solver
    • triggerOde

      protected org.opensourcephysics.numerics.TriggerODE triggerOde
    • eventList

      protected Vector<StateEvent> eventList
    • happened

      protected Vector<StateEvent> happened
    • errorCode

      protected int errorCode
    • eventHappened

      protected boolean eventHappened
  • Constructor Details

    • ODEBisectionEventSolver

      public ODEBisectionEventSolver(ODE ode, 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 Details

    • 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