ptolemy.domains.ct.lib
Class ThresholdMonitor

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.InstantiableNamedObj
          extended by ptolemy.kernel.Entity
              extended by ptolemy.kernel.ComponentEntity
                  extended by ptolemy.actor.AtomicActor
                      extended by ptolemy.actor.TypedAtomicActor
                          extended by ptolemy.domains.ct.lib.ThresholdMonitor
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, TypedActor, CTStepSizeControlActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

public class ThresholdMonitor
extends TypedAtomicActor
implements CTStepSizeControlActor

Output true if the input value is in the interval [a, b], which is centered at thresholdCenter and has width thresholdWidth. This actor controls the integration step size so that the input does not cross the threshold without producing at least one true output. The output can be used as a pure event to trigger other events or state transitions. When the input crosses the interval in one step, this actor will report that the integration step is not accurate and refines the new step size by bisecting the old step size.

Since:
Ptolemy II 0.4
Version:
$Id: ThresholdMonitor.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Jie Liu
See Also:
Serialized Form
Accepted Rating:
Red (cxh)
Proposed Rating:
Red (liuj)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
 
Field Summary
private  boolean _accurate
           
private  boolean _first
           
private  double _lastInput
           
private  double _lowerBound
           
private  double _thCenter
           
private  double _thisInput
           
private  double _thWidth
           
private  double _upperBound
           
 TypedIOPort input
          The input port, single port with type double.
 TypedIOPort output
          The output port, single port with type boolean.
 Parameter thresholdCenter
          The parameter for the center of the threshold.
 Parameter thresholdWidth
          The parameter for the width of the threshold.
 
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
 
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
ThresholdMonitor(CompositeEntity container, java.lang.String name)
          Construct an actor in the specified container with the specified name.
 
Method Summary
 void attributeChanged(Attribute attribute)
          Update local caches if the attributes have been changed.
 void fire()
          Consume the current input.
 void initialize()
          Initialize the execution.
 boolean isOutputAccurate()
          Implementations of this method should return true if this actor declares the current integration step is accurate w.r.t. its output values.
 boolean isStateAccurate()
          Implementations of this method should return true if this actor declares the current integration step is accurate w.r.t. its current states.
 boolean postfire()
          Make this input to be the history input and return true.
 double predictedStepSize()
          Return java.lang.Double.MAX_VALUE, since this actor does not predict step sizes.
 double refinedStepSize()
          Return half the current step size if the step crosses the threshold.
 
Methods inherited from class ptolemy.actor.TypedAtomicActor
_addPort, _fireAt, _fireAt, attributeTypeChanged, clone, newPort, typeConstraintList, typeConstraints
 
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, addActorFiringListener, addInitializable, clone, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, 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
_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, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeList, attributeList, 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, propagateValue, propagateValues, removeChangeListener, removeDebugListener, 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.actor.Executable
isFireFunctional, isStrict, 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
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 

Field Detail

input

public TypedIOPort input
The input port, single port with type double.


output

public TypedIOPort output
The output port, single port with type boolean.


thresholdWidth

public Parameter thresholdWidth
The parameter for the width of the threshold.


thresholdCenter

public Parameter thresholdCenter
The parameter for the center of the threshold.


_thWidth

private double _thWidth

_thCenter

private double _thCenter

_first

private boolean _first

_accurate

private boolean _accurate

_upperBound

private double _upperBound

_lowerBound

private double _lowerBound

_lastInput

private double _lastInput

_thisInput

private double _thisInput
Constructor Detail

ThresholdMonitor

public ThresholdMonitor(CompositeEntity container,
                        java.lang.String name)
                 throws IllegalActionException,
                        NameDuplicationException
Construct an actor in the specified container with the specified name. The name must be unique within the container or an exception is thrown. The container argument must not be null, or a NullPointerException will be thrown.

Parameters:
container - The subsystem that this actor is lived in
name - The name of the actor.
Throws:
IllegalActionException - If the entity cannot be contained by the proposed container.
NameDuplicationException - If name coincides with an entity already in the container.
Method Detail

attributeChanged

public void attributeChanged(Attribute attribute)
                      throws IllegalActionException
Update local caches if the attributes have been changed.

Overrides:
attributeChanged in class NamedObj
Parameters:
attribute - The attribute that changed.
Throws:
IllegalActionException - If there is no token in the the attribute.

fire

public void fire()
          throws IllegalActionException
Consume the current input. If the input is in the threshold, then output true, otherwise output false.

Specified by:
fire in interface Executable
Overrides:
fire in class AtomicActor
Throws:
IllegalActionException - If there is no director.

initialize

public void initialize()
                throws IllegalActionException
Initialize the execution.

Specified by:
initialize in interface Initializable
Overrides:
initialize in class AtomicActor
Throws:
IllegalActionException - If thrown by the super class.

postfire

public boolean postfire()
                 throws IllegalActionException
Make this input to be the history input and return true.

Specified by:
postfire in interface Executable
Overrides:
postfire in class AtomicActor
Returns:
True.
Throws:
IllegalActionException - If token can not be read from or sent to ports, or thrown by the super class.

predictedStepSize

public double predictedStepSize()
Return java.lang.Double.MAX_VALUE, since this actor does not predict step sizes.

Specified by:
predictedStepSize in interface CTStepSizeControlActor
Returns:
java.lang.Double.MAX_VALUE.

refinedStepSize

public double refinedStepSize()
Return half the current step size if the step crosses the threshold. Otherwise, return the current step size.

Specified by:
refinedStepSize in interface CTStepSizeControlActor
Returns:
Half of the current step size if the step is not accurate.

isStateAccurate

public boolean isStateAccurate()
Description copied from interface: CTStepSizeControlActor
Implementations of this method should return true if this actor declares the current integration step is accurate w.r.t. its current states.

Specified by:
isStateAccurate in interface CTStepSizeControlActor
Returns:
True if the current step is accurate.

isOutputAccurate

public boolean isOutputAccurate()
Description copied from interface: CTStepSizeControlActor
Implementations of this method should return true if this actor declares the current integration step is accurate w.r.t. its output values.

Specified by:
isOutputAccurate in interface CTStepSizeControlActor
Returns:
True if the current step is accurate.