|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectptolemy.kernel.util.NamedObj
ptolemy.kernel.util.Attribute
ptolemy.actor.Director
ptolemy.actor.sched.StaticSchedulingDirector
ptolemy.actor.sched.FixedPointDirector
ptolemy.domains.continuous.kernel.ContinuousDirector
public class ContinuousDirector
The continuous time domain is a timed domain that supports continuous-time signals, discrete-event signals, and mixtures of the two. There is a global notion of time that all the actors are aware of. The semantics of this domain is given in the following two papers:
A signal is a set of "events," each of which has a tag and value. The set of values includes a special element, called "absent", denoting the absence of a (normal) value. This director uses superdense time, where every event has a tag that is a member of the set RxN. R is a connected subset of the real numbers (giving "time", and approximated by instances of the Time class), and N is the natural numbers (giving an "index"). At a time t, a signal may have multiple values in sequence with tags (t, 0), (t, 1)... Its "initial value" is the value at tag (t, 0). It typically settles to a "final value" after a finite number of indices. If it fails to settle to a final value, the signal is said to have a "stuttering Zeno" condition, and time will not progress.
In our semantics, all signals are piecewise continuous. This means that the initial value, as a function of time, is continuous on the left, the final value, as a function of time, is continuous on the right, and the signal has exactly one value (meaning the initial value and the final value are the same) at all times except those on a discrete subset D.
A purely continuous signal has exactly one value at all times, meaning that the final value equals the initial value at all times. A purely discrete signal has initial value "absent" and final value "absent" at all times, and at a discrete subset of the times, it may have non-absent values. The only signal that is both purely continuous and purely discrete is the one that is absent at all tags.
A signal may be mostly continuous, but have multiple values at a discrete subset of times. These multiple values semantically represent discontinuities in a continuous signal that is not purely continuous.
The set of times where signals have more than one distinct value is a discrete subset D of the time line. These times are called "breakpoints" and are treated specially in the execution. Between these times, an ordinary differential equation (ODE) solver governs the execution. Initial values are always given by the ODE solver.
The parameters of this director are:
This director maintains a breakpoint table to record all predictable breakpoints that are greater than or equal to the current time. The breakpoints are sorted in chronological order. Breakpoints at the same time are considered to be identical, and the breakpoint table does not contain duplicate time points. A breakpoint can be inserted into the table by calling the fireAt() method. The fireAt method may be requested by the director, which inserts the stop time of the execution. The fireAt method may also be requested by actors and the requested firing time will be inserted into the breakpoint table.
This director is designed to work with any other director that implements the strict actor semantics. As long as the other director does not commit state changes except in postfire(), that director can be used within the model controlled by this director. If, in addition to implementing the strict actor semantics that other director also respects calls to fireAt(), then this director may be used within a model governed by that director.
This director is based on the CTDirector by Jie Liu and Haiyang Zheng, but it has a much simpler scheduler and a fixed-point semantics.
Red (hyzheng) |
Yellow (hyzheng) |
Nested Class Summary |
---|
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj |
---|
NamedObj.ContainedObjectsIterator |
Field Summary | |
---|---|
private Time |
_accumulatedSuspendTime
The accumulated suspend time relative to an eclosing ContinuousDirector, calculated as a side effect of calling _enclosingContinuousDirector(). |
private TotallyOrderedSet |
_breakpoints
A table for breakpoints. |
private boolean |
_commitIsPending
Flag indicating that postfire() did not commit the state at the local current time. |
private double |
_currentStepSize
Simulation step sizes. |
private ContinuousDirector |
_enclosingContinuousDirector
The enclosing continuous director. |
private long |
_enclosingContinuousDirectorVersion
The version for __enclosingContinuousDirector. |
private double |
_errorTolerance
The error tolerance for state resolution. |
private boolean |
_ignoreSetTime
Flag to temporarily ignore the setModelTime() calls. |
private double |
_initStepSize
A cache of the value of initStepSize. |
protected boolean |
_isInitializing
A local boolean variable indicating whether this director is in initialization phase execution. |
private boolean |
_isIntermediateStep
Flag indicating that the solver is iterating through the first or intermediate steps in a multi-step solver. |
private int |
_iterationBeginIndex
The index of the time at which the current integration step began. |
protected Time |
_iterationBeginTime
The current time at the start of the current integration step. |
private Time |
_lastSuspendTime
The environment time when this refinement was last suspended (that is, the enclosing state was exited). |
private int |
_maxIterations
The maximum iterations for implicit ODE solver to resolve states. |
private double |
_maxStepSize
The maximum step size used for integration. |
private ContinuousODESolver |
_ODESolver
The ODE solver, which is an instance of the class given by the ODESolver parameter. |
private boolean |
_redoingSolverIteration
Flag indicating that we are redoing a speculative solver iteration. |
private static java.lang.String |
_solverClasspath
The package name for the solvers supported by this director. |
private Time |
_startTime
The cached value of the startTime parameter. |
private java.util.List |
_statefulComponents
The list of stateful actors. |
private long |
_statefulComponentsVersion
The version for the list of step size control actors. |
private java.util.List |
_stepSizeControllers
The list of step size control actors. |
private long |
_stepSizeControllersVersion
The version for the list of step size control actors. |
private Time |
_stopTime
The cached value of the stopTime parameter. |
protected long |
_timeBase
The real starting time in term of system millisecond counts. |
private boolean |
_triedTheMinimumStepSize
The local flag variable indicating whether the we have tried the time resolution as the integration step size. |
private Time |
_zeroTime
Time with value 0.0. |
Parameter |
errorTolerance
Error tolerance for data values, used with variable step size solvers to determine whether the current step size is accurate. |
Parameter |
initStepSize
User's hint for the initial integration step size. |
Parameter |
maxIterations
The maximum number of rounds that an ODE solver can use to resolve the states of integrators. |
Parameter |
maxStepSize
The maximum step size. |
StringParameter |
ODESolver
The class name of the ODE solver used for integration. |
Parameter |
startTime
Starting time of the execution. |
Parameter |
stopTime
Stop time of the simulation. |
Fields inherited from class ptolemy.actor.sched.FixedPointDirector |
---|
_index, _receivers, iterations, synchronizeToRealTime |
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 | |
---|---|
ContinuousDirector(CompositeEntity container,
java.lang.String name)
Construct a director in the given container with the given name. |
Method Summary | |
---|---|
private void |
_assertAbsentInside()
Set all receivers on the inside of input ports to absent. |
private boolean |
_commit()
Commit the current state by postfiring the actors under the control of this director. |
private ContinuousDirector |
_enclosingContinuousDirector()
Return the enclosing continuous director, or null if there is none. |
protected double |
_getCurrentStepSize()
Return the current step size. |
protected ContinuousODESolver |
_getODESolver()
Return the ODE solver used to resolve states by the director. |
private void |
_handleBreakpointsBefore(Time time,
int index)
Throw an exception if there are any breakpoints in the breakpoint table before the specified time. |
private void |
_initializeLocalVariables()
Initialize the local variables of this ContinuousDirector. |
protected void |
_initParameters()
Create and initialize all parameters to their default values. |
protected ContinuousODESolver |
_instantiateODESolver(java.lang.String className)
Instantiate an ODESolver from its classname. |
protected boolean |
_isDebugging()
Return true if debugging is turned on. |
protected boolean |
_isIntermediateStep()
Return true if the solver is at the first or intermediate steps of a multi-step solver. |
private boolean |
_postfireAtTopLevel()
Postfire method when this director is at the top level. |
private boolean |
_postfireWithEnclosingContinuousDirector()
Postfire method when the enclosing director is an instance of this same class. |
private boolean |
_postfireWithEnclosingNonContinuousDirector()
Postfire method when the enclosing director is not an instance of this same class. |
private boolean |
_prefireAtTopLevel()
Prefire method when this director is at the top level. |
private boolean |
_prefireWithEnclosingContinuousDirector()
Prefire method when the enclosing director is an instance of this same class. |
private boolean |
_prefireWithEnclosingNonContinuousDirector()
Prefire method when the enclosing director is not an instance of this same class. |
protected void |
_reportDebugMessage(java.lang.String message)
Expose the debug method to the package. |
private void |
_setCurrentStepSize(double stepSize)
Set the current step size. |
private java.util.List |
_statefulComponents()
Return a list of stateful components, which includes actors deeply contained within the container of this director that implement the ContinuousStatefulComponent interface and directors of opaque composite actors within the container of this director that implement the same interface. |
private java.util.List |
_stepSizeControllers()
Return a list of step-size controllers. |
private boolean |
_transferInputsToInside()
Transfer inputs from the environment to inside. |
private void |
_transferOutputsToEnvironment()
Transfer outputs to the environment. |
Time |
accumulatedSuspendTime()
Return the accumulated time that the actor has been suspended since the last call to initialize(), or null if it has never been suspended. |
void |
attributeChanged(Attribute attribute)
React to a change in an attribute. |
java.lang.Object |
clone(Workspace workspace)
Clone the object into the specified workspace. |
Dependency |
delayDependency(double delay)
Return a boolean dependency representing a model-time delay of the specified amount. |
void |
fire()
Perform an integration step. |
Time |
fireAt(Actor actor,
Time time)
Handle firing requests from the contained actors by registering breakpoints. |
double |
getCurrentStepSize()
Return the current integration step size. |
double |
getErrorTolerance()
Return the local truncation error tolerance. |
Time |
getModelNextIterationTime()
Return the next time of interest in the model being executed by this director or the director of any enclosing model up the hierarchy. |
Time |
getModelStartTime()
Return the start time. |
Time |
getModelStopTime()
Return the stop time, which is the value of the stopTime parameter, represented as an instance of the Time class. |
void |
initialize()
Initialize model after type resolution. |
boolean |
isStepSizeAccurate()
Return true if all step size control actors agree that the current step is accurate and if there are no breakpoints in the past. |
boolean |
postfire()
If this director is not at the top level and the breakpoint table is not empty, request a refiring at the first breakpoint or at the local current time (iteration start time plus the step size), whichever is less. |
boolean |
prefire()
Initialize the fixed-point iteration by setting all receivers to unknown, and return true if we have not passed the stop time. |
void |
preinitialize()
Preinitialize the model for an execution. |
double |
refinedStepSize()
Return the refined step size, which is the minimum of the current step size and the suggested step size of all actors that implement ContinuousStepSizeController and that also ensures that we do not pass a breakpoint. |
void |
resume(Time time)
Resume the actor at the specified time. |
void |
rollBackToCommittedState()
Roll back all actors that implement ContinuousStatefulComponent to committed state, and set local model time to the start of the integration period. |
void |
setModelTime(Time newTime)
Set a new value to the current time of the model. |
java.lang.String[] |
suggestedModalModelDirectors()
Return an array of suggested ModalModel directors to use with ContinuousDirector. |
double |
suggestedStepSize()
Return the suggested step size for next integration. |
void |
suspend(Time time)
Resume the actor at the specified time. |
boolean |
transferInputs(IOPort port)
Override the base class to do nothing. |
boolean |
transferOutputs(IOPort port)
Override the base class to do nothing. |
Methods inherited from class ptolemy.actor.sched.FixedPointDirector |
---|
_receiverChanged, _resetAllReceivers, _synchronizeToRealTime, getIndex, implementsStrictActorSemantics, isFireFunctional, isStrict, newReceiver, setIndex |
Methods inherited from class ptolemy.actor.sched.StaticSchedulingDirector |
---|
_setScheduler, addDebugListener, getScheduler, invalidateSchedule, isScheduleValid, removeDebugListener, setScheduler |
Methods inherited from class ptolemy.kernel.util.Attribute |
---|
_checkContainer, _getContainedObject, _propagateExistence, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setName, updateContent |
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 |
Methods inherited from interface ptolemy.actor.Executable |
---|
isFireFunctional, isStrict, iterate, stop, stopFire, terminate |
Methods inherited from interface ptolemy.actor.Initializable |
---|
addInitializable, removeInitializable, wrapup |
Field Detail |
---|
public Parameter errorTolerance
public Parameter initStepSize
public Parameter maxIterations
public Parameter maxStepSize
public StringParameter ODESolver
public Parameter startTime
public Parameter stopTime
protected boolean _isInitializing
protected Time _iterationBeginTime
protected long _timeBase
private Time _accumulatedSuspendTime
private TotallyOrderedSet _breakpoints
private boolean _commitIsPending
private double _currentStepSize
private ContinuousDirector _enclosingContinuousDirector
private long _enclosingContinuousDirectorVersion
private double _errorTolerance
private boolean _ignoreSetTime
private double _initStepSize
private boolean _isIntermediateStep
private int _iterationBeginIndex
private Time _lastSuspendTime
private int _maxIterations
private double _maxStepSize
private ContinuousODESolver _ODESolver
private boolean _redoingSolverIteration
private static java.lang.String _solverClasspath
private Time _startTime
private java.util.List _statefulComponents
private long _statefulComponentsVersion
private java.util.List _stepSizeControllers
private long _stepSizeControllersVersion
private Time _stopTime
private boolean _triedTheMinimumStepSize
private Time _zeroTime
Constructor Detail |
---|
public ContinuousDirector(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
container
- The container.name
- Name of this director.
IllegalActionException
- If the director is not compatible
with the specified container. May be thrown by a derived class.
NameDuplicationException
- If the name collides with
a property in the container.Method Detail |
---|
public Time accumulatedSuspendTime()
accumulatedSuspendTime
in interface Suspendable
public void attributeChanged(Attribute attribute) throws IllegalActionException
attributeChanged
in class Director
attribute
- The changed parameter.
IllegalActionException
- If the new parameter value
is not valid.public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
clone
in class FixedPointDirector
workspace
- The workspace for the cloned object.
java.lang.CloneNotSupportedException
- Not thrown in this base classNamedObj.exportMoML(Writer, int, String)
,
NamedObj.setDeferringChangeRequests(boolean)
public Dependency delayDependency(double delay)
delayDependency
in interface TimedDirector
delay
- A non-negative delay.
public void fire() throws IllegalActionException
If there is an enclosing ContinuousDirector, however, then this method simply performs the current round of execution of the enclosing director, using the step size of the enclosing director.
fire
in interface Executable
fire
in class FixedPointDirector
IllegalActionException
- If an actor throws it.public Time fireAt(Actor actor, Time time) throws IllegalActionException
fireAt
in class Director
actor
- The actor that requests the firing.time
- The requested firing time.
IllegalActionException
- If the time is earlier than
the current time.Director.fireAtCurrentTime(Actor)
public final double getCurrentStepSize()
public final double getErrorTolerance()
getErrorTolerance
in class Director
public Time getModelNextIterationTime()
This method is useful for domains that perform speculative execution (such as Continuous itself). Such a domain in a hierarchical model (i.e. CT inside DE) uses this method to determine how far into the future to execute. This is simply an optimization that reduces the likelihood of having to roll back.
The base class implementation in Director is almost right, but not quite, because at the top level it returns current time. However, this director should not constrain any director below it from speculatively executing into the future. Instead, it assumes that any director below it implements a strict actor semantics. Note in particular that the implementation below would block time advancement in a Continuous in DE in Continuous model because the top-level model will usually only invoke the DE model during a zero-step execution, which means that the returned next iteration time will always be current time, which will force the inside Continuous director to have a zero step size always.
getModelNextIterationTime
in class Director
Director.getModelTime()
public final Time getModelStartTime() throws IllegalActionException
getModelStartTime
in class Director
IllegalActionException
- If the enclosing director throws it.public final Time getModelStopTime()
getModelStopTime
in class Director
public void initialize() throws IllegalActionException
initialize
in interface Initializable
initialize
in class FixedPointDirector
IllegalActionException
- If the super class throws it.public boolean isStepSizeAccurate()
isStepSizeAccurate
in interface ContinuousStepSizeController
public boolean postfire() throws IllegalActionException
If the synchronizeToRealTime parameter is true, then this method will block execution until the real time catches up with current model time. The units for time are seconds.
postfire
in interface Executable
postfire
in class FixedPointDirector
IllegalActionException
- If the current model time exceeds
the stop time, or refiring can not be granted, or the super class throws it.public boolean prefire() throws IllegalActionException
prefire
in interface Executable
prefire
in class FixedPointDirector
IllegalActionException
- If thrown by the super class,
or if the model time of the environment is less than our current
model time.public void preinitialize() throws IllegalActionException
preinitialize
in interface Initializable
preinitialize
in class Director
IllegalActionException
- If the super class throws it, or
local variables cannot be initialized.public double refinedStepSize() throws IllegalActionException
refinedStepSize
in interface ContinuousStepSizeController
IllegalActionException
- If the scheduler throws it or the
refined step size is less than the time resolution.public void resume(Time time) throws IllegalActionException
resume
in interface Suspendable
time
- The time at which the actor is resumed.
IllegalActionException
- If the fireAt() request throws it.public void rollBackToCommittedState()
rollBackToCommittedState
in interface ContinuousStatefulComponent
public final void setModelTime(Time newTime) throws IllegalActionException
setModelTime
in class Director
newTime
- The new current simulation time.
IllegalActionException
- If the time is in the past
relative to the time of local committed state.Director.getModelTime()
public java.lang.String[] suggestedModalModelDirectors()
suggestedModalModelDirectors
in class FixedPointDirector
Director.suggestedModalModelDirectors()
public double suggestedStepSize() throws IllegalActionException
suggestedStepSize
in interface ContinuousStepSizeController
IllegalActionException
- If an actor suggests an illegal step size.public void suspend(Time time) throws IllegalActionException
suspend
in interface Suspendable
time
- The time at which the actor is suspended.
IllegalActionException
- If the suspend cannot be completed.public boolean transferInputs(IOPort port) throws IllegalActionException
transferInputs
in class FixedPointDirector
port
- The port to transfer tokens from.
IllegalActionException
- Not thrown in this base class.public boolean transferOutputs(IOPort port) throws IllegalActionException
transferOutputs
in class FixedPointDirector
port
- The port to transfer tokens from.
IllegalActionException
- Not thrown in this base class.protected double _getCurrentStepSize()
protected final ContinuousODESolver _getODESolver()
protected void _initParameters()
protected final ContinuousODESolver _instantiateODESolver(java.lang.String className) throws IllegalActionException
className
- The solver's full class name.
IllegalActionException
- If the solver can not be created.protected final boolean _isDebugging()
protected boolean _isIntermediateStep() throws IllegalActionException
IllegalActionException
- If the Time class throws it.protected void _reportDebugMessage(java.lang.String message)
message
- The message that is to be reported.private void _assertAbsentInside() throws IllegalActionException
IllegalActionException
- If the send fails.private boolean _commit() throws IllegalActionException
IllegalActionException
private ContinuousDirector _enclosingContinuousDirector()
private void _handleBreakpointsBefore(Time time, int index) throws IllegalActionException
time
- The time.index
- The superdense time index.
IllegalActionException
- If there are any breakpoints in the
breakpoint table earlier than the specified time.private void _initializeLocalVariables() throws IllegalActionException
IllegalActionException
private boolean _postfireAtTopLevel() throws IllegalActionException
IllegalActionException
private boolean _postfireWithEnclosingContinuousDirector() throws IllegalActionException
IllegalActionException
private boolean _postfireWithEnclosingNonContinuousDirector() throws IllegalActionException
IllegalActionException
private boolean _prefireAtTopLevel() throws IllegalActionException
IllegalActionException
private boolean _prefireWithEnclosingContinuousDirector() throws IllegalActionException
IllegalActionException
private boolean _prefireWithEnclosingNonContinuousDirector() throws IllegalActionException
IllegalActionException
private void _setCurrentStepSize(double stepSize)
stepSize
- The step size to be set._currentStepSize
private java.util.List _statefulComponents()
private java.util.List _stepSizeControllers()
private boolean _transferInputsToInside() throws IllegalActionException
IllegalActionException
- If the transferInputs(Port)
method throws it.private void _transferOutputsToEnvironment() throws IllegalActionException
IllegalActionException
- If the transferOutputs(Port)
method throws it.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |