ptolemy.domains.ct.kernel.solver
Class TrapezoidalRuleSolver

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

public class TrapezoidalRuleSolver
extends ODESolver

This is a second order variable step size ODE solver that uses the trapezoidal rule algorithm. Unlike the solvers with fixed step size, this solver adjusts its step size based on the estimation of the local truncation error.

NOTE: The design of this solver, in particular, the design of estimation of the local truncation error, is still preliminary.

For an ODE

 x' = f(x, t)
 x(0) = x0
 
the solver iterates:
 x(t+h) = x(t) + (h/2)*(x'(t) + x'(t+h))
 
This solver uses an implicit algorithm, which involves a fixed-point iteration to find x(t+h) and x'(t+h).

The local truncation error (LTE) control is based on the formula 9.78 in "Modeling and Simulation of Dynamic Systems" by Robert L. Woods and Kent L. Lawrence.

The basic idea is that once states and derivatives are resolved, denoted as x(t+h) and x'(t+h), use a two-step method with the calculated derivatives to recalculate the states, denoted as xx(t+h). Since this solver is second order, the LTE is approximately:

 abs(x(t+h) - xx(t+h))/(2^2 - 1)
 
This is used to adjust the step size.

Since:
Ptolemy II 0.2
Version:
$Id: TrapezoidalRuleSolver.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Jie Liu, 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 java.lang.String _DEFAULT_NAME
          Name of this Solver.
private  boolean _firstStep
           
private  boolean _recalculatingWithTwoSteps
           
 
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
TrapezoidalRuleSolver()
          Construct a solver in the default workspace with an empty string as name.
TrapezoidalRuleSolver(Workspace workspace)
          Construct a solver in the given workspace.
 
Method Summary
 void fireDynamicActors()
          Fire dynamic actors.
 void fireStateTransitionActors()
          Fire state transition actors.
 int getAmountOfHistoryInformation()
          Return 0 to indicate that this solver needs no history information.
 int getIntegratorAuxVariableCount()
          Return 2 to indicate that an integrator under this solver needs 2 auxiliary variables.
 void integratorFire(CTBaseIntegrator integrator)
          Fire the given integrator.
 boolean integratorIsAccurate(CTBaseIntegrator integrator)
          Perform the integratorIsAccurate() test for the integrator under this solver.
 double integratorPredictedStepSize(CTBaseIntegrator integrator)
          Provide the suggestedNextStepSize() method for integrators under this solver.
 boolean resolveStates()
          Return true if the resolved states have converged.
 
Methods inherited from class ptolemy.domains.ct.kernel.ODESolver
_advanceModelTime, _getRoundCount, _getSchedule, _incrementRoundCount, _isConverged, _makeSolverOf, _resetRoundCount, _setConverged, _voteForConverged, getContainer
 
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
Name of this Solver.

See Also:
Constant Field Values

_recalculatingWithTwoSteps

private boolean _recalculatingWithTwoSteps

_firstStep

private boolean _firstStep
Constructor Detail

TrapezoidalRuleSolver

public TrapezoidalRuleSolver()
Construct a solver in the default workspace with an empty string as name. 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_Trapezoidal_Rule_Solver".


TrapezoidalRuleSolver

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

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

fireDynamicActors

public void fireDynamicActors()
                       throws IllegalActionException
Fire dynamic actors. Advance the model time to the current model time plus the current step size.

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

fireStateTransitionActors

public void fireStateTransitionActors()
                               throws IllegalActionException
Fire state transition actors. Increment the round count. If the states have converged, reset the round count.

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

getAmountOfHistoryInformation

public int getAmountOfHistoryInformation()
Return 0 to indicate that this solver needs no history information.

Specified by:
getAmountOfHistoryInformation in class ODESolver
Returns:
0.

getIntegratorAuxVariableCount

public int getIntegratorAuxVariableCount()
Return 2 to indicate that an integrator under this solver needs 2 auxiliary variables.

Specified by:
getIntegratorAuxVariableCount in class ODESolver
Returns:
2.

integratorFire

public void integratorFire(CTBaseIntegrator integrator)
                    throws IllegalActionException
Fire the given integrator. Vote false for convergence if a fixed-point solution is not found. When the states first converged, calculate the states again with two steps (each step advance time half of the current step size) for error control.

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 send output.

integratorIsAccurate

public boolean integratorIsAccurate(CTBaseIntegrator integrator)
Perform the integratorIsAccurate() test for the integrator under this solver. This method returns true if the local truncation error (an estimation of the local error) is less than the error tolerance. Otherwise, return false.

Specified by:
integratorIsAccurate in class ODESolver
Parameters:
integrator - The integrator that calls this method.
Returns:
True if the local truncation error is less than the error tolerance.

integratorPredictedStepSize

public double integratorPredictedStepSize(CTBaseIntegrator integrator)
Provide the suggestedNextStepSize() method for integrators under this solver. If this step (with step size 'h') is successful, the local truncation error is 'localError', and the local truncation error tolerance is 'tolerance', then the suggested next step size is:
     h* max(0.5, power((3.0*tolerance/localError), 1.0/3.0))
  

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

resolveStates

public boolean resolveStates()
                      throws IllegalActionException
Return true if the resolved states have converged. Return false if states have not converged but the number of iterations reaches the maxIterations number. Mean while, the round count is reset.

Overrides:
resolveStates in class ODESolver
Returns:
True if the resolved states have converged.
Throws:
IllegalActionException - Not thrown in this base class.