org.opensourcephysics.numerics.dde_solvers.interpolation
Class StateMemory

java.lang.Object
  extended by org.opensourcephysics.numerics.dde_solvers.interpolation.StateMemory

public class StateMemory
extends java.lang.Object

StateMemory is a class for objects that store past states of an ODE (in form of IntervalData objects) and uses this information to provide interpolated states at different instants of time. For proper operation, the IntervalData must be ordered from old to new and the left side of each interval must match the right side of the previous interval.

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

Constructor Summary
StateMemory(ODE ode)
          Instantiates a StateMemory for a given ode
 
Method Summary
 void addIntervalData(IntervalData data)
          Adds an IntervalData at the end of the memory
 void clearAll()
          Clears all the memory data
 void clearBefore(double time)
          Clears all intervals whose data is older than the given time.
 IntervalData findInterval(double time, boolean useLeftInterval)
          Finds the interval responsible for interpolating data at this time , including the initial conditions if all other intervals fail
 java.util.Iterator<IntervalData> getDescendingIterator()
          Returns the mIntervalList in descending order.
 double[] interpolate(double time, boolean useLeftInterval, double[] state)
          Retrieve the state for the given time.
 double[] interpolate(double time, boolean useLeftInterval, double[] state, int beginIndex, int length)
          Retrieve the state for the given time for a subset of indexes
 double interpolate(double time, boolean useLeftInterval, int index)
          Retrieve the value of one entry of the state for the given time
 void setInitialConditions(IntervalData interval)
          Sets a DDE which can provide data further for time beyond the memory limits
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StateMemory

public StateMemory(ODE ode)
Instantiates a StateMemory for a given ode

Parameters:
ode -
Method Detail

setInitialConditions

public void setInitialConditions(IntervalData interval)
Sets a DDE which can provide data further for time beyond the memory limits

Parameters:
dde -

addIntervalData

public void addIntervalData(IntervalData data)
Adds an IntervalData at the end of the memory

Parameters:
data -

getDescendingIterator

public java.util.Iterator<IntervalData> getDescendingIterator()
Returns the mIntervalList in descending order. Does not include the initial conditions


clearAll

public void clearAll()
Clears all the memory data


clearBefore

public void clearBefore(double time)
Clears all intervals whose data is older than the given time. This method is used to save memory when the data is not needed anymore. The initial conditions are not cleared.

Parameters:
time -

findInterval

public IntervalData findInterval(double time,
                                 boolean useLeftInterval)
Finds the interval responsible for interpolating data at this time , including the initial conditions if all other intervals fail

Parameters:
time - double the given time for the state
useLeftInterval - boolean If the time coincides with the end of an interval, use the boolean to choose the correct interval
Returns:
IntervalData the data responsible for this instant of time, null if there is no such interval (for instance if the time extends beyond the memory limit)

interpolate

public double[] interpolate(double time,
                            boolean useLeftInterval,
                            double[] state)
Retrieve the state for the given time.

Parameters:
time - double the given time for the state
useLeftInterval - boolean If the time coincides with the end of an interval, use the boolean to choose the correct interval
state - double[] a place holder for the returned state
Returns:
double[] the array with the data, same as passed state, if the value was found in memory, null otherwise (the time extends beyond the memory limit)

interpolate

public double[] interpolate(double time,
                            boolean useLeftInterval,
                            double[] state,
                            int beginIndex,
                            int length)
Retrieve the state for the given time for a subset of indexes

Parameters:
time - double the given time for the state
useLeftInterval - boolean If the time coincides with the end of an interval, use the boolean to choose the correct interval
state - double[] a place holder for the returned state
beginIndex - the first index
length - the number of indexes requested
Returns:
double[] the array with the data, same as passed state, if the value was found in memory, null otherwise (the time extends beyond the memory limit)

interpolate

public double interpolate(double time,
                          boolean useLeftInterval,
                          int index)
Retrieve the value of one entry of the state for the given time

Parameters:
time - double the given time for the state
useLeftInterval - boolean If the time coincides with the end of an interval, use the boolean to choose the correct interval
index - the index of the value required
Returns:
double the value if found in memory, Double.NaN otherwise (the time extends beyond the memory limit)