DDESystem
Construction of DDESystem
A DDESystem
is represented by the following state equation
where $t$ is the time, $x$ is the value of the state
, $u$ is the value of the input
. $h$ is the history function for which
and by the output equation
where $y$ is the value of the output
.
As an example, consider a system with the state equation
First, we define the history function histfunc
,
julia> using Jusdl # hdie
julia> const out = zeros(1)
1-element Array{Float64,1}:
0.0
julia> histfunc(out, u, t)
ERROR: UndefVarError: histfunc not defined
Note that histfunc
mutates a vector out
. This mutation is for performance reasons
. Next the state function can be defined
julia> function statefunc(dx, x, h, u, t)
h(out, u, t - tau) # Update out vector
dx[1] = out[1] + x[1]
end
statefunc (generic function with 1 method)
and let us take all the state variables as outputs. Thus, the output function is
julia> outputfunc(x, u, t) = x
outputfunc (generic function with 1 method)
Next, we need to define the history
for the system. History is defined by specifying a history function, and the type of the lags. There may be two different lag: constant lags which are independent of the state variable $x$ and the dependent lags which are mainly the functions of the state variable $x$. Note that for this example, the have constant lags. Thus,
julia> tau = 1
1
julia> conslags = [tau]
1-element Array{Int64,1}:
1
julia> hist = History(histfunc, conslags, ())
ERROR: UndefVarError: History not defined
At this point, we are ready to construct the system.
julia> ds = DDESystem(nothing, Bus(), statefunc, outputfunc, state, hist, 0.)
ERROR: UndefVarError: state not defined
Basic Operation of DDESystem
The basis operaiton of DDESystem
is the same as those of other dynamical systems. When triggered from its trigger
link, the DDESystem
reads its time from its trigger
link, reads input, solves its differential equation, computes its output and writes the computed output to its output
bus. To drive DDESystem
, we must first launch it,
julia> task = launch(ds)
ERROR: UndefVarError: ds not defined
When launched, ds
is drivable. To drive ds
, we can use the syntax drive(ds, t)
or put!(ds.trigger, t)
where t
is the time until which ds
is to be driven.
julia> drive(ds, 1.)
ERROR: UndefVarError: ds not defined
When driven, ds
reads the time t
from its trigger
link, (since its input is nothing
, ds
does nothing during its input reading stage), solves its differential equation, computes output and writes the value of its output to its output
bus. To signify, the step was taken with success, ds
writes true
to its handshake
which must be read to further drive ds
. For this, we can use the syntax approve(ds)
or take!(ds.handshake)
.
julia> approve(ds)
ERROR: UndefVarError: ds not defined
We can continue to drive ds
.
julia> for t in 2. : 10.
drive(ds, t)
approve(ds)
end
ERROR: UndefVarError: ds not defined
When launched, we constructed a task
whose state is running
which implies that ds
can be driven.
julia> task
ERROR: UndefVarError: task not defined
As long as the state of the task
is running
, ds
can be driven. To terminate task
safely, we need to terminate the ds
.
julia> terminate(ds)
ERROR: UndefVarError: ds not defined
Note that the state of task
is done
which implies that ds
is not drivable any more.
Note that the output values of ds
is written to its output
bus.
julia> ds.output[1].buffer.data
ERROR: UndefVarError: ds not defined
Full API
Jusdl.Components.Systems.DynamicSystems.DDESystem
— TypeDDESystem(input, output, statefunc, outputfunc, state, t, modelargs=(), solverargs=();
alg=DDEAlg, modelkwargs=NamedTuple(), solverkwargs=NamedTuple())
Constructs a DDESystem
with input
and output
. statefunc
is the state function and outputfunc
is the output function of DDESystem
. state
is the initial state and t
is the time. modelargs
and modelkwargs
are passed into ODEProblem
and solverargs
and solverkwargs
are passed into solve
method of DifferentialEquations
. alg
is the algorithm to solve the differential equation of the system.
The DDESystem
is represented by
where $t$ is the time t
, $x$ is the value of state
, $u$ is the value of input
, $y$ is the value of output
. $f$ is statefunc
, $g$ is outputfunc
. $h$is the history function of history
. solver
is used to solve the above differential equation.
The syntax of statefunc
must be of the form
function statefunc(dx, x, u, t)
dx .= ... # Update dx
end
and the syntax of outputfunc
must be of the form
function outputfunc(x, u, t)
y = ... # Compute y
return y
end
Example
julia> const out = zeros(1);
julia> histfunc(out, u, t) = (out .= 1.);
julia> function statefunc(dx, x, h, u, t)
h(out, u, t - tau) # Update out vector
dx[1] = out[1] + x[1]
end;
julia> outputfunc(x, u, t) = x;
julia> tau = 1;
julia> conslags = [tau];
julia> ds = DDESystem(nothing, Bus(), (statefunc, histfunc), outputfunc, [1.], 0.)
DDESystem(state:[1.0], t:0.0, input:nothing, output:Bus(nlinks:1, eltype:Link{Float64}, isreadable:false, iswritable:false))
See DifferentialEquations for more information about modelargs
, modelkwargs
, solverargs
solverkwargs
and alg
.