ptolemy.domains.ct.kernel
Class CTMixedSignalDirector

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.util.Attribute
          extended by ptolemy.actor.Director
              extended by ptolemy.actor.sched.StaticSchedulingDirector
                  extended by ptolemy.domains.ct.kernel.CTDirector
                      extended by ptolemy.domains.ct.kernel.CTMultiSolverDirector
                          extended by ptolemy.domains.ct.kernel.CTMixedSignalDirector
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Executable, Initializable, TimedDirector, CTGeneralDirector, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

public class CTMixedSignalDirector
extends CTMultiSolverDirector

A CTDirector that supports the interaction of the continuous-time simulation with event-based domains. This director can both serve as a top-level director and an inside director that is contained by a composite actor in an event-based domain. If it is a top-level director, it behaves exactly like a CTMultiSolverDirector. If it is embedded in an event-based domain, it will run ahead of the global time and prepare to roll back if necessary.

This director has an extra parameter compared to the CTMultiSolverDirector, the maximum run ahead of time length (runAheadLength). Its default value is 1.0.

The running ahead of time is achieved by the following mechanism.

At the prefire stage, the local current time is compared with the current time of the executive director. If the local time is later than the executive director time, then the directed system will rollback to a "known good" state. The "known good" state is the state of the system at the time when local time is equal to the current time of the executive director

.

Since:
Ptolemy II 0.2
Version:
$Id: CTMixedSignalDirector.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Jie Liu, Haiyang Zheng
See Also:
Serialized Form
Accepted Rating:
Red (hyzheng)
Proposed Rating:
Yellow (hyzheng)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
 
Field Summary
private  boolean _isTop
           
private  Time _knownGoodTime
           
private  long _mutationVersion
           
private  Time _outsideTime
           
private  double _runAheadLength
           
 Parameter runAheadLength
          Parameter of the run ahead length.
 
Fields inherited from class ptolemy.domains.ct.kernel.CTMultiSolverDirector
_initialStatesNotReady, breakpointODESolver, ODESolver
 
Fields inherited from class ptolemy.domains.ct.kernel.CTDirector
_timeBase, errorTolerance, initStepSize, maxIterations, maxStepSize, minStepSize, startTime, stopTime, synchronizeToRealTime, valueResolution
 
Fields inherited from class ptolemy.actor.sched.StaticSchedulingDirector
_postfireReturns
 
Fields inherited from class ptolemy.actor.Director
_actorsFinishedExecution, _currentTime, _finishRequested, _initializables, _stopRequested, timeResolution
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
CTMixedSignalDirector()
          Construct a director in the default workspace with an empty string as its name.
CTMixedSignalDirector(CompositeEntity container, java.lang.String name)
          Construct a director in the given container with the given name.
CTMixedSignalDirector(Workspace workspace)
          Construct a director in the workspace with an empty name.
 
Method Summary
protected  void _initParameters()
          Initialize parameters in addition to the parameters inherited from CTMultiSolverDirector.
protected  boolean _isTopLevel()
          Return true if this is a top-level director.
protected  void _rollback()
          Rollback the system to a "known good" state.
 void attributeChanged(Attribute attribute)
          React to a change in an attribute.
 boolean canBeInsideDirector()
          Return true indicating that this director can be an inside director.
 void fire()
          Record the current model time as a known good time for roll back and call the super.fire() method.
 void initialize()
          Initialize the execution.
 boolean postfire()
          If this is not a top-level director, request a refiring at the current model time.
 boolean prefire()
          Always returns true, indicating that the (sub)system is always ready for one iteration.
 
Methods inherited from class ptolemy.domains.ct.kernel.CTMultiSolverDirector
_continuousPhaseExecution, _discretePhaseExecution, _isOutputAccurate, _isStateAccurate, _iterateEventGenerators, _iteratePurelyDiscreteActors, _iterateWaveformGenerators, _predictNextStepSize, _propagateResolvedStates, _refinedStepWRTOutput, _refinedStepWRTState, _removeCurrentTimeFromBreakpointTable, _resolveInitialStates, canBeTopLevelDirector, establishInitialStates, fireEventGenerators, getBreakpointSolver, getExecutiveCTGeneralDirector, getNormalODESolver, getODESolverClassName, hasCurrentEvent, postfireEventGenerators, preinitialize, produceOutput, setInitialStatesNotReady, setModelTime, updateContinuousStates
 
Methods inherited from class ptolemy.domains.ct.kernel.CTDirector
_instantiateODESolver, _setCurrentODESolver, _setDiscretePhase, _setExecutionPhase, _setIterationBeginTime, clone, delayDependency, fireAt, getBreakPoints, getCurrentODESolver, getCurrentStepSize, getErrorTolerance, getExecutionPhase, getInitialStepSize, getIterationBeginTime, getMaxIterations, getMaxStepSize, getMinStepSize, getModelNextIterationTime, getModelStartTime, getModelStopTime, getSuggestedNextStepSize, getValueResolution, isDiscretePhase, newReceiver, prefireClear, prefireDynamicActors, setCurrentStepSize, setSuggestedNextStepSize, suggestedModalModelDirectors
 
Methods inherited from class ptolemy.actor.sched.StaticSchedulingDirector
_setScheduler, addDebugListener, getScheduler, invalidateSchedule, isScheduleValid, removeDebugListener, setScheduler
 
Methods inherited from class ptolemy.actor.Director
_description, _fireContainerAt, _isEmbedded, _transferInputs, _transferOutputs, addInitializable, createSchedule, defaultDependency, finish, fireAt, fireAtCurrentTime, getCausalityInterface, getCurrentTime, getGlobalTime, getModelTime, getNextIterationTime, getStartTime, getStopTime, getTimeResolution, implementsStrictActorSemantics, initialize, invalidateResolvedTypes, isFireFunctional, isStopRequested, isStrict, iterate, preinitialize, removeInitializable, requestInitialization, setContainer, setCurrentTime, stop, stopFire, supportMultirateFiring, terminate, transferInputs, transferOutputs, wrapup
 
Methods inherited from class ptolemy.kernel.util.Attribute
_checkContainer, _getContainedObject, _propagateExistence, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setName, updateContent
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _exportMoMLContents, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, attributeList, attributeList, attributeTypeChanged, 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, propagateExistence, propagateValue, propagateValues, removeChangeListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, uniqueName, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.actor.TimedDirector
getModelTime, getTimeResolution
 

Field Detail

runAheadLength

public Parameter runAheadLength
Parameter of the run ahead length. The default value is 1.0.


_isTop

private boolean _isTop

_knownGoodTime

private Time _knownGoodTime

_mutationVersion

private long _mutationVersion

_outsideTime

private Time _outsideTime

_runAheadLength

private double _runAheadLength
Constructor Detail

CTMixedSignalDirector

public CTMixedSignalDirector()
Construct a director in the default workspace with an empty string as its name. The director is added to the list of objects in the workspace. Increment the version number of the workspace. All the parameters take their default values.


CTMixedSignalDirector

public CTMixedSignalDirector(Workspace workspace)
Construct a director in the workspace with an empty name. The director is added to the list of objects in the workspace. Increment the version number of the workspace. All the parameters take their default values.

Parameters:
workspace - The workspace of this object.

CTMixedSignalDirector

public CTMixedSignalDirector(CompositeEntity container,
                             java.lang.String name)
                      throws IllegalActionException,
                             NameDuplicationException
Construct a director in the given container with the given name. The container argument must not be null, or a NullPointerException will be thrown. If the name argument is null, then the name is set to the empty string. Increment the version number of the workspace. All the parameters take their default values.

Parameters:
container - The container.
name - Name of this director.
Throws:
IllegalActionException - If the director is not compatible with the specified container. May be thrown in a derived class.
NameDuplicationException - If the container is not a CompositeActor and the name collides with an entity in the container.
Method Detail

attributeChanged

public void attributeChanged(Attribute attribute)
                      throws IllegalActionException
React to a change in an attribute. If the changed attribute matches a parameter of the director, then the corresponding private copy of the parameter value will be updated.

Overrides:
attributeChanged in class CTMultiSolverDirector
Parameters:
attribute - The changed attribute.
Throws:
IllegalActionException - If the runAhendLength does not have a valid token, or the superclass throws it.

canBeInsideDirector

public boolean canBeInsideDirector()
Return true indicating that this director can be an inside director.

Overrides:
canBeInsideDirector in class CTMultiSolverDirector
Returns:
True always.

fire

public void fire()
          throws IllegalActionException
Record the current model time as a known good time for roll back and call the super.fire() method.

Specified by:
fire in interface Executable
Overrides:
fire in class CTMultiSolverDirector
Throws:
IllegalActionException - If thrown by the super class.

initialize

public void initialize()
                throws IllegalActionException
Initialize the execution. If this director is not at the top level, ask the executive director to fire the container of this director at the current model time.

Specified by:
initialize in interface Initializable
Overrides:
initialize in class CTMultiSolverDirector
Throws:
IllegalActionException - If thrown by the initialize method of super class, or the quest for refiring can not be accepted, or if the director does not agree to fire the actor at the specified time.
See Also:
CTMultiSolverDirector.initialize()

postfire

public boolean postfire()
                 throws IllegalActionException
If this is not a top-level director, request a refiring at the current model time. Otherwise, behave exactly as a CTMultiSolverDirector.

Specified by:
postfire in interface Executable
Overrides:
postfire in class CTMultiSolverDirector
Returns:
True if the simulation is not finished.
Throws:
IllegalActionException - If thrown in the postfire method in the super class or the refiring can not be granted, or if the director does not agree to fire the actor at the specified time.

prefire

public boolean prefire()
                throws IllegalActionException
Always returns true, indicating that the (sub)system is always ready for one iteration.

If this is not a top-level director, some additional work is done to synchronize time with the executive director. In particular, it will compare its local time, say t, with the current time of the executive director, say t0.
If t == t0, do nothing.

If t > t0, then rollback to the "known good" time (which should be less than the outside time).

If t < t0, then throw an exception because the CT subsystem should always run ahead of the outside event-based system.

If this director is not a top-level director, the iteration end time is resolved from the current time of the outside system, say t1, the next iteration time of the outside system, say t2, and the runAheadLength parameter of this director, say t3. The iteration end time is set to be t5 = t1 + min(t2, t3). The iteration end time may be further refined in the fire() method due to possible event generated during the iteration. In particular, when the first event is detected, say at t5 and t5 < t4, then the iteration ends at t5.

This method updates the suggested step size.

Specified by:
prefire in interface Executable
Overrides:
prefire in class CTMultiSolverDirector
Returns:
true Always.
Throws:
IllegalActionException - If the local time is less than the current time of the executive director, or thrown by a directed actor.

_initParameters

protected void _initParameters()
Initialize parameters in addition to the parameters inherited from CTMultiSolverDirector. In this class the additional parameter is the maximum run ahead time length (runAheadLength). The default value is 1.0.

Overrides:
_initParameters in class CTMultiSolverDirector

_isTopLevel

protected final boolean _isTopLevel()
Return true if this is a top-level director.

Overrides:
_isTopLevel in class Director
Returns:
True if this director is at the top level.

_rollback

protected void _rollback()
                  throws IllegalActionException
Rollback the system to a "known good" state. All the actors with states are called to restore their saved states. The current time of the director is set to the time of the "known good" state.

Throws:
IllegalActionException - If thrown by the goToMarkedState() method of an actor, or the schedule does not exist.