|
|||||||||
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.domains.ct.kernel.CTDirector
ptolemy.domains.ct.kernel.CTMultiSolverDirector
public class CTMultiSolverDirector
A CTDirector that uses multiple ODE solvers. The reason for using different solvers is that we need to handle both normal integration of ODEs over a time interval and abrupt changes in signals (or actors' functions) that happen at discrete time points.
At the time points where abrupt changes happen, a special ODE solver, called breakpointODESolver, is used. Typically, breakpointODESolver does not advance time. The job for a breakpointODESolver is to find the states of the system at a breakpoint. Usually, the system has more than one state at such time points, which is also known as discontinuities. We call the first state at a discontinuity the initial state, and the last state the final state. Therefore, a breakpointODESolver is responsible to resolve the final state of a discontinuity from the inputs and the initial states.
The following paper gives a detailed explanation of initial and final states and how the initial and final states are resolved.
This director handles both predictable breakpoints, whose appearance can be assured before reaching the time points they happen, and unpredictable breakpoints, whose appearance is unknown before the simulation passes the time points they happen.
This director can only be a top-level director. For a CT model as an opaque composite actor inside another model, use CTMixedSignalDirector (if the outer model is a discrete-event model) or CTEmbeddedDirector (if the outer model is a CT model or a Modal model with a HSFSMDirector.)
This director recognizes actors that implement the CTStepSizeControlActor interface and adjusts the step size by polling such actors. If all actors are content with the current step size, then it attempts to raise the step size. If any actor is not satisfied with the current step size, then this director reduces the step size. A special case is that if there are no CT step size control actors, then this director uses 5 times of the current step size or the maximum step size, whichever is smaller.
This director has two more parameters than the CTDirector base class.
DerivativeResolver
.
CTDirector
,
Serialized Form
Red (hyzheng) |
Yellow (hyzheng) |
Nested Class Summary |
---|
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj |
---|
NamedObj.ContainedObjectsIterator |
Field Summary | |
---|---|
private ODESolver |
_breakpointSolver
The breakpoint solver. |
private java.lang.String |
_breakpointSolverClassName
The classname of the breakpoint ODE solver. |
protected boolean |
_initialStatesNotReady
Flag indicating the initial states are not ready. |
private ODESolver |
_normalSolver
The normal solver. |
private java.lang.String |
_normalSolverClassName
The classname of the normal ODE solver. |
private static java.lang.String |
_solverClasspath
The classpath for solvers. |
Parameter |
breakpointODESolver
The class name of the ODE solver that is used in the breakpoint iterations. |
Parameter |
ODESolver
The class name of the normal ODE solver used in iterations for normal integration. |
Fields inherited from class ptolemy.domains.ct.kernel.CTDirector |
---|
_timeBase, errorTolerance, initStepSize, maxIterations, maxStepSize, minStepSize, startTime, stopTime, synchronizeToRealTime, valueResolution |
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 | |
---|---|
CTMultiSolverDirector()
Construct a director in the default workspace with an empty string as its name. |
|
CTMultiSolverDirector(CompositeEntity container,
java.lang.String name)
Construct a director in the given container with the given name. |
|
CTMultiSolverDirector(Workspace workspace)
Construct a director in the workspace with an empty name. |
Method Summary | |
---|---|
protected void |
_continuousPhaseExecution()
This method performs a continuous phase of execution. |
protected void |
_discretePhaseExecution()
Perform a discrete phase of execution by processing all discrete events happening at the current model time. |
protected void |
_initParameters()
Initialize parameters to their default values. |
protected boolean |
_isOutputAccurate()
Return true if all step size control actors in the output schedule agree that the current step is accurate. |
protected boolean |
_isStateAccurate()
Return true if all step size control actors in the dynamic actor schedule and the state transition schedule agree that the current step size is accurate. |
protected void |
_iterateEventGenerators(CTSchedule schedule)
Iterate all event generators . |
protected void |
_iteratePurelyDiscreteActors(CTSchedule schedule)
Iterate all purely discrete-event actors. |
private void |
_iterateSchedule(ScheduleElement schedule)
Iterate all the actors inside a given schedule, by prefiring, firing and postfiring them. |
protected void |
_iterateWaveformGenerators(CTSchedule schedule)
Iterate all wave generators. |
private void |
_markStates()
Mark the current state as the known good state. |
protected double |
_predictNextStepSize()
Predict the next step size. |
protected void |
_propagateResolvedStates()
Use breakpoint ODE solver to propagate the resolved states at the current phase of execution. |
private double |
_refinedStepWRTBreakpoints()
Adjust step size so that the first breakpoint is not in the middle of this step. |
protected double |
_refinedStepWRTOutput()
Return the refined step size with respect to the output actors. |
protected double |
_refinedStepWRTState()
Return the refined step size with respect to state accuracy requirement. |
protected boolean |
_removeCurrentTimeFromBreakpointTable()
Return true if the current time is the first element in the breakpoint table, and remove that element from the breakpoint table. |
protected void |
_resolveInitialStates()
Resolve the initial states with a normal ODE solver at a further time. |
void |
attributeChanged(Attribute attribute)
React to a change in an attribute. |
boolean |
canBeInsideDirector()
Return false always, since this director cannot be an inside director. |
boolean |
canBeTopLevelDirector()
Return true since this director can be a top-level director. |
void |
establishInitialStates()
Establish the initial states for discrete phase of execution. |
void |
fire()
Fire the system for one iteration. |
void |
fireEventGenerators()
Fire event generators. |
ODESolver |
getBreakpointSolver()
Return the breakpoint ODE solver. |
CTGeneralDirector |
getExecutiveCTGeneralDirector()
Always return null, because this director can not be an inside director. |
ODESolver |
getNormalODESolver()
Return the ODE solver for normal integration. |
java.lang.String |
getODESolverClassName()
Return the class name for the ODE solver. |
boolean |
hasCurrentEvent()
Return true if there is an event at the current time. |
void |
initialize()
Initialize the model for a simulation. |
boolean |
postfire()
Return true if this director wants to be fired again. |
void |
postfireEventGenerators()
Postfire event generators. |
boolean |
prefire()
Call the prefire() method of the super class and return its value. |
void |
preinitialize()
After calling the preinitialize() method of the super class, instantiate all the solvers. |
void |
produceOutput()
Fire all the actors in the output schedule. |
void |
setInitialStatesNotReady()
Set the flag indicating that the initial states are not ready. |
void |
setModelTime(Time newTime)
Set a new value to the current time of the model, where the new time can be earlier than the current time to support rollback. |
void |
updateContinuousStates()
Call the postfire() method on all continuous actors in the schedule. |
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 |
Field Detail |
---|
public Parameter breakpointODESolver
public Parameter ODESolver
protected boolean _initialStatesNotReady
private ODESolver _breakpointSolver
private java.lang.String _breakpointSolverClassName
private ODESolver _normalSolver
private java.lang.String _normalSolverClassName
private static java.lang.String _solverClasspath
Constructor Detail |
---|
public CTMultiSolverDirector()
public CTMultiSolverDirector(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 in derived classes.
NameDuplicationException
- If the container is not a
CompositeActor and the name collides with an entity in the container.public CTMultiSolverDirector(Workspace workspace)
workspace
- The workspace of this object.Method Detail |
---|
public void attributeChanged(Attribute attribute) throws IllegalActionException
attributeChanged
in class CTDirector
attribute
- The changed attribute.
IllegalActionException
- If the new solver can not be
instantiated, or the change to other attributes is invalid.public boolean canBeInsideDirector()
canBeInsideDirector
in class CTDirector
public boolean canBeTopLevelDirector()
canBeTopLevelDirector
in class CTDirector
public void establishInitialStates() throws IllegalActionException
IllegalActionException
- If any actor can not be iterated, or
can not ODE solver can not be set.public void fire() throws IllegalActionException
To resolve the final states at the time point t_0, a discrete phase of execution is performed. A discrete phase of execution at a time point is a fixed-point iteration, where the fixed point is reached when no more events exist and there will be no more events to be generated at that time point. To be concrete, at a discrete phase execution, event generators, purely discrete actors, waveform generators, and continuous actors are repeatedly iterated. The discrete phase of execution stops only when no event generators generate any more events. At the ending of the execution, the system states are resolved, which are called the final states at t_0. These states are marked as known good states for roll back purpose. The solver for the discrete phase of execution is a breakpoint ODE solver.
The way we find the fixed point is based on the synchronous reactive semantics. To be specific, the directors resolve the value of each signal from unknown to be either absent or present. This design is simple but firing all actors at each breakpoint causes overhead.
We could have used a smarter event queue like the one used by the DE director. Therefore only those actors with trigger events will be executed. However, this design will increase the complexity of this class. We assume that a CT model does not have many DE actors inside. If the discrete part of the model is complicated with a lot of DE actors, we would suggest using an opaque DE composite actor to encapsulate these DE actors and associate the composite actor with a DE director to take charge of the execution of those DE actors.
A continuous phase of execution immediately follows a discrete one, which solves the initial states at t_1. The initial states at t_1 are resolved by a normal ODE solver. This process is a normal integration over a time interval.
The ending time point t_1 of an iteration is determined by the step sizes suggested by the step size control actors and the earliest entry in the breakpoint table. A correct step size is no greater than the smallest suggested step size, and the current time plus the step size should not be later than the first entry in the breakpoint table.
Because of the existence of unpredictable events, a step size may need to be refined. Another reason to adjust step size is to achieve a reasonably accurate approximation of states. The mechanism to control step size is described below. After the states are resolved, step size control actors in the dynamic actor schedule and the state transition schedule are queried for the accuracy of the current step size. If any one of them is not satisfied with the current step size, then the states will be recalculated with a refined step size, which is the minimum of the refined step sizes from all step size control actors in the dynamic actor schedule and the state transition schedule. On the other hand, if all the above actors are satisfied with the current step, then the actors in the output path will be fired according to the output schedule. Then, the step size control actors in the output path will be checked for accuracy. If any actor is not satisfied with the current step size, the current step size is refined. Note that states have to be resolved again with this new step size. States are completely resolved only when all actors agree that the step size is accurate.
fire
in interface Executable
fire
in class CTDirector
IllegalActionException
- If thrown in discrete or continuous
phase of execution.public void fireEventGenerators() throws IllegalActionException
IllegalActionException
- If the schedule does not exist,
or any actor can not be prefired, or any actor throws it during firing.public ODESolver getBreakpointSolver()
getNormalODESolver()
public CTGeneralDirector getExecutiveCTGeneralDirector()
public ODESolver getNormalODESolver()
getBreakpointSolver()
public java.lang.String getODESolverClassName()
CTGeneralDirector
public boolean hasCurrentEvent()
public void initialize() throws IllegalActionException
initialize
in interface Initializable
initialize
in class CTDirector
IllegalActionException
- If the initialize() method of the
super class throws it, or the stop time can not be
registered as a breakpoint.public boolean postfire() throws IllegalActionException
postfire
in interface Executable
postfire
in class CTDirector
IllegalActionException
- If thrown by the super class, or the
current model time is bigger than the stop time.public boolean prefire() throws IllegalActionException
prefire
in interface Executable
prefire
in class StaticSchedulingDirector
IllegalActionException
- If thrown by the super class.public void preinitialize() throws IllegalActionException
preinitialize
in interface Initializable
preinitialize
in class CTDirector
IllegalActionException
- If thrown by the super class,
or not all solvers can be instantiated, or the current solver
can not be set.public void produceOutput() throws IllegalActionException
If they have not be prefired, prefire them first. The abstract semantics require that prefire() be called exactly once in an iteration. This is important because, for example, time can only be tested reliably in prefire(). The time tested indicates the starting point of an integration step. During the following possibly multiple firings, time may progress, depending on the ODE solver used. Hierarchies in CT and hybrid systems cases actually rely on this fact to control internal step sizes.
FIXME: If we treat time as a state, it should not change until the postfire method!
IllegalActionException
- If there is no schedule, or any
output actor can not be prefired or fired, or any output actor
returns false from its prefire method.public void postfireEventGenerators() throws IllegalActionException
IllegalActionException
- If the schedule does not exist, or
any actor throws it during postfiring.public void setInitialStatesNotReady()
public final void setModelTime(Time newTime)
setModelTime
in class Director
newTime
- The new current simulation time.Director.getModelTime()
public void updateContinuousStates() 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.
IllegalActionException
- If the synchronizeToRealTime
parameter does not have a valid token, or the sleep is interrupted,
or there is not a schedule, or any of the actors in the schedule can
not be postfired.protected void _continuousPhaseExecution() throws IllegalActionException
Note that t_1 can be adjusted by the normal ODE solver with respect to the accuracy requirements from step size control actors. Therefore, this method starts with a guess of t_1, or an integration step size as (t_1 - t_0). If all step size control actors are satisfied with the guess, this method returns. Otherwise, the normal ODE solver chooses a smaller step size and tries to solve the states. Therefore, this method ends up with either resolved states or an exception complaining that states can not be resolved even with the preconfigured minimum step size.
IllegalActionException
- If ODESolver can not be set or
one of the continuous actors throws it.protected void _discretePhaseExecution() throws IllegalActionException
IllegalActionException
- If one of the actors throws it or
the schedule does not exist.protected void _initParameters()
_initParameters
in class CTDirector
protected boolean _isOutputAccurate()
protected boolean _isStateAccurate()
protected void _iteratePurelyDiscreteActors(CTSchedule schedule) throws IllegalActionException
schedule
- The schedule that contains purely discrete-event actors.
IllegalActionException
- If any actor can not be iterated.protected void _iterateEventGenerators(CTSchedule schedule) throws IllegalActionException
schedule
- The schedule that contains event generators.
IllegalActionException
- If any actor can not be iterated.protected void _iterateWaveformGenerators(CTSchedule schedule) throws IllegalActionException
schedule
- The schedule that contains wave generators.
IllegalActionException
- If any actor can not be iterated.protected double _predictNextStepSize() throws IllegalActionException
IllegalActionException
- If the scheduler throws it.protected double _refinedStepWRTOutput() throws IllegalActionException
IllegalActionException
- If the scheduler throws it or the
refined step size is less than the time resolution.protected double _refinedStepWRTState() throws IllegalActionException
IllegalActionException
- If the scheduler throws it, or the
refined step size is less than the minimum step size parameter
of the director.protected boolean _removeCurrentTimeFromBreakpointTable() throws IllegalActionException
IllegalActionException
- If a breakpoint is missed.protected void _propagateResolvedStates() throws IllegalActionException
IllegalActionException
- If one of the actors throws it or
the ODE solver can not be set.protected void _resolveInitialStates() throws IllegalActionException
IllegalActionException
- If one the actors throws it
in its execution methods.private void _iterateSchedule(ScheduleElement schedule) throws IllegalActionException
IllegalActionException
private void _markStates() throws IllegalActionException
IllegalActionException
- If thrown by the scheduler.private double _refinedStepWRTBreakpoints()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |