ptolemy.domains.ct.kernel
Class CTMixedSignalDirector

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

public class CTMixedSignalDirector
extends CTMultiSolverDirector

This is 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 acts exactly like a CTMultiSolverDirector. If it is embedded in another event-based domain, it will run ahead of the global time and prepare to roll back if necessary.

This class has an extra parameter as compare to the CTMultiSolverDirector, which is the maximum run ahead of time length (runAheadLength). The default value is 1.0.

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

Since:
Ptolemy II 0.2
Version:
$Id: CTMixedSignalDirector.java,v 1.110.2.1 2004/07/31 01:09:45 cxh Exp $
Author:
Jie Liu
See Also:
Serialized Form
Accepted Rating:
Green (chf)
Proposed Rating:
Green (liuj)

Nested Class Summary
 
Nested classes inherited from class ptolemy.kernel.util.NamedObj
ptolemy.kernel.util.NamedObj.ContainedObjectsIterator
 
Field Summary
protected  int _Nroll
          The number of rollbacks.
 ptolemy.data.expr.Parameter runAheadLength
          Parameter of the run ahead length.
 
Fields inherited from class ptolemy.domains.ct.kernel.CTMultiSolverDirector
breakpointODESolver, ODESolver
 
Fields inherited from class ptolemy.domains.ct.kernel.CTDirector
_postfireReturns, _refireActors, errorTolerance, initStepSize, maxIterations, maxStepSize, minStepSize, startTime, stopTime, synchronizeToRealTime, timeResolution, valueResolution
 
Fields inherited from class ptolemy.actor.Director
_currentTime, _stopRequested
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _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(ptolemy.kernel.CompositeEntity container, java.lang.String name)
          Construct a director in the given container with the given name.
CTMixedSignalDirector(ptolemy.kernel.util.Workspace workspace)
          Construct a director in the workspace with an empty name.
 
Method Summary
protected  void _catchUp()
          Catch up the simulation from a known good state to the outside current time.
protected  void _initParameters()
          Initialize parameters in addition to the parameters inherited from CTMultiSolverDirector.
protected  boolean _isStoppedByEvent()
          Return true if the current fire phase is stopped due to the occurrence of events (predictable or unpredictable).
protected  boolean _isTopLevel()
          Return true if this is a top-level director.
protected  void _markStates()
          Mark the current state as the known good state.
protected  void _rollback()
          Rollback the system to a "known good" state.
protected  void _setIterationEndTime(double time)
          Set the end time for this iteration.
 void attributeChanged(ptolemy.kernel.util.Attribute attribute)
          React to a change in an attribute.
 boolean canBeInsideDirector()
          Return true indicating that this director can be an inside director.
 void fire()
          Execute the directed (sub)system to the iteration end time.
 double getIterationEndTime()
          Return the end time of this director's current iteration.
 double getOutsideTime()
          Return the time of the outside domain.
 void initialize()
          First initialize the execution as in CTMultiSolverDirector.
 boolean postfire()
          If this is a top-level director, behave exactly as a CTMultiSolverDirector, otherwise always return true.
 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, _fireOneIteration, _isOutputAccurate, _isStateAccurate, _predictNextStepSize, _prefireDynamicActors, _processBreakpoints, _refinedStepWRTOutput, _refinedStepWRTState, canBeTopLevelDirector, getBreakpointSolver, getODESolver, hasCurrentEvent, preinitialize
 
Methods inherited from class ptolemy.domains.ct.kernel.CTDirector
_areTimesCloseEnough, _instantiateODESolver, _setBreakpointIteration, _setCurrentODESolver, _setDiscretePhase, _setIterationBeginTime, _writeAccessRequired, fireAt, getBreakPoints, getCurrentODESolver, getCurrentStepSize, getErrorTolerance, getInitialStepSize, getIterationBeginTime, getMaxIterations, getMaxStepSize, getMinStepSize, getNextIterationTime, getStartTime, getStopTime, getSuggestedNextStepSize, getValueResolution, isBreakpointIteration, isDiscretePhase, isPrefireComplete, newReceiver, prefireClear, produceOutput, setCurrentStepSize, setCurrentTime, setPrefireComplete, setSuggestedNextStepSize, updateContinuousStates
 
Methods inherited from class ptolemy.actor.sched.StaticSchedulingDirector
_setScheduler, addDebugListener, getScheduler, invalidateSchedule, isScheduleValid, removeDebugListener, setScheduler, setScheduleValid
 
Methods inherited from class ptolemy.actor.Director
_description, _isEmbedded, domainPolymorphicTransferInputs, domainPolymorphicTransferOutputs, fireAtCurrentTime, getCurrentTime, getTimeResolution, initialize, invalidateResolvedTypes, iterate, needWriteAccess, requestInitialization, setContainer, setTimeResolution, stop, stopFire, terminate, transferInputs, transferOutputs, wrapup
 
Methods inherited from class ptolemy.kernel.util.Attribute
_getContainedObject, _propagateExistence, clone, getContainer, setName
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _exportMoMLContents, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, attributeList, attributeList, attributeTypeChanged, 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, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setModelErrorHandler, setPersistent, setSource, toplevel, toString, uniqueName, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

runAheadLength

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


_Nroll

protected int _Nroll
The number of rollbacks. Used for statistics.

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(ptolemy.kernel.util.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(ptolemy.kernel.CompositeEntity container,
                             java.lang.String name)
                      throws ptolemy.kernel.util.IllegalActionException,
                             ptolemy.kernel.util.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:
ptolemy.kernel.util.IllegalActionException - If the director is not compatible with the specified container. May be thrown in a derived class.
ptolemy.kernel.util.NameDuplicationException - If the container is not a CompositeActor and the name collides with an entity in the container.
Method Detail

attributeChanged

public void attributeChanged(ptolemy.kernel.util.Attribute attribute)
                      throws ptolemy.kernel.util.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:
ptolemy.kernel.util.IllegalActionException - If 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 ptolemy.kernel.util.IllegalActionException
Execute the directed (sub)system to the iteration end time. If the current phase is an event phase, (in the sense that discrete events will be produced or consumed), this director will consume all the input tokens, produce all output tokens, and then request a zero delay refire from it executive director. If this is a top-level director, the iteration end time is the current time at the beginning of the fire() method plus the the step size of one accurate step. Otherwise, it executes until one of the following conditions is satisfied. 1) The iteration end time computed in the prefire() method is reached. 2) An event is generated. It saves the state of the system at the current time of the executive director as the "known good" state, and runs ahead of that time. The "known good" state is used for roll back.

Specified by:
fire in interface ptolemy.actor.Executable
Overrides:
fire in class CTMultiSolverDirector
Throws:
ptolemy.kernel.util.IllegalActionException - If thrown by the ODE solver, or the prefire() or the fire() methods of an actor.

getIterationEndTime

public final double getIterationEndTime()
Return the end time of this director's current iteration.

Returns:
The fire end time.

getOutsideTime

public double getOutsideTime()
Return the time of the outside domain. If this is the top level director return the current time.

Returns:
The outside current time.

initialize

public void initialize()
                throws ptolemy.kernel.util.IllegalActionException
First initialize the execution as in CTMultiSolverDirector. If this director is not at the top-level, also request to fire at the current time from the executive director.

Specified by:
initialize in interface ptolemy.actor.Executable
Overrides:
initialize in class CTMultiSolverDirector
Throws:
ptolemy.kernel.util.IllegalActionException - If this director has no container or no scheduler, or thrown by a contained actor.
See Also:
CTMultiSolverDirector.initialize()

postfire

public boolean postfire()
                 throws ptolemy.kernel.util.IllegalActionException
If this is a top-level director, behave exactly as a CTMultiSolverDirector, otherwise always return true.

Specified by:
postfire in interface ptolemy.actor.Executable
Overrides:
postfire in class CTMultiSolverDirector
Returns:
True if this is not a top-level director or the simulation is not finished.
Throws:
ptolemy.kernel.util.IllegalActionException - Not thrown in this base class.

prefire

public boolean prefire()
                throws ptolemy.kernel.util.IllegalActionException
Always returns true, indicating that the (sub)system is always ready for one iteration. The schedule is recomputed if there are mutations that occurred after last iteration. Note that mutations can only occur between iterations in the CT domain.

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) and catch up to the outside time.
If t < t0, then throw an exception because the CT subsystem should always run ahead of time.

The iteration end time is computed. If this is a top-level director, the iteration end time is the (local) current time plus the (local) current step size. If this director is not a top-level director, the time is resolved from the current time of the outside domains, say t1, the next iteration time of the outside domain, say t2, and the runAheadLength parameter of this director, say t3. The iteration end time is set to be t1 + min(t2, t3). The iteration end time may be further refined by the fire() method due to event detection. In particular, when the first event is detected, say at t4, then the iteration end time is set to t4.

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

_catchUp

protected void _catchUp()
                 throws ptolemy.kernel.util.IllegalActionException
Catch up the simulation from a known good state to the outside current time. There should be no breakpoints of any kind in this process. If the current time is greater than or equal to the outside time, then do nothing.

Throws:
ptolemy.kernel.util.IllegalActionException - If thrown from the execution methods from any 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

_isStoppedByEvent

protected boolean _isStoppedByEvent()
                             throws ptolemy.kernel.util.IllegalActionException
Return true if the current fire phase is stopped due to the occurrence of events (predictable or unpredictable).

Returns:
True if the current fire phase is stopped by an event.
Throws:
ptolemy.kernel.util.IllegalActionException - If thrown by the scheduler.

_isTopLevel

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

Returns:
True if this director is at the top-level.

_markStates

protected void _markStates()
                    throws ptolemy.kernel.util.IllegalActionException
Mark the current state as the known good state. Call the markStates() method on all CTStatefulActors. Save the current time as the "known good" time.

Throws:
ptolemy.kernel.util.IllegalActionException - If thrown by the scheduler.

_rollback

protected void _rollback()
                  throws ptolemy.kernel.util.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:
ptolemy.kernel.util.IllegalActionException - If thrown by the goToMarkedState() method of an actor.

_setIterationEndTime

protected void _setIterationEndTime(double time)
Set the end time for this iteration. If the argument is less than the current time, then an InvalidStateException will be thrown.

Parameters:
time - The fire end time.