ptolemy.domains.ct.kernel.solver
Class ExplicitRK45Solver

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.domains.ct.kernel.ODESolver
          extended by ptolemy.domains.ct.kernel.solver.ExplicitRK45Solver
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

public class ExplicitRK45Solver
extends ODESolver

This class implements a fourth-order Runge-Kutta ODE solving method. The algorithm was introduced in "A Variable Order Runge-Kutta Method for Initial Value Problems with Rapidly Varying Right-Hand Sides" by J. R. Cash and Alan H. Karp, ACM Transactions on Mathematical Software, vol 16, pp. 201-222, 1990. For completeness, a brief explanation of the algorithm is explained below.

For an ODE of the form:

 dx(t)/dt = f(x(t), t), x(0) = x0
 
it does the following:
 K0 = f(x(n), tn);
 K1 = f(x(n) + 0.2*K0*h, tn + 0.2*h);
 K2 = f(x(n) + (3.0/40*K0 + 9.0/40*K1)*h, tn + 0.3*h);
 K3 = f(x(n) + (0.3*K0 - 0.9*K1 + 1.2*K2)*h, tn + 0.6*h);
 K4 = f(x(n) + (-11/54*K0 + 5.0/2*K1 -70/27*K2 + 35/27*K3)*h, tn + 1.0*h);
 K5 = f(x(n) + (1631/55296*K0 + 175/512*K1 + 575/13824*K2 + 3544275/110592*K3
 + 253/4096*K4)*h, tn + 7/8*h);
 x(n+1) = x(n)+(37/378*K0 + 250/621*K2 + 125.0/594*K3 + 512.0/1771*K5)*h;
 
, and error control:
 LTE = [(37.0/378 - 2825.0/27648)*K0 + (250.0/621 - 18575.0/48384)*K2 +
 (125.0/594 - 13525.0/55296)*K3 + (0.0 - 277.0/14336)*K4 +
 (512.0/1771 - 0.25)*K5]*h.
 

If the LTE is less than the error tolerance, then this step size h is considered successful, and the next integration step size h' is predicted as:

 h' = h * Math.pow((ErrorTolerance/LTE), 1.0/5.0)
 
This is a fourth order method, but uses a fifth order procedure to estimate the local truncation error.

It takes 6 steps for this solver to resolve a state with an integration step size. A round counter is used to record which step this solver performs.

Since:
Ptolemy II 4.1
Version:
$Id: ExplicitRK45Solver.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Haiyang Zheng
See Also:
Serialized Form
Accepted Rating:
Green (hyzheng)
Proposed Rating:
Green (hyzheng)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
 
Field Summary
private static double[][] _B
          B coefficients
private static java.lang.String _DEFAULT_NAME
          The name of the solver
private static double[] _E
          E coefficients
private static int _order
          The order of the algorithm.
private static double[] _timeInc
          The ratio of time increments within one integration step.
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Constructor Summary
ExplicitRK45Solver()
          Construct a solver in the default workspace.
ExplicitRK45Solver(Workspace workspace)
          Construct a solver in the given workspace.
 
Method Summary
protected  void _advanceModelTime()
          Override the method in the base abstract class to advance the model time.
 void fireStateTransitionActors()
          Fire state transition actors.
 int getAmountOfHistoryInformation()
          Return 0 to indicate that no history information is needed by this solver.
 int getIntegratorAuxVariableCount()
          Return 7 to indicate that 7 auxiliary variables are needed by this solver.
 void integratorFire(CTBaseIntegrator integrator)
          Fire the given integrator.
 boolean integratorIsAccurate(CTBaseIntegrator integrator)
          Return true if the integration is accurate for the given integrator.
 double integratorPredictedStepSize(CTBaseIntegrator integrator)
          Predict the next step size for the integrators executed under this solver.
 
Methods inherited from class ptolemy.domains.ct.kernel.ODESolver
_getRoundCount, _getSchedule, _incrementRoundCount, _isConverged, _makeSolverOf, _resetRoundCount, _setConverged, _voteForConverged, fireDynamicActors, getContainer, resolveStates
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _description, _exportMoMLContents, _getContainedObject, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateExistence, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, attributeChanged, attributeList, attributeList, attributeTypeChanged, clone, clone, containedObjectsIterator, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getElementName, getFullName, getModelErrorHandler, getName, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setName, setPersistent, setSource, sortContainedObjects, toplevel, toString, uniqueName, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_DEFAULT_NAME

private static final java.lang.String _DEFAULT_NAME
The name of the solver

See Also:
Constant Field Values

_timeInc

private static final double[] _timeInc
The ratio of time increments within one integration step.


_B

private static final double[][] _B
B coefficients


_E

private static final double[] _E
E coefficients


_order

private static final int _order
The order of the algorithm.

See Also:
Constant Field Values
Constructor Detail

ExplicitRK45Solver

public ExplicitRK45Solver()
Construct a solver in the default workspace. The solver is added to the list of objects in the workspace. Increment the version number of the workspace. The name of the solver is set to "CT_Runge_Kutta_4_5_Solver".


ExplicitRK45Solver

public ExplicitRK45Solver(Workspace workspace)
Construct a solver in the given workspace. If the workspace argument is null, use the default workspace. The director is added to the list of objects in the workspace. Increment the version number of the workspace. The name of the solver is set to "CT_Runge_Kutta_4_5_Solver".

Parameters:
workspace - Object for synchronization and version tracking.
Method Detail

fireStateTransitionActors

public void fireStateTransitionActors()
                               throws IllegalActionException
Fire state transition actors. Increment the round count. If the current round is the last (sixth) round, set converged flag to true indicating the fixed-point states have been reached. Reset the round count if the current round is the last round.

Overrides:
fireStateTransitionActors in class ODESolver
Throws:
IllegalActionException - If thrown in the super class.

getAmountOfHistoryInformation

public final int getAmountOfHistoryInformation()
Return 0 to indicate that no history information is needed by this solver.

Specified by:
getAmountOfHistoryInformation in class ODESolver
Returns:
0.

getIntegratorAuxVariableCount

public final int getIntegratorAuxVariableCount()
Return 7 to indicate that 7 auxiliary variables are needed by this solver.

Specified by:
getIntegratorAuxVariableCount in class ODESolver
Returns:
7.

integratorFire

public void integratorFire(CTBaseIntegrator integrator)
                    throws IllegalActionException
Fire the given integrator. This method performs the ODE solving algorithm described in the class comment.

Specified by:
integratorFire in class ODESolver
Parameters:
integrator - The integrator of that calls this method.
Throws:
IllegalActionException - If there is no director, or can not read input, or can not send output.

integratorIsAccurate

public boolean integratorIsAccurate(CTBaseIntegrator integrator)
Return true if the integration is accurate for the given integrator. This estimates the local truncation error for that integrator and compare it with the error tolerance.

Specified by:
integratorIsAccurate in class ODESolver
Parameters:
integrator - The integrator of that calls this method.
Returns:
True if the integration is successful.

integratorPredictedStepSize

public double integratorPredictedStepSize(CTBaseIntegrator integrator)
Predict the next step size for the integrators executed under this solver. It uses the algorithm in the class comments to predict the next step size based on the current estimation of the local truncation error.

Specified by:
integratorPredictedStepSize in class ODESolver
Parameters:
integrator - The integrator that calls this method.
Returns:
The next step size suggested by the given integrator.

_advanceModelTime

protected void _advanceModelTime()
                          throws IllegalActionException
Override the method in the base abstract class to advance the model time. The amount of the increment is decided by the number of the round counter and the current step size.

Overrides:
_advanceModelTime in class ODESolver
Throws:
IllegalActionException - If thrown in the super class or the model time can not be set.