NumericalSolver Class Reference

Inheritance diagram for NumericalSolver:

Inheritance graph
[legend]

List of all members.


Detailed Description

Abstract numerical solver for a system of differential equations.

Author:
Lawrence Murray <lawrence@indii.org>
Version:
Rev
Date:
Date

Definition at line 24 of file NumericalSolver.hpp.


Public Member Functions

 NumericalSolver (const unsigned int dimensions)
 Constructor.
 NumericalSolver (const indii::ml::aux::vector &y0)
 Constructor.
virtual ~NumericalSolver ()
 Destructor.
unsigned int getDimensions ()
 Get dimensionality of the state space.
double getTime ()
 Get the current time.
void setTime (const double t)
 Set the current time.
double getVariable (const unsigned int index)
 Get the value of a state variable at the current time.
void setVariable (const unsigned int index, const double value)
 Set the value of a state variable.
indii::ml::aux::vector getState ()
 Get the state at the current time.
void setState (const indii::ml::aux::vector &y)
 Set the state at the current time.
virtual double step (double upper)
 Advance the system one time step.
void stepTo (double to)
 Advance the system to a particular time.
virtual double stepBack (double lower)
 Rewind the system one time step.
void stepBackTo (double to)
 Rewind the system to a specific time.
void setErrorBounds (double maxAbsoluteError=1e-6, double maxRelativeError=1e-6)
 Set the error bounds.
void setStepSize (double stepSize)
 Set the proposed size for the next time step.
double getStepSize ()
 Get the proposed size for the next time step.
void setSuggestedStepSize (double stepSize=1.0e-7)
 Set the suggested step size.
double getSuggestedStepSize ()
 Get the suggested step size.
void setMaxStepSize (double stepSize=0.0)
 Set the maximum step size.
double getMaxStepSize ()
 Get the maximum step size.
void setDiscontinuity ()
 Indicates a discontinuity at the current time.
void setStepType (const gsl_odeiv_step_type *stepType)
 Set the stepping method.
virtual int calculateDerivativesForward (double t, const double y[], double dydt[])=0
 Calculate derivatives for forwards step.
virtual int calculateDerivativesBackward (double t, const double y[], double dydt[])=0
 Calculate derivatives for backwards step.

Protected Member Functions

void init ()
 Initialise the system.
void terminate ()
 Terminate the system.
virtual void reset ()
 Reset the model.

Protected Attributes

const size_t dimensions
 Dimensionality of the system of differential equations.
double t
 $t$; the current time
double * y
 Array of state variables of the system.
double base
 Base time used for backward steps.
double stepSize
 Proposed size for the next time step.
double maxStepSize
 Maximum step size.
double suggestedStepSize
 Suggested step size.
gsl_odeiv_step * gslStep
 GSL ordinary differential equations step structure.
gsl_odeiv_control * gslControl
 GSL ordinary differential equations control structure.
gsl_odeiv_evolve * gslEvolve
 GSL ordinary differential equations evolution structure.
gsl_odeiv_system gslForwardSystem
 GSL system of ordinary differential equations for forward steps in time.
gsl_odeiv_system gslBackwardSystem
 GSL system of ordinary differential equations for backward steps in time.

Constructor & Destructor Documentation

NumericalSolver ( const unsigned int  dimensions  ) 

Constructor.

Parameters:
dimensions Dimensionality of the state space.
The time is initialised to zero, but the state is uninitialised and should be set with setVariable() or setState().

Definition at line 13 of file NumericalSolver.cpp.

NumericalSolver ( const indii::ml::aux::vector y0  ) 

Constructor.

Parameters:
y0 Initial state.
The time is initialised to zero and the state to that given.

Definition at line 28 of file NumericalSolver.cpp.

~NumericalSolver (  )  [virtual]

Destructor.

Definition at line 44 of file NumericalSolver.cpp.


Member Function Documentation

unsigned int getDimensions (  )  [inline]

Get dimensionality of the state space.

Definition at line 382 of file NumericalSolver.hpp.

double getTime (  )  [inline]

Get the current time.

Definition at line 386 of file NumericalSolver.hpp.

void setTime ( const double  t  ) 

Set the current time.

Parameters:
t Time.
See also:
setVariable() or setState() to update the state for the new time also.

Definition at line 49 of file NumericalSolver.cpp.

double getVariable ( const unsigned int  index  )  [inline]

Get the value of a state variable at the current time.

Parameters:
index Index of the state variable to retrieve.
Returns:
The value of the state variable at the current time.

Definition at line 390 of file NumericalSolver.hpp.

void setVariable ( const unsigned int  index,
const double  value 
)

Set the value of a state variable.

Parameters:
index Index of the state variable to set.
value The value to which to set the state variable.

Definition at line 158 of file NumericalSolver.cpp.

indii::ml::aux::vector getState (  )  [inline]

Get the state at the current time.

Returns:
Current state of the system.

Definition at line 398 of file NumericalSolver.hpp.

void setState ( const indii::ml::aux::vector y  ) 

Set the state at the current time.

Parameters:
y New state of the system.

Definition at line 167 of file NumericalSolver.cpp.

double step ( double  upper  )  [virtual]

Advance the system one time step.

The size of the step is chosen to be optimal given the provided error bounds. State variables are updated to this new time after completion of the step.

Parameters:
upper Upper bound on time. This must be greater than the current time. The current time is guaranteed not to exceed this value after the step is complete. It may equal this time, and indeed if step() is continuously called with the same upper bound it will eventually do so.
Returns:
The new current time.

Reimplemented in StochasticAdaptiveEulerMaruyama, StochasticAdaptiveRungeKutta, and StochasticEulerMaruyama.

Definition at line 54 of file NumericalSolver.cpp.

void stepTo ( double  to  ) 

Advance the system to a particular time.

This convenience method internally calls step() as many times as necessary to advance the system to the given time. This is useful if fixed time steps are required rather than the variable steps taken by step().

Parameters:
to The time to which to advance the system. This must be greater than the current time. The current time is guaranteed to match this value at the end of the call.

Definition at line 73 of file NumericalSolver.cpp.

double stepBack ( double  lower  )  [virtual]

Rewind the system one time step.

This works in the same fashion at step(), except that the step is backwards in time.

Parameters:
lower Lower bound on time. This must be less than the current time. The current time is guaranteed not to be below this value after the step is complete. It may equal this time, and indeed if stepBack() is continuously called with the same lower bound it will eventually do so.
Returns:
The new current time.

Reimplemented in StochasticAdaptiveEulerMaruyama, StochasticAdaptiveRungeKutta, and StochasticEulerMaruyama.

Definition at line 86 of file NumericalSolver.cpp.

void stepBackTo ( double  to  ) 

Rewind the system to a specific time.

This convenience method internally calls stepBack() as many times as necessary to rewind the system to a given point in time. This is useful if fixed time steps are required rather than the variable steps taken by stepBack().

Parameters:
to The time to which to rewind the system. This must be less than the current time. The current time is guaranteed to match this value at the end of the call.

Definition at line 117 of file NumericalSolver.cpp.

void setErrorBounds ( double  maxAbsoluteError = 1e-6,
double  maxRelativeError = 1e-6 
)

Set the error bounds.

Smaller error bounds produce more accurate estimates, but reduce the size of time steps, so that more steps are required in order to estimate functions over the same length of time.

Parameters:
maxAbsoluteError The maximum permitted absolute error of estimated values compared to real values.
maxRelativeError The maximum permitted relative error of estimated values compared to real values.

Definition at line 130 of file NumericalSolver.cpp.

void setStepSize ( double  stepSize  ) 

Set the proposed size for the next time step.

This is useful for handling discontinuities, where step() may be called to advance to the discontinuity, then setStepSize() used to propose a small step size ensuring that the discontinuity is tiptoed across rather than leapt.

It should be called immediately before any call to step() or stepTo(). Any other methods called in between may themselves adjust the proposed step size.

Parameters:
stepSize The proposed time step size for the next call to step().
Note that this sets only the proposed step size -- it will be optimised, within some constraints, relative to the permitted error bounds.

Definition at line 141 of file NumericalSolver.cpp.

double getStepSize (  )  [inline]

Get the proposed size for the next time step.

Returns:
The proposed time step size for the next call to step().

Definition at line 408 of file NumericalSolver.hpp.

void setSuggestedStepSize ( double  stepSize = 1.0e-7  ) 

Set the suggested step size.

The step size is set to this immediately, and subsequently after any calls to setDiscontinuity().

Parameters:
stepSize The suggested step size.
Note that this sets only the proposed step size -- it will be optimised, within some constraints, relative to the permitted error bounds.

Definition at line 145 of file NumericalSolver.cpp.

double getSuggestedStepSize (  )  [inline]

Get the suggested step size.

Returns:
The suggested step size.

Definition at line 412 of file NumericalSolver.hpp.

void setMaxStepSize ( double  stepSize = 0.0  ) 

Set the maximum step size.

Parameters:
stepSize The maximum step size.
This is useful for bounding the step size on schemes which may propose steps that, for some models, produce inf or nan derivative calculations. Empirically, we particularly observe this with implicit schemes. By default the step size is not bound.

Definition at line 150 of file NumericalSolver.cpp.

double getMaxStepSize (  )  [inline]

Get the maximum step size.

Returns:
The maximum step size.

Definition at line 416 of file NumericalSolver.hpp.

void setDiscontinuity (  ) 

Indicates a discontinuity at the current time.

Internally, this simply calls setStepSize() with the suggested step size.

Definition at line 154 of file NumericalSolver.cpp.

void setStepType ( const gsl_odeiv_step_type *  stepType  ) 

Set the stepping method.

Parameters:
stepType The stepping method.
This allows modification of the underlying numerical scheme used by the solver, as specified by the GSL. For advanced users only.

Definition at line 216 of file NumericalSolver.cpp.

virtual int calculateDerivativesForward ( double  t,
const double  y[],
double  dydt[] 
) [pure virtual]

Calculate derivatives for forwards step.

Implemented in AdaptiveRungeKutta, StochasticAdaptiveEulerMaruyama, StochasticAdaptiveRungeKutta, and StochasticEulerMaruyama.

virtual int calculateDerivativesBackward ( double  t,
const double  y[],
double  dydt[] 
) [pure virtual]

Calculate derivatives for backwards step.

Implemented in AdaptiveRungeKutta, StochasticAdaptiveEulerMaruyama, StochasticAdaptiveRungeKutta, and StochasticEulerMaruyama.

void init (  )  [protected]

Initialise the system.

Should be called before any calls to step() or stepTo().

Definition at line 178 of file NumericalSolver.cpp.

void terminate (  )  [protected]

Terminate the system.

Should be called after work with the system has been finished. Will be called by the destructor if it hasn't been already.

Definition at line 194 of file NumericalSolver.cpp.

void reset (  )  [protected, virtual]

Reset the model.

This is used internally to reset GSL structures when the next step will not be a continuation of the last, usually when the time or state is changed with a call to setTime(), setVariable() or setState().

Reimplemented in StochasticNumericalSolver.

Definition at line 210 of file NumericalSolver.cpp.


Member Data Documentation

const size_t dimensions [protected]

Dimensionality of the system of differential equations.

Definition at line 270 of file NumericalSolver.hpp.

double t [protected]

$t$; the current time

Definition at line 275 of file NumericalSolver.hpp.

double* y [protected]

Array of state variables of the system.

Definition at line 280 of file NumericalSolver.hpp.

double base [protected]

Base time used for backward steps.

Definition at line 285 of file NumericalSolver.hpp.

double stepSize [protected]

Proposed size for the next time step.

Definition at line 290 of file NumericalSolver.hpp.

double maxStepSize [protected]

Maximum step size.

Definition at line 295 of file NumericalSolver.hpp.

double suggestedStepSize [protected]

Suggested step size.

Definition at line 300 of file NumericalSolver.hpp.

gsl_odeiv_step* gslStep [protected]

GSL ordinary differential equations step structure.

Definition at line 305 of file NumericalSolver.hpp.

gsl_odeiv_control* gslControl [protected]

GSL ordinary differential equations control structure.

Definition at line 310 of file NumericalSolver.hpp.

gsl_odeiv_evolve* gslEvolve [protected]

GSL ordinary differential equations evolution structure.

Definition at line 315 of file NumericalSolver.hpp.

gsl_odeiv_system gslForwardSystem [protected]

GSL system of ordinary differential equations for forward steps in time.

Definition at line 321 of file NumericalSolver.hpp.

gsl_odeiv_system gslBackwardSystem [protected]

GSL system of ordinary differential equations for backward steps in time.

Definition at line 327 of file NumericalSolver.hpp.


Generated on Wed Dec 17 15:11:58 2008 for dysii Dynamical Systems Library by  doxygen 1.5.3