ptolemy.domains.ct.kernel
Class HSModalDirector

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.util.Attribute
          extended by ptolemy.actor.Director
              extended by ptolemy.domains.fsm.kernel.FSMDirector
                  extended by ptolemy.domains.ct.kernel.HSModalDirector
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Executable, Initializable, QuasiTransparentDirector, ExplicitChangeContext, CTGeneralDirector, CTTransparentDirector, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

public class HSModalDirector
extends FSMDirector
implements CTTransparentDirector

An HSModalDirector governs the execution of the discrete dynamics of a hybrid system model.

Hierarchical Hybrid System Simulation describes how hybrid system models are built and simulated in Ptolemy II. A detailed discussion about the underlying semantics can be found at Operational Semantics of Hybrid Systems.

Since:
Ptolemy II 8.0
Version:
$Id: HSModalDirector.java 57044 2010-01-27 22:41:05Z cxh $
Author:
Xiaojun Liu, Haiyang Zheng
See Also:
Serialized Form
Accepted Rating:
Red (liuxj)
Proposed Rating:
Yellow (hyzheng)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
 
Field Summary
private  double _distanceToBoundary
          Local variable to indicate the distance to boundary.
private  double _lastDistanceToBoundary
          Local variable to indicate the last distance to boundary.
private  boolean _outputAccurate
          Local variable to indicate whether the output is accurate.
private  boolean _transitionHasEvent
           
 
Fields inherited from class ptolemy.domains.fsm.kernel.FSMDirector
_currentLocalReceiverMap, _enabledRefinements, _enabledTransition, _localReceiverMaps, controllerName
 
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
HSModalDirector()
          Construct a director in the default workspace with an empty string as its name.
HSModalDirector(CompositeEntity container, java.lang.String name)
          Construct a director in the given container with the given name.
HSModalDirector(Workspace workspace)
          Construct a director in the workspace with an empty name.
 
Method Summary
private  Transition _checkEvent(java.util.List transitionList)
           
 void emitCurrentStates()
          Iterate the enbled refinements to emit the current states of their dynamic actors.
 void fire()
          Set the values of input variables in the mode controller.
 double getCurrentStepSize()
          Ask for the current step size used by the solver from the executive CT director.
 double getErrorTolerance()
          Return error tolerance used for detecting enabled transitions.
 CTExecutionPhase getExecutionPhase()
          Get the current execution phase of this director.
 CTGeneralDirector getExecutiveCTGeneralDirector()
          Return the executive CT director of this director, or null if this director is at the top level or the executive director is not a CT general director.
 Time getIterationBeginTime()
          Return the begin time of the current iteration, this method only makes sense in continuous-time domain.
 Time getModelTime()
          Return the current time obtained from the executive director, if there is one, and otherwise return the local view of current time.
 java.lang.String getODESolverClassName()
          Get the ODE solver class name.
 ParseTreeEvaluator getParseTreeEvaluator()
          Return the parse tree evaluator used to evaluate guard expressions.
 void goToMarkedState()
          Restore the states of all the enabled refinements to the previously marked states.
 boolean hasCurrentEvent()
          Return true if the enabled refinements may produce events.
 void initialize()
          Call the initialize method of the supper class.
 boolean isDiscretePhase()
          Return true if this is the discrete phase execution.
 boolean isOutputAccurate()
          Retun true if all the output-step-size-control actors of the enabled refinements are satisfied with the current step size and there is no enabled transition detected.
 boolean isStateAccurate()
          Retun true if all the refinements can resolve their states with the current step size.
 void markState()
          Make the current states of all the enabled refinements.
 Receiver newReceiver()
          Return a CTReceiver.
 boolean postfire()
          Return true if the mode controller wishes to be scheduled for another iteration.
 double predictedStepSize()
          Return the smallest next step size predicted by the all the enabled refinements, which are refinements that returned true in their prefire() methods in this iteration.
 boolean prefire()
          Set the controller and current state.
 boolean prefireDynamicActors()
          Return true if all the dynamic actors contained by the enabled refinements return true from their prefire() method.
 double refinedStepSize()
          Return the step size refined by all the enabled refinements, which are refinements that returned true in their prefire() methods in this iteration, or the enabled transition which requires the current time be the same with the time it is enabled.
 
Methods inherited from class ptolemy.domains.fsm.kernel.FSMDirector
_buildLocalReceiverMaps, _checkTransition, _chooseTransition, _currentLocalReceivers, _getLastChosenTransition, _readInputs, _readOutputsFromRefinement, _setCurrentConnectionMap, _setCurrentState, attributeChanged, clone, defaultDependency, fireAt, getContext, getController, getModelNextIterationTime, getModifiedVariables, handleModelError, implementsStrictActorSemantics, isStrict, setContainer, setModelTime, transferInputs
 
Methods inherited from class ptolemy.actor.Director
_description, _fireContainerAt, _isEmbedded, _isTopLevel, _transferInputs, _transferOutputs, addInitializable, createSchedule, finish, fireAt, fireAtCurrentTime, getCausalityInterface, getCurrentTime, getGlobalTime, getModelStartTime, getModelStopTime, getNextIterationTime, getStartTime, getStopTime, getTimeResolution, initialize, invalidateResolvedTypes, invalidateSchedule, isFireFunctional, isStopRequested, iterate, preinitialize, preinitialize, removeInitializable, requestInitialization, setCurrentTime, stop, stopFire, suggestedModalModelDirectors, supportMultirateFiring, terminate, 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, addDebugListener, 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, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, propagateExistence, propagateValue, propagateValues, removeChangeListener, removeDebugListener, 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.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
 

Field Detail

_distanceToBoundary

private double _distanceToBoundary
Local variable to indicate the distance to boundary.


_lastDistanceToBoundary

private double _lastDistanceToBoundary
Local variable to indicate the last distance to boundary.


_outputAccurate

private boolean _outputAccurate
Local variable to indicate whether the output is accurate.


_transitionHasEvent

private boolean _transitionHasEvent
Constructor Detail

HSModalDirector

public HSModalDirector()
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.


HSModalDirector

public HSModalDirector(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.

Parameters:
container - Container of this director.
name - Name of this director.
Throws:
IllegalActionException - If the name has a period in it, or the director is not compatible with the specified container.
NameDuplicationException - If the container is not a CompositeActor and the name collides with an entity in the container.

HSModalDirector

public HSModalDirector(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.

Parameters:
workspace - The workspace of this director.
Method Detail

emitCurrentStates

public void emitCurrentStates()
                       throws IllegalActionException
Iterate the enbled refinements to emit the current states of their dynamic actors.

Specified by:
emitCurrentStates in interface CTTransparentDirector
Throws:
IllegalActionException - If the current states can not be emitted.

fire

public void fire()
          throws IllegalActionException
Set the values of input variables in the mode controller. Examine the preemptive outgoing transitions of its current state. Throw an exception if there is more than one transition enabled. If there is exactly one preemptive transition enabled then it is chosen and the choice actions contained by the transition are executed. The refinement of the current state of the mode controller will not be fired. If no preemptive transition is enabled and the refinement is ready to fire in the current iteration, fire the refinement. If this refinement has not been fired before, or needs initialization, establish the initial states of continuous variables. After this, the non-preemptive transitions from the current state of the mode controller are examined. If there is more than one transition enabled, an exception is thrown. If there is exactly one non-preemptive transition enabled then it is chosen and the choice actions contained by the transition are executed.

Specified by:
fire in interface Executable
Overrides:
fire in class FSMDirector
Throws:
IllegalActionException - If there is more than one transition enabled, or can not find the refinements associated with the current state or enabled transition, or can not read inputs or outputs from refinements.

getCurrentStepSize

public double getCurrentStepSize()
Ask for the current step size used by the solver from the executive CT director.

Specified by:
getCurrentStepSize in interface CTGeneralDirector
Returns:
The current step size.

getErrorTolerance

public final double getErrorTolerance()
Return error tolerance used for detecting enabled transitions.

Specified by:
getErrorTolerance in interface CTGeneralDirector
Overrides:
getErrorTolerance in class Director
Returns:
The error tolerance used for detecting enabled transitions.

getExecutiveCTGeneralDirector

public CTGeneralDirector getExecutiveCTGeneralDirector()
Return the executive CT director of this director, or null if this director is at the top level or the executive director is not a CT general director.

Specified by:
getExecutiveCTGeneralDirector in interface CTGeneralDirector
Returns:
The executive CT general director of this director, if there is any.

getExecutionPhase

public CTExecutionPhase getExecutionPhase()
Get the current execution phase of this director.

Specified by:
getExecutionPhase in interface CTGeneralDirector
Returns:
The current execution phase of this director.

getIterationBeginTime

public Time getIterationBeginTime()
Return the begin time of the current iteration, this method only makes sense in continuous-time domain.

Specified by:
getIterationBeginTime in interface CTGeneralDirector
Returns:
The begin time of the current iteration.

getModelTime

public Time getModelTime()
Return the current time obtained from the executive director, if there is one, and otherwise return the local view of current time.

Overrides:
getModelTime in class Director
Returns:
The current time.
See Also:
Director.setModelTime(Time)

getParseTreeEvaluator

public ParseTreeEvaluator getParseTreeEvaluator()
Return the parse tree evaluator used to evaluate guard expressions. In this class, an instance of ParseTreeEvaluatorForGuardExpression is returned. The parse tree evaluator is set to construction mode.

Overrides:
getParseTreeEvaluator in class FSMDirector
Returns:
ParseTreeEvaluator used to evaluate guard expressions.

goToMarkedState

public void goToMarkedState()
                     throws IllegalActionException
Restore the states of all the enabled refinements to the previously marked states.

Specified by:
goToMarkedState in interface CTTransparentDirector
Throws:
IllegalActionException - If there is no marked state.

getODESolverClassName

public java.lang.String getODESolverClassName()
Get the ODE solver class name.

Specified by:
getODESolverClassName in interface CTGeneralDirector
Returns:
the name of the ODE solver class.

hasCurrentEvent

public boolean hasCurrentEvent()
Return true if the enabled refinements may produce events.

Specified by:
hasCurrentEvent in interface CTTransparentDirector
Returns:
True if the enabled refinements may produce events.

initialize

public void initialize()
                throws IllegalActionException
Call the initialize method of the supper class. Get the controller and the current state. Get a set of the refinements associated with this state.

Specified by:
initialize in interface Initializable
Overrides:
initialize in class FSMDirector
Throws:
IllegalActionException - If the enabled refinements or the super class throws it.

isDiscretePhase

public boolean isDiscretePhase()
Return true if this is the discrete phase execution.

Specified by:
isDiscretePhase in interface CTGeneralDirector
Returns:
True if this is the discrete phase execution.

isOutputAccurate

public boolean isOutputAccurate()
Retun true if all the output-step-size-control actors of the enabled refinements are satisfied with the current step size and there is no enabled transition detected.

Specified by:
isOutputAccurate in interface CTTransparentDirector
Returns:
True if all the refinements are satisfied with the current step size and there is no enabled transition detected.

isStateAccurate

public boolean isStateAccurate()
Retun true if all the refinements can resolve their states with the current step size.

Specified by:
isStateAccurate in interface CTTransparentDirector
Returns:
True if all the refinements can resolve their states with the current step size.

markState

public void markState()
Make the current states of all the enabled refinements.

Specified by:
markState in interface CTTransparentDirector

newReceiver

public Receiver newReceiver()
Return a CTReceiver. By default, the signal type is discrete.

Overrides:
newReceiver in class FSMDirector
Returns:
a new CTReceiver with signal type as discrete.

postfire

public boolean postfire()
                 throws IllegalActionException
Return true if the mode controller wishes to be scheduled for another iteration. Postfire the enabled refinements of the current state of the mode controller and take out event outputs that the refinements generate. Execute the commit actions contained by the last chosen transition of the mode controller and set its current state to the destination state of the transition. Clear the relation list associated with the enabled transition and request to be fired again at the current time.

Specified by:
postfire in interface Executable
Overrides:
postfire in class FSMDirector
Returns:
True if the mode controller wishes to be scheduled for another iteration.
Throws:
IllegalActionException - If thrown by any action, or there is no controller, or if the director does not agree to fire the actor at the specified time.

predictedStepSize

public double predictedStepSize()
Return the smallest next step size predicted by the all the enabled refinements, which are refinements that returned true in their prefire() methods in this iteration. If there are no refinements, then return Double.MAX_VALUE. If a refinement is not a CTStepSizeControlActor, then its prediction is Double.MAX_VALUE.

Specified by:
predictedStepSize in interface CTTransparentDirector
Returns:
The predicted next step size.

prefire

public boolean prefire()
                throws IllegalActionException
Set the controller and current state. Call super.prefire().

Specified by:
prefire in interface Executable
Overrides:
prefire in class FSMDirector
Returns:
True if the prefire() method of the super class returns true.
Throws:
IllegalActionException - If the controller does not exit, or can not find the specified refinements associated with the current state, or the prefire() method of refinements throw it, or the super class throws it.

prefireDynamicActors

public boolean prefireDynamicActors()
                             throws IllegalActionException
Return true if all the dynamic actors contained by the enabled refinements return true from their prefire() method.

Specified by:
prefireDynamicActors in interface CTTransparentDirector
Returns:
True if all dynamic actors of enabled refinements can be prefired.
Throws:
IllegalActionException - If the local directors of refinements throw it.

refinedStepSize

public double refinedStepSize()
Return the step size refined by all the enabled refinements, which are refinements that returned true in their prefire() methods in this iteration, or the enabled transition which requires the current time be the same with the time it is enabled. If there are no refinements, or no refinement is a CTStepSizeControlActor, then the refined step size is the smaller value between current step size of the executive director and refined step size from enabled transition.

Specified by:
refinedStepSize in interface CTTransparentDirector
Returns:
The refined step size.

_checkEvent

private Transition _checkEvent(java.util.List transitionList)