org.simulator.math.odes
Class AbstractDESSolver

java.lang.Object
  extended by org.simulator.math.odes.AbstractDESSolver
All Implemented Interfaces:
Serializable, Cloneable, EventHandler, DelayValueHolder, DESSolver
Direct Known Subclasses:
AdaptiveStepsizeIntegrator, EulerMethod, RungeKutta_EventSolver

public abstract class AbstractDESSolver
extends Object
implements DelayValueHolder, DESSolver, EventHandler

This Class represents an abstract solver for event-driven DES

Since:
0.9
Version:
$Rev: 332 $
Author:
Alexander Dörr, Andreas Dräger, Roland Keller, Hannes Planatscher, Philip Stevens, Max Zwießele
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface org.apache.commons.math.ode.events.EventHandler
CONTINUE, RESET_DERIVATIVES, RESET_STATE, STOP
 
Constructor Summary
AbstractDESSolver()
          Initialize with default integration step size and non-negative attribute true.
AbstractDESSolver(AbstractDESSolver solver)
          Clone constructor.
AbstractDESSolver(double stepSize)
          Initialize with given integration step size.
AbstractDESSolver(double stepSize, boolean nonnegative)
          Initialize with given step size and a flag whether or not negative values should be allowed.
 
Method Summary
protected  double[] additionalResults(DESystem DES, double t, double[] yTemp, MultiTable data, int rowIndex)
          Compute additional result values
 void addPropertyChangeListener(PropertyChangeListener listener)
          Add PropertyChangedListener to this Solver
abstract  AbstractDESSolver clone()
           
abstract  double[] computeChange(DESystem DES, double[] y, double t, double stepSize, double[] change, boolean steadyState)
          Computes the change for a given system at the current time with the current setting for the integration step size.
 double computeDelayedValue(double time, String id)
          Returns the value for the element with the given id at a time point in the past, where the time gives the amount of time in the past.
protected  double[] computeSteadyState(FastProcessDESystem DES, double[] result, double timeBegin)
           
 int eventOccurred(double t, double[] y, boolean increasing)
           
 void firePropertyChange(double oldValue, double newValue)
          Tell each listener that property value changed.
 double g(double t, double[] y)
           
abstract  String getName()
          This gives a human-readable name of this solver that can be displayed in a graphical user interface.
static long getSerialversionuid()
           
 double getStepSize()
          Obtain the currently set integration step size.
protected abstract  boolean hasSolverEventProcessing()
           
 int inBetweenSteps(double lastTime, double nextTime, double stepSize)
          Computes the number of necessary steps between two time steps.
protected  MultiTable initResultMatrix(DESystem DES, double[] initialValues, double[] timePoints)
           
protected  MultiTable initResultMatrix(DESystem DES, double[] initialValues, double timeBegin, double timeEnd)
           
protected  MultiTable initResultMatrix(DESystem DES, double[] initialValues, double timeBegin, int numSteps)
           
 boolean isIncludeIntermediates()
          If this method returns true, intermediate results that may originate from a RichDESystem are included into the MultiTable that contains the result of a numerical integration.
 boolean isNonnegative()
           
 boolean isUnstable()
          Method to check whether the solution of the numerical integration procedure contains Double.NaN values.
 boolean processEvents(EventDESystem EDES, double time, double previousTime, double[] yTemp)
          Processes sudden changes in the system due to events in the EDES
 boolean processEventsAndRules(boolean forceProcessing, DESystem DES, double t, double previousTime, double[] yTemp)
          Function for processing the events and rules at a certain time step.
 boolean processRules(EventDESystem EDES, double time, double[] Ytemp)
          Function for processing the rules at a certain time step.
 void removePropertyChangeListener(PropertyChangeListener listener)
          remove PropertyChangedListener to this Solver
 void reset()
          Initialize with default integration step size and non-negative attribute true.
 void resetState(double t, double[] y)
           
 void setIncludeIntermediates(boolean includeIntermediates)
          Allows switching whether or not intermediate results should be included into the MultiTable of the result.
 void setNonnegative(boolean nonnegative)
           
 void setStepSize(double stepSize)
          Set the integration step size.
 void setUnstableFlag(boolean unstableFlag)
           
 MultiTable solve(DESystem DES, double[] initialValues, double[] timePoints)
          Solves the given differential equation system with the step size h and the number of steps as given starting at the value x.
 MultiTable solve(DESystem DES, double[] initialValues, double timeBegin, double timeEnd)
          Solves the given differential equation system
 MultiTable solve(DESystem DES, double[] initialValues, double x, double h, int steps)
          Solves the given differential equation system with the step size h and the number of steps as given starting at the value x.
 MultiTable solve(DESystem DES, MultiTable.Block initConditions, double[] initialValues)
          Solves the given DESystem using new initial conditions in each time step.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.simulator.math.odes.DESSolver
getKiSAOterm
 

Constructor Detail

AbstractDESSolver

public AbstractDESSolver()
Initialize with default integration step size and non-negative attribute true.


AbstractDESSolver

public AbstractDESSolver(AbstractDESSolver solver)
Clone constructor.

Parameters:
solver -

AbstractDESSolver

public AbstractDESSolver(double stepSize)
Initialize with given integration step size.

Parameters:
stepSize -

AbstractDESSolver

public AbstractDESSolver(double stepSize,
                         boolean nonnegative)
Initialize with given step size and a flag whether or not negative values should be allowed.

Parameters:
stepSize -
nonnegative -
Method Detail

getSerialversionuid

public static long getSerialversionuid()
Returns:
the serial version uid

reset

public void reset()
Initialize with default integration step size and non-negative attribute true.


additionalResults

protected double[] additionalResults(DESystem DES,
                                     double t,
                                     double[] yTemp,
                                     MultiTable data,
                                     int rowIndex)
                              throws DerivativeException
Compute additional result values

Parameters:
DES - the differential equation system
t - the current time
yTemp - the vector yTemp
data - the data as multi table
rowIndex - the index of the row
Returns:
an array of additional (intermediate) results.
Throws:
DerivativeException

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Description copied from interface: DESSolver
Add PropertyChangedListener to this Solver

Specified by:
addPropertyChangeListener in interface DESSolver

clone

public abstract AbstractDESSolver clone()
Specified by:
clone in interface DESSolver
Overrides:
clone in class Object
Returns:
the cloned solver

computeChange

public abstract double[] computeChange(DESystem DES,
                                       double[] y,
                                       double t,
                                       double stepSize,
                                       double[] change,
                                       boolean steadyState)
                                throws DerivativeException
Computes the change for a given system at the current time with the current setting for the integration step size.

Parameters:
DES - The system to be simulated.
y - The current state of the system.
t - The current simulation time.
stepSize - The current integration step size.
change - The vector for the resulting change of the system.
steadyState -
Returns:
The change.
Throws:
Exception
DerivativeException

computeDelayedValue

public double computeDelayedValue(double time,
                                  String id)
Description copied from interface: DelayValueHolder
Returns the value for the element with the given id at a time point in the past, where the time gives the amount of time in the past.

Specified by:
computeDelayedValue in interface DelayValueHolder
Parameters:
time - the time point (in the past) at which the value is to be computed for the element with the given id.
id - the id of the delayed value
Returns:
the computed value for the element with the given identifier at the time point in the past.

computeSteadyState

protected double[] computeSteadyState(FastProcessDESystem DES,
                                      double[] result,
                                      double timeBegin)
                               throws DerivativeException
Parameters:
DES - the differential equation system
result - the result vector
timeBegin - the current time
Returns:
the computed steady state
Throws:
DerivativeException

eventOccurred

public int eventOccurred(double t,
                         double[] y,
                         boolean increasing)
                  throws EventException
Specified by:
eventOccurred in interface EventHandler
Throws:
EventException

firePropertyChange

public void firePropertyChange(double oldValue,
                               double newValue)
Description copied from interface: DESSolver
Tell each listener that property value changed. OldValue and newValue are the old and current time point of simulation, respectively.

Specified by:
firePropertyChange in interface DESSolver

g

public double g(double t,
                double[] y)
         throws EventException
Specified by:
g in interface EventHandler
Throws:
EventException

getName

public abstract String getName()
This gives a human-readable name of this solver that can be displayed in a graphical user interface.

Returns:
A name that describes the underlying algorithm.

getStepSize

public double getStepSize()
Description copied from interface: DESSolver
Obtain the currently set integration step size.

Specified by:
getStepSize in interface DESSolver
Returns:
the step size

hasSolverEventProcessing

protected abstract boolean hasSolverEventProcessing()
Returns:
Does the solver do the event processing itself?

inBetweenSteps

public int inBetweenSteps(double lastTime,
                          double nextTime,
                          double stepSize)
Computes the number of necessary steps between two time steps.

Parameters:
lastTime -
nextTime -
stepSize -
Returns:
steps the number of steps between the given time points

initResultMatrix

protected MultiTable initResultMatrix(DESystem DES,
                                      double[] initialValues,
                                      double timeBegin,
                                      double timeEnd)
Parameters:
DES -
initialValues -
timeBegin -
timeEnd -
Returns:
table the initialized MultiTable

initResultMatrix

protected MultiTable initResultMatrix(DESystem DES,
                                      double[] initialValues,
                                      double timeBegin,
                                      int numSteps)
Parameters:
DES -
initialValues -
timeBegin -
numSteps -
Returns:
table the initialized MultiTable

initResultMatrix

protected MultiTable initResultMatrix(DESystem DES,
                                      double[] initialValues,
                                      double[] timePoints)
Parameters:
DES -
initialValues -
timePoints -
Returns:
table the initialized MultiTable

isIncludeIntermediates

public boolean isIncludeIntermediates()
Description copied from interface: DESSolver
If this method returns true, intermediate results that may originate from a RichDESystem are included into the MultiTable that contains the result of a numerical integration.

Specified by:
isIncludeIntermediates in interface DESSolver
Returns:
the flag

isNonnegative

public boolean isNonnegative()
Returns:
the nonnegative flag

isUnstable

public boolean isUnstable()
Description copied from interface: DESSolver
Method to check whether the solution of the numerical integration procedure contains Double.NaN values.

Specified by:
isUnstable in interface DESSolver
Returns:
the unstableFlag

processEvents

public boolean processEvents(EventDESystem EDES,
                             double time,
                             double previousTime,
                             double[] yTemp)
                      throws DerivativeException
Processes sudden changes in the system due to events in the EDES

Parameters:
EDES - the differential equation system with events
time - the current time
previousTime - the time this function has been called previously
yTemp - the vector Ytemp
Returns:
a flag that is true if an event has been fired
Throws:
DerivativeException

processEventsAndRules

public boolean processEventsAndRules(boolean forceProcessing,
                                     DESystem DES,
                                     double t,
                                     double previousTime,
                                     double[] yTemp)
                              throws DerivativeException
Function for processing the events and rules at a certain time step.

Parameters:
forceProcessing - flag that is true if the events should be processed even if the solver has its own event processing
DES - the differential equation system with events
t - the current time
previousTime - the time this function has been called previously
yTemp - the vector Ytemp
Returns:
a flag that is true if there has been a change caused by a rule or an event has been fired
Throws:
DerivativeException

processRules

public boolean processRules(EventDESystem EDES,
                            double time,
                            double[] Ytemp)
                     throws DerivativeException
Function for processing the rules at a certain time step.

Parameters:
EDES - the differential equation system with events
time - the current time
Ytemp - the vector Ytemp
Returns:
a flag that is true if there has been a change caused by a rule
Throws:
DerivativeException

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Description copied from interface: DESSolver
remove PropertyChangedListener to this Solver

Specified by:
removePropertyChangeListener in interface DESSolver

resetState

public void resetState(double t,
                       double[] y)
                throws EventException
Specified by:
resetState in interface EventHandler
Throws:
EventException

setIncludeIntermediates

public void setIncludeIntermediates(boolean includeIntermediates)
Description copied from interface: DESSolver
Allows switching whether or not intermediate results should be included into the MultiTable of the result.

Specified by:
setIncludeIntermediates in interface DESSolver
Parameters:
includeIntermediates - if true, intermediate results are included into the result.

setNonnegative

public void setNonnegative(boolean nonnegative)
Parameters:
nonnegative - the nonnegative to set

setStepSize

public void setStepSize(double stepSize)
Description copied from interface: DESSolver
Set the integration step size.

Specified by:
setStepSize in interface DESSolver

setUnstableFlag

public void setUnstableFlag(boolean unstableFlag)
Parameters:
unstableFlag -

solve

public MultiTable solve(DESystem DES,
                        double[] initialValues,
                        double timeBegin,
                        double timeEnd)
                 throws DerivativeException
Description copied from interface: DESSolver
Solves the given differential equation system

Specified by:
solve in interface DESSolver
Parameters:
DES - the differential equation system
initialValues -
timeBegin -
timeEnd -
Returns:
result as multi table
Throws:
DerivativeException - if something's wrong...

solve

public MultiTable solve(DESystem DES,
                        double[] initialValues,
                        double x,
                        double h,
                        int steps)
                 throws DerivativeException
Description copied from interface: DESSolver
Solves the given differential equation system with the step size h and the number of steps as given starting at the value x.

Specified by:
solve in interface DESSolver
Parameters:
DES - The differential equation system to be solved.
initialValues - Return value at the start point.
x - Start argument.
h - Step size.
steps - Number of steps.
Returns:
A matrix containing the values of x, x + h, x + h + steps/h... in the rows and the columns contain the return values for the arguments.
Throws:
DerivativeException - if something's wrong...

solve

public MultiTable solve(DESystem DES,
                        double[] initialValues,
                        double[] timePoints)
                 throws DerivativeException
Description copied from interface: DESSolver
Solves the given differential equation system with the step size h and the number of steps as given starting at the value x.

Specified by:
solve in interface DESSolver
Parameters:
DES - differential equation system
initialValues -
timePoints - the time points
Returns:
result as a multi table
Throws:
DerivativeException - if something's wrong...

solve

public MultiTable solve(DESystem DES,
                        MultiTable.Block initConditions,
                        double[] initialValues)
                 throws DerivativeException
Description copied from interface: DESSolver
Solves the given DESystem using new initial conditions in each time step. The given MultiTable contains the expected solution of the solver at certain time points. The solver has the task to re-initialize the integration procedure in each given time point using the initial values from this state.

Specified by:
solve in interface DESSolver
Parameters:
DES - The DESystem to be simulated.
initConditions - A time series of initial conditions for each time point. In some cases the dimension of the given DESystem may exceed the number of columns in this given time-series. Thus, for the initialization of the simulation a full vector of initial values is required and must be passed to this method as a separate double array.
initialValues - An array of all initial values. This array may exceed the number of columns in the given MultiTable.Block but its length must equal the dimension of the given DESystem.
Returns:
A new MultiTable containing a time series of the same dimension as given by the DESystem and simulated values at each time point.
Throws:
DerivativeException

Generated December 13 2012