Class Derivative
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.kernel.InstantiableNamedObj
-
- ptolemy.kernel.Entity<T>
-
- ptolemy.kernel.ComponentEntity<T>
-
- ptolemy.actor.AtomicActor<TypedIOPort>
-
- ptolemy.actor.TypedAtomicActor
-
- ptolemy.domains.continuous.lib.Derivative
-
- All Implemented Interfaces:
java.lang.Cloneable
,Actor
,Executable
,FiringsRecordable
,Initializable
,TypedActor
,Changeable
,Debuggable
,DebugListener
,Derivable
,Instantiable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
public class Derivative extends TypedAtomicActor
A crude approximation to a derivative in the continuous domain. In continuous-time modeling, one should generally avoid taking derivatives directly. It is better to use anIntegrator
actor in a feedback loop. The input to the Integrator is the derivative of its output. The reason for avoiding taking derivatives directly is that small amounts of noise on the input of a derivative actor result in large output fluctuations. Since continuous-time simulation involves choosing step sizes, the choice of step size will strongly affect the resulting output of the derivative. Derivatives tend to be very noisy, with considerable fluctuations in value. Moreover, if the input to this actor has discontinuities, the output will not be piecewise continuous, and at the discontinuity, the results could be difficult to control. If an Integrator is downstream, then the solver will be forced to use its smallest step size.That said, if you have read this far, you are probably determined to compute a derivative. Hence, we provide this actor, which performs a simple operation and provides a simple (partial) guarantee. Specifically, a correctly connected Derivative followed by an Integrator is (almost) an identity function. And an Integrator followed by a Derivative is also (almost) an identity function. The reason for the "almost" is that very first derivative output of the Derivative actor is always zero. Determining a derivative without any past history requires seeing the future. Although in principle it might be possible for this actor to collaborate with the solver to speculatively execute into the future to get the derivative, we have not done that here.
Upon firing, this actor produces an output on the derivative port, and may also produce an output on the impulse port. The derivative output value is the difference between the input at the current time and the previous input divided by the time between these inputs, unless that time is zero. If the time between this input and the previous one is zero, and the value of the previous input and the current one is non-zero, then this actor will be produce the value difference on the impulse output and will produce whatever it previously produced on the derivative output.
On the very first firing after being initialized, this actor always produces zero on the derivative output. If the input is non-zero, then it will produce the value of the input on the impulse output. This ensures that if the impulse output is connected to the impulse input of a downstream Integrator, that the Integrator will be correctly initialized.
The impulse output should be interpreted as a Dirac delta function. It is a discrete output. If it is connected to the impulse input of the Integrator actor, and the derivative output is connected to the derivative input of the Integrator actor, then the cascade of two actors will be an identity function for all input signals.
If upon any firing the input is absent, then both outputs will be absent, and the actor will reinitialize. Hence, on the next firing where the input is present, this actor will behave as if that firing is a first firing.
Note that this actor exercises no control at all over step sizes. It simply works with whatever step sizes are provided. Thus, it is mathematically questionable to use it in any model except where its input comes from an Integrator or its outputs go to an Integrator. The Integrator actor will exercise control over step sizes.
- Since:
- Ptolemy II 10.0
- Version:
- $Id$
- Author:
- Edward A. Lee and Janette Cardoso
- Pt.AcceptedRating:
- Red (eal)
- Pt.ProposedRating:
- Yellow (eal)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description TypedIOPort
derivative
The derivative output port.TypedIOPort
impulse
The impulse output port.TypedIOPort
input
The input port.-
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 Derivative(CompositeEntity container, java.lang.String name)
Construct a derivative actor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
fire()
Produce outputs as specified in the class comment.void
initialize()
Ensure that the next invocation of the fire() method is treated as a first firing.boolean
postfire()
Record the current input and time.-
Methods inherited from class ptolemy.actor.TypedAtomicActor
_containedTypeConstraints, _customTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints
-
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, _declareDelayDependency, addActorFiringListener, addInitializable, 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
_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, attributeChanged, 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, 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
-
-
-
-
Field Detail
-
derivative
public TypedIOPort derivative
The derivative output port. This port has type double.
-
impulse
public TypedIOPort impulse
The impulse output port. This port has type double.
-
input
public TypedIOPort input
The input port. This port has type double.
-
-
Constructor Detail
-
Derivative
public Derivative(CompositeEntity container, java.lang.String name) throws NameDuplicationException, IllegalActionException
Construct a derivative actor.- Parameters:
container
- The container.name
- The name.- Throws:
NameDuplicationException
- If the name is used by another actor in the container.IllegalActionException
- If ports can not be created, or thrown by the super class.- See Also:
ContinuousIntegrator
-
-
Method Detail
-
fire
public void fire() throws IllegalActionException
Produce outputs as specified in the class comment.- Specified by:
fire
in interfaceExecutable
- Overrides:
fire
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- If the superclass throws it.
-
initialize
public void initialize() throws IllegalActionException
Ensure that the next invocation of the fire() method is treated as a first firing.- Specified by:
initialize
in interfaceInitializable
- Overrides:
initialize
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- If the superclass throws it.
-
postfire
public boolean postfire() throws IllegalActionException
Record the current input and time.- Specified by:
postfire
in interfaceExecutable
- Overrides:
postfire
in classAtomicActor<TypedIOPort>
- Returns:
- Whatever the superclass returns (true).
- Throws:
IllegalActionException
- If the superclass throws it.
-
-