Class TimeDelay
- java.lang.Object
-
- All Implemented Interfaces:
java.lang.Cloneable
,Actor
,Executable
,FiringsRecordable
,Initializable
,TypedActor
,Changeable
,Debuggable
,DebugListener
,Derivable
,Instantiable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
- Direct Known Subclasses:
BoundedBufferTimedDelay
public class TimeDelay extends Transformer
This actor delays the input by a specified amount of time given by the delay port or parameter, which defaults to 1.0. It is designed to be used in timed domains, particularly DE. It can also be used in other domains, such as SR and SDF, but this will only be useful if the delay value is a multiple of the period of those directors. The value of delay is required to be nonnegative. In addition, if the delay port is connected (and hence the delay will be variable at run time), then the values provided at the port are required to be greater than or equal minimumDelay, which defaults to the initial value of delay. If the delay is to be changed dynamically during execution, consider setting minimumDelay to 0.0. The input and output types are unconstrained, except that the output type must be the same as that of the input.Note that in Ptides the SuperdenseDependency is used for computing offsets and deadlines. The dependency between the input and the output of this actor is the minimumDelay. A minimumDelay of values greater than 0.0 allows for more efficient execution of Ptides models. If this actor is used as a fixed delay actor, i.e. the delay value is not changed during the execution, the minimumDelay should be set to the actual delay, which is the default.
For directors that implement
SuperdenseTimeDirector
, such as DE, the output microstep of an event will match the input microstep, unless the time delay is 0.0, in which case, the output microstep will be one greater than the input microstep. A time delay of 0.0 is sometimes useful to break causality loops in feedback systems. It is sometimes useful to think of this zero-valued delay as an infinitesimal delay.This actor keeps a local FIFO queue to store all received but not produced inputs. The behavior of this actor on each firing is to output any previously received token that is scheduled to be produced at the current time (and microstep). If there is no previously received token scheduled to be produced, then the output will be absent.
Inputs are read only during the postfire() method. If an input is present, then this actor schedules itself to fire again to produce the just received token on the corresponding output channel after the appropriate time delay. Note that if the value of delay is 0.0, the actor schedules itself to fire at the current model time, resulting in an output with an incremented microstep.
This actor can also be used in the Continuous domain, but it is only useful to delay purely discrete signals. As a consequence, for directors that implement
SuperdenseTimeDirector
, this actor insists that input events have microstep 1 or greater. It will throw an exception if it receives an input with microstep 0, which in the Continuous domain, implies a continuous signal. There are two reasons for rejecting continuous inputs. First, because of the way variable-step-size ODE solvers work, the TimeDelay actor has the side effect of forcing the solver to use very small step sizes, which slows down a simulation. Second, and more important, some odd artifacts will appear if a variable step-size solver is being used. In particular, the output will be absent on any firing where there was no input at exactly time t - d, where t is the time of the firing and d is the value of the delay parameter. Thus, a continuous signal input will have gaps on the output, and will fail to be bR piecewise continuous.- Since:
- Ptolemy II 8.0
- Version:
- $Id$
- Author:
- Edward A. Lee
- Pt.AcceptedRating:
- Red (eal)
- Pt.ProposedRating:
- Yellow (eal)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TimeDelay.PendingEvent
Data structure to store pending events.-
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description protected double
_delay
The amount of delay.protected double
_minimumDelay
The amount of minimumDelay.protected java.util.LinkedList<TimeDelay.PendingEvent>
_pendingOutputs
A local queue to store the delayed output tokens.PortParameter
delay
The amount of delay.Parameter
minimumDelay
Minimum delay to impose if the delay port is connected.-
Fields inherited from class ptolemy.actor.lib.Transformer
input, output
-
Fields inherited from class ptolemy.actor.TypedAtomicActor
_typesValid
-
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _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
Constructors Constructor Description TimeDelay(CompositeEntity container, java.lang.String name)
Construct an actor with the specified container and name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
_addEvent(TimeDelay.PendingEvent newEvent)
Insert a new event into the queue of pending events.protected boolean
_isTime()
Return true if it is time to produce an output.void
attributeChanged(Attribute attribute)
If the attribute is delay, then ensure that the value is non-negative.java.lang.Object
clone(Workspace workspace)
Clone the actor into the specified workspace.void
declareDelayDependency()
Declare that the output does not depend on the input in a firing.void
fire()
Send out a token that is scheduled to be produced at the current time, if any.void
initialize()
Initialize the states of this actor.boolean
isStrict()
Return false indicating that this actor can be fired even if the inputs are unknown.boolean
postfire()
Read the input, if there is one, and request refiring.-
Methods inherited from class ptolemy.actor.TypedAtomicActor
_containedTypeConstraints, _customTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints
-
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, _declareDelayDependency, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, iterate, newReceiver, outputPortList, prefire, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate, wrapup
-
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
-
Methods inherited from class ptolemy.kernel.Entity
_addPort, _description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
-
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
-
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
-
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
-
Methods inherited from interface ptolemy.actor.Executable
isFireFunctional, iterate, prefire, stop, stopFire, terminate
-
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, preinitialize, removeInitializable, wrapup
-
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
-
-
-
-
Field Detail
-
delay
public PortParameter delay
The amount of delay. The default for this parameter is 1.0. This parameter must contain a DoubleToken with a non-negative value, or an exception will be thrown when it is set.
-
minimumDelay
public Parameter minimumDelay
Minimum delay to impose if the delay port is connected. This is a double that defaults to the value of the delay.
-
_delay
protected double _delay
The amount of delay.
-
_minimumDelay
protected double _minimumDelay
The amount of minimumDelay.
-
_pendingOutputs
protected java.util.LinkedList<TimeDelay.PendingEvent> _pendingOutputs
A local queue to store the delayed output tokens.
-
-
Constructor Detail
-
TimeDelay
public TimeDelay(CompositeEntity container, java.lang.String name) throws NameDuplicationException, IllegalActionException
Construct an actor with the specified container and name. Constrain that the output type to be the same as the input type.- Parameters:
container
- The composite entity to contain this one.name
- The name of this actor.- Throws:
IllegalActionException
- If the entity cannot be contained by the proposed container.NameDuplicationException
- If the container already has an actor with this name.
-
-
Method Detail
-
attributeChanged
public void attributeChanged(Attribute attribute) throws IllegalActionException
If the attribute is delay, then ensure that the value is non-negative.NOTE: the newDelay may be 0.0, which may change the causality property of the model. We leave the model designers to decide whether the zero delay is really what they want.
- Overrides:
attributeChanged
in classNamedObj
- Parameters:
attribute
- The attribute that changed.- Throws:
IllegalActionException
- If the delay is negative.
-
clone
public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
Clone the actor into the specified workspace. Set a type constraint that the output type is the same as the that of input.- Overrides:
clone
in classTypedAtomicActor
- Parameters:
workspace
- The workspace for the new object.- Returns:
- A new actor.
- Throws:
java.lang.CloneNotSupportedException
- If a derived class has has an attribute that cannot be cloned.- See Also:
NamedObj.exportMoML(Writer, int, String)
,NamedObj.setDeferringChangeRequests(boolean)
-
declareDelayDependency
public void declareDelayDependency() throws IllegalActionException
Declare that the output does not depend on the input in a firing.- Overrides:
declareDelayDependency
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- If the causality interface cannot be computed.- See Also:
AtomicActor.getCausalityInterface()
-
fire
public void fire() throws IllegalActionException
Send out a token that is scheduled to be produced at the current time, if any.- Specified by:
fire
in interfaceExecutable
- Overrides:
fire
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- If there is no director, or the input can not be read, or the output can not be sent.
-
initialize
public void initialize() throws IllegalActionException
Initialize the states of this actor.- Specified by:
initialize
in interfaceInitializable
- Overrides:
initialize
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- If a derived class throws it.
-
isStrict
public boolean isStrict()
Return false indicating that this actor can be fired even if the inputs are unknown.- Specified by:
isStrict
in interfaceExecutable
- Overrides:
isStrict
in classAtomicActor<TypedIOPort>
- Returns:
- False.
-
postfire
public boolean postfire() throws IllegalActionException
Read the input, if there is one, and request refiring.- Specified by:
postfire
in interfaceExecutable
- Overrides:
postfire
in classAtomicActor<TypedIOPort>
- Returns:
- True if execution can continue into the next iteration.
- Throws:
IllegalActionException
- If scheduling to refire cannot be performed or the superclass throws it.
-
_addEvent
protected void _addEvent(TimeDelay.PendingEvent newEvent)
Insert a new event into the queue of pending events. This method ensures that events in the queue are in time-stamp and microstep order, and that when time stamps and microsteps match, that the order is FIFO. The latest time stamp and largest microstep are at the beginning of the list.- Parameters:
newEvent
- The new event to be inserted into the queue of pending events.
-
_isTime
protected boolean _isTime() throws IllegalActionException
Return true if it is time to produce an output.- Returns:
- Return true if it is time to produce an output.
- Throws:
IllegalActionException
- If current time exceeds the time of of the next pending event.
-
-