Evolution of Components
In Causal, the simulation of a model is performed by individual evolution of components (see Modeling and Simulation for more information of modeling and simulation adopted in Causal). Basically, when triggered through its trigger pin, based on its type, a component takes a forward step as follows,
- The next clock time
tis read from itstriggerpin. - The next input value
u(t)is read from from itsinputport, - The component evolves from its current time
t - dtto the current clock timet - Using the state variable
x(t)at timet, current clock timetandu(t), the next output valuey(t)is computed. - The component writes
trueto itshandshakepin to signal that taking step is performed with success.
or a backward step as follows.
- The next clock time
tis read from itstriggerpin. - Using the state variable
x(t - dt)at timet - dt, current component timet - dtandu(t - dt), the next output valuey(t)is computed. - The next input value
u(t)is read from from itsinputport, - The component evolves from its current time
t - dtto the current clock timet - The component writes
trueto itshandshakepin to signal that taking step is performed with success.
Here dt is the simulation step size.
Reading Time
Causal.readtime! — Functionreadtime!(comp::AbstractComponent)Returns current time of comp read from its trigger link.
To read time of comp, comp must be launched. See also: launch(comp::AbstractComponent).
Reading State
Causal.readstate — Functionreadstate(comp::AbstractComponent)Returns the state of comp if comp is AbstractDynamicSystem. Otherwise, returns nothing.
Reading Input
Causal.readinput! — Functionreadinput!(comp::AbstractComponent)Returns the input value of comp if the input of comp is Inport. Otherwise, returns nothing.
To read input value of comp, comp must be launched. See also: launch(comp::AbstractComponent)
Writing Output
Causal.writeoutput! — Functionwriteoutput!(comp::AbstractComponent, out)Writes out to the output of comp if the output of comp is Outport. Otherwise, does nothing.
Computing Output
Causal.computeoutput — Functioncomputeoutput(comp, x, u, t)Computes the output of comp according to its readout if readout is not nothing. Otherwise, nothing is done. x is the state, u is the value of input, t is the time.
Evolve
Causal.evolve! — Functionevolve!(comp::AbstractSource, u, t)Does nothing. u is the value of input and t is time.
evolve!(comp::AbstractSink, u, t)Writes t to time buffer timebuf and u to databuf of comp. u is the value of input and t is time.
evolve!(comp::AbstractStaticSystem, u, t)Writes u to buffer of comp if comp is an AbstractMemory. Otherwise, nothing is done. u is the value of input and t is time.
evolve!(comp::AbstractDynamicSystem, u, t)Solves the differential equation of the system of comp for the time interval (comp.t, t) for the inital condition x where x is the current state of comp . u is the input function defined for (comp.t, t). The comp is updated with the computed state and time t.
Taking Steps
Causal.takestep! — Functiontakestep!(comp::AbstractComponent)Reads the time t from the trigger link of comp. If comp is an AbstractMemory, a backward step is taken. Otherwise, a forward step is taken. See also: forwardstep, backwardstep.
takestep!(comp::AbstractSubSystem)Makes comp to take a step by making each subcomponent of comp take a step. See also: takestep!(comp::AbstractComponent)
Causal.forwardstep — Functionforwardstep(comp, t)Makes comp takes a forward step. The input value u and state x of comp are read. Using x, u and time t, comp is evolved. The output y of comp is computed and written into the output bus of comp.
Causal.backwardstep — Functionbackwardstep(comp, t)Reads the state x. Using the time t and x, computes and writes the ouput value y of comp. Then, the input value u is read and comp is evolved.
Causal.launch — Methodlaunch(comp::AbstractComponent)Returns a tuple of tasks so that trigger link and output bus of comp is drivable. When launched, comp is ready to be driven from its trigger link. See also: drive!(comp::AbstractComponent, t)
Causal.launch — Methodlaunch(comp::AbstractSubSystem)Launches all subcomponents of comp. See also: launch(comp::AbstractComponent)
Causal.drive! — Functiondrive!(comp::AbstractComponent, t)Writes t to the trigger link of comp. When driven, comp takes a step. See also: takestep!(comp::AbstractComponent)
drive!(comp::AbstractSubSystem, t)Drives comp by driving each subcomponent of comp. See also: drive!(comp::AbstractComponent, t)
Causal.approve! — Functionapprove!(comp::AbstractComponent)Read handshake link of comp. When not approved or false is read from the handshake link, the task launched for the trigger link of comp gets stuck during comp is taking step.
approve!(comp::AbstractSubSystem)Approves comp by approving each subcomponent of comp. See also: approve!(comp::AbstractComponent)
Causal.terminate! — Functionterminate!(comp::AbstractComponent)Closes the trigger link and output bus of comp.
terminate!(comp::AbstractSubSystem)Terminates comp by terminating each subcomponent of comp. See also: terminate!(comp::AbstractComponent)
terminate!(model::Model)Terminates model by terminating all the components of the model, i.e., the components tasks in the task manager of the model is terminated.