# 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,

1. The next clock time t is read from its trigger pin.
2. The next input value u(t) is read from from its input port,
3. The component evolves from its current time t - dt to the current clock time t
4. Using the state variable x(t) at time t, current clock time t and u(t), the next output value y(t) is computed.
5. The component writes true to its handshake pin to signal that taking step is performed with success.

or a backward step as follows.

1. The next clock time t is read from its trigger pin.
2. Using the state variable x(t - dt) at time t - dt, current component time t - dt and u(t - dt), the next output value y(t) is computed.
3. The next input value u(t) is read from from its input port,
4. The component evolves from its current time t - dt to the current clock time t
5. The component writes true to its handshake pin to signal that taking step is performed with success.

Here dt is the simulation step size.

Returns the state of comp if comp is AbstractDynamicSystem. Otherwise, returns nothing.

## Writing Output

Causal.writeoutput!Function
writeoutput!(comp, out)

Writes out to the output of comp if the output of comp is Outport. Otherwise, does nothing.

## Computing Output

Causal.computeoutputFunction

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!Function
evolve!(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.forwardstepFunction
forwardstep(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.backwardstepFunction
backwardstep(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.approve!Function
approve!(comp)

approve!(comp)