org.opensourcephysics.numerics.dde_solvers
Class AbstractDiscreteTimeSolverInterpolator

java.lang.Object
  extended by org.opensourcephysics.numerics.dde_solvers.AbstractDiscreteTimeSolverInterpolator
All Implemented Interfaces:
ODESolverInterpolator
Direct Known Subclasses:
AbstractDiscreteTimeAdaptiveSolverInterpolator, Euler, EulerRichardson, Fehlberg8, RK4, VelocityVerlet

public abstract class AbstractDiscreteTimeSolverInterpolator
extends java.lang.Object
implements ODESolverInterpolator

Title: AbstractDiscreteTimeSolverInterpolator Description: Abstract class for a solver based on time discretization with state memory for interpolation

Version:
1.0 Feb 2011
Author:
Francisco Esquembre, Maria Jose Cano

Nested Class Summary
static class AbstractDiscreteTimeSolverInterpolator.WrapperDDE
           
 
Method Summary
 double[] bestInterpolate(double time, double[] state)
          Similar to interpolate(), but using the best estimate the algorith can provide and only between the current time and getMaximumTime().
 long getCounter()
          Returns the number of function evaluations required by the method to reach the tolerance
 double[] getCurrentRate()
          Returns the rate of the current state
 double getInternalStepSize()
          Returns the actual internal step size
 double getMaximumTime()
          Returns the maximum time forward in time (or minimum, if the step is negative) for which the solver can interpolate without doing any internal step.
 ODE getODE()
          Returns the ODE with which it was created.
 StateMemory getStateMemory()
          Provides access to the internal StateMemory responsible for interpolations.
 double getStepSize()
          Returns the current step size
 void initialize(double stepSize)
          Initializes the interpolator and clears the memory.
 double internalStep()
          Steps the internal step as much as possible (respecting the step size and the tolerance, if any).
 double[] interpolate(double time, boolean useLeftApproximation, double[] state)
          Returns the value of the ODE's state[] at the given time in the provided state[] array.
 void reinitialize(double[] state)
          Does the minimum (soft) initialization of the solver to a given state.
 void setEstimateFirstStep(boolean _estimate)
          Makes adaptive steps estimate the best initial step after reinitialize().
 void setMaximumStepSize(double stepSize)
          Sets a maximum step size for variable step solvers.
 void setMemoryLength(double length)
          Sets the length of the memory requested to the solver.
 void setStepSize(double stepSize)
          Changes the internal step size.
 void setTolerances(double absTol, double relTol)
          The preferred absolute and relative tolerance desired for the solution if the underlying solver supports it.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getODE

public final ODE getODE()
Description copied from interface: ODESolverInterpolator
Returns the ODE with which it was created.

Specified by:
getODE in interface ODESolverInterpolator
Returns:

initialize

public final void initialize(double stepSize)
Description copied from interface: ODESolverInterpolator
Initializes the interpolator and clears the memory. Implementing classes typically use this method to declare arrays, initialize the underlying ODESolver, set its step size, and call reinitialize().

Specified by:
initialize in interface ODESolverInterpolator

reinitialize

public void reinitialize(double[] state)
Description copied from interface: ODESolverInterpolator
Does the minimum (soft) initialization of the solver to a given state. The memory is preserved. Users of an ODESolverInterpolator MUST call reinitialize (or the harder initialize) whenever they change the state. Typically, solvers synchronize their internal states and auxiliary variables using the provided state.

Specified by:
reinitialize in interface ODESolverInterpolator
Parameters:
state - double[]

getCurrentRate

public double[] getCurrentRate()
Description copied from interface: ODESolverInterpolator
Returns the rate of the current state

Specified by:
getCurrentRate in interface ODESolverInterpolator
Returns:

setStepSize

public final void setStepSize(double stepSize)
Description copied from interface: ODESolverInterpolator
Changes the internal step size. This is the step at which internal steps are computed for fixed step methods, and the initial step size (after reinitialize()) for variable step methods.

Specified by:
setStepSize in interface ODESolverInterpolator

setMaximumStepSize

public void setMaximumStepSize(double stepSize)
Description copied from interface: ODESolverInterpolator
Sets a maximum step size for variable step solvers. Has no effect on fixed-step solvers.

Specified by:
setMaximumStepSize in interface ODESolverInterpolator

getStepSize

public final double getStepSize()
Description copied from interface: ODESolverInterpolator
Returns the current step size

Specified by:
getStepSize in interface ODESolverInterpolator
Returns:

getInternalStepSize

public final double getInternalStepSize()
Description copied from interface: ODESolverInterpolator
Returns the actual internal step size

Specified by:
getInternalStepSize in interface ODESolverInterpolator
Returns:

setEstimateFirstStep

public void setEstimateFirstStep(boolean _estimate)
Description copied from interface: ODESolverInterpolator
Makes adaptive steps estimate the best initial step after reinitialize(). If false, the given initial step (as set by setStepSize()) is used.

Specified by:
setEstimateFirstStep in interface ODESolverInterpolator

setTolerances

public void setTolerances(double absTol,
                          double relTol)
Description copied from interface: ODESolverInterpolator
The preferred absolute and relative tolerance desired for the solution if the underlying solver supports it. If the solver does not support this feature, the method is ignored. Changing the tolerances typically involves a re-computation of the current step.

Specified by:
setTolerances in interface ODESolverInterpolator

getMaximumTime

public final double getMaximumTime()
Description copied from interface: ODESolverInterpolator
Returns the maximum time forward in time (or minimum, if the step is negative) for which the solver can interpolate without doing any internal step.

Specified by:
getMaximumTime in interface ODESolverInterpolator
Returns:
double The maximum advance time or NaN if there was any error.

internalStep

public final double internalStep()
Description copied from interface: ODESolverInterpolator
Steps the internal step as much as possible (respecting the step size and the tolerance, if any).

Specified by:
internalStep in interface ODESolverInterpolator
Returns:
double Same as getMaximumTime()

getCounter

public final long getCounter()
Description copied from interface: ODESolverInterpolator
Returns the number of function evaluations required by the method to reach the tolerance

Specified by:
getCounter in interface ODESolverInterpolator
Returns:

setMemoryLength

public final void setMemoryLength(double length)
Description copied from interface: ODESolverInterpolator
Sets the length of the memory requested to the solver. Must be a positive value. The user will then be able to ask for values of the state as far as the current time minus this length. 0 is the default for plain ODE, getMaximumDelay() is the minimum used by DDEs. Setting a value of Infinity makes the solver to remmeber for ever (i.e. as much as computer memory permits)

Specified by:
setMemoryLength in interface ODESolverInterpolator

getStateMemory

public StateMemory getStateMemory()
Description copied from interface: ODESolverInterpolator
Provides access to the internal StateMemory responsible for interpolations.

Specified by:
getStateMemory in interface ODESolverInterpolator
Returns:

interpolate

public double[] interpolate(double time,
                            boolean useLeftApproximation,
                            double[] state)
Description copied from interface: ODESolverInterpolator
Returns the value of the ODE's state[] at the given time in the provided state[] array. The time must be in the range of the memory or between the current time and getMaximumTime() for correct operation.

Specified by:
interpolate in interface ODESolverInterpolator
Parameters:
time - the time for the interpolation desired
useLeftApproximation - In case of doubt, approximate the value from the left (this is important if the state has a discontinuity at that instant of time, such as for DDEs)
state - placeholder for the returned state
Returns:
The state provided as argument or null if there is no interpolation available at this time.

bestInterpolate

public double[] bestInterpolate(double time,
                                double[] state)
Description copied from interface: ODESolverInterpolator
Similar to interpolate(), but using the best estimate the algorith can provide and only between the current time and getMaximumTime(). In some RK schemes, this results in computing the RK algorithm from the initial point. Therefore, this method typically involves a bigger computational load.

Specified by:
bestInterpolate in interface ODESolverInterpolator
Returns:
The state provided as argument or null if there was any previous error.