ptolemy.domains.ct.kernel.solver
Class TrapezoidalRuleSolver

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

public class TrapezoidalRuleSolver
extends ODESolver

NOTE: The step size control mechanism in this class is not very elegant. Please avoiding using this class if possible. This is a second order variable step size ODE solver that uses the trapezoidal rule algorithm. 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 is the most accurate second order multi-step ODE solver. It is an implicit algorithm, which involves a fixed-point iteration to find x(t+h) and x'(t+h).

Since:
Ptolemy II 0.2
Version:
$Id: TrapezoidalRuleSolver.java,v 1.53 2004/04/13 05:12:51 cxh Exp $
Author:
Jie Liu
See Also:
Serialized Form
Accepted Rating:
Red (cxh)
Proposed Rating:
Red (liuj)

Nested Class Summary
 
Nested classes inherited from class ptolemy.kernel.util.NamedObj
ptolemy.kernel.util.NamedObj.ContainedObjectsIterator
 
Field Summary
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _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(ptolemy.kernel.util.Workspace workspace)
          Construct a solver in the given workspace.
 
Method Summary
protected  boolean _isConverged()
          Return true if the fixed point iteration is converged.
protected  void _setConvergence(boolean converge)
          Set the convergence flag.
protected  void _voteForConvergence(boolean converge)
          Vote for whether a fixed point has reached.
 int getHistoryCapacityRequirement()
          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)
          The fire() method for integrators under this solver.
 boolean integratorIsAccurate(CTBaseIntegrator integrator)
          Perform the isThisStepAccurate() test for the integrator under this solver.
 double integratorPredictedStepSize(CTBaseIntegrator integrator)
          Provide the suggestedNextStepSize() method for integrators under this solver.
 boolean resolveStates()
          Resolve the state of the integrators at time CurrentTime+CurrentStepSize.
 
Methods inherited from class ptolemy.domains.ct.kernel.ODESolver
_makeSolverOf, _prefireIfNecessary, getContainer, getRound, incrementRound, resetRound
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _description, _exportMoMLContents, _getContainedObject, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateExistence, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeChanged, attributeList, attributeList, attributeTypeChanged, clone, clone, containedObjectsIterator, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoML, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getDerivedLevel, getDerivedList, getElementName, getFullName, getModelErrorHandler, getName, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, message, propagateExistence, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setModelErrorHandler, setName, setPersistent, setSource, toplevel, toString, uniqueName, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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(ptolemy.kernel.util.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

getHistoryCapacityRequirement

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

Specified by:
getHistoryCapacityRequirement 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 ptolemy.kernel.util.IllegalActionException
The fire() method for integrators under this solver. It performs the ODE solving algorithm.

Specified by:
integratorFire in class ODESolver
Parameters:
integrator - The integrator of that calls this method.
Throws:
ptolemy.kernel.util.IllegalActionException - If there is no director.

integratorIsAccurate

public boolean integratorIsAccurate(CTBaseIntegrator integrator)
Perform the isThisStepAccurate() test for the integrator under this solver. This method calculates the tentative state and test whether the local truncation error (an estimation of the local error) is less than the error tolerance

Specified by:
integratorIsAccurate in class ODESolver
Parameters:
integrator - The integrator that calls this method.
Returns:
True if the intergrator report a success on the this step.

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 ptolemy.kernel.util.IllegalActionException
Resolve the state of the integrators at time CurrentTime+CurrentStepSize. It gets the state transition schedule from the scheduler and fire until the fixed point is reached.

Specified by:
resolveStates in class ODESolver
Throws:
ptolemy.kernel.util.IllegalActionException - Not thrown in this base class May be needed by the derived class.

_isConverged

protected boolean _isConverged()
Return true if the fixed point iteration is converged. This is the result of all _voteForConvergence() in the current integration step.

Returns:
True if all the votes are true.

_setConvergence

protected void _setConvergence(boolean converge)
Set the convergence flag. Usually called to reset the flag to false at the beginning of an integration step.

Parameters:
converge - The flag setting.

_voteForConvergence

protected void _voteForConvergence(boolean converge)
Vote for whether a fixed point has reached. The final result is the and of all votes.

Parameters:
converge - True if vote for converge.