DAESystem
Full API
Causal.@def_dae_system
— Macro@def_dae_system ex
where ex
is the expression to define to define a new AbstractDAESystem component type. The usage is as follows:
@def_dae_system mutable struct MyDAESystem{T1,T2,T3,...,TN,OP,RH,RO,ST,IP,OP} <: AbstractDAESystem
param1::T1 = param1_default # optional field
param2::T2 = param2_default # optional field
param3::T3 = param3_default # optional field
⋮
paramN::TN = paramN_default # optional field
righthandside::RH = righthandside_function # mandatory field
readout::RO = readout_function # mandatory field
state::ST = state_default # mandatory field
stateder::ST = stateder_default # mandatory field
diffvars::Vector{Bool} = diffvars_default # mandatory field
input::IP = input_default # mandatory field
output::OP = output_default # mandatory field
end
Here, MyDAESystem
has N
parameters. MyDAESystem
is represented by the righthandside
and readout
function. state
, 'stateder,
diffvars,
inputand
outputis the initial state, initial value of differential variables, vector signifing differetial variables, input port and output port of
MyDAESystem`.
righthandside
must have the signature
function righthandside(out, dx, x, u, t, args...; kwargs...)
out .= .... # update out
end
and readout
must have the signature
function readout(x, u, t)
y = ...
return y
end
New DAE system must be a subtype of AbstractDAESystem
to function properly.
Example
julia> @def_dae_system mutable struct MyDAESystem{RH, RO, ST, IP, OP} <: AbstractDAESystem
righthandside::RH = function sfuncdae(out, dx, x, u, t)
out[1] = x[1] + 1 - dx[1]
out[2] = (x[1] + 1) * x[2] + 2
end
readout::RO = (x,u,t) -> x
state::ST = [1., -1]
stateder::ST = [2., 0]
diffvars::Vector{Bool} = [true, false]
input::IP = nothing
output::OP = Outport(1)
end
julia> ds = MyDAESystem();
Causal.DAESystem
— Typemutable struct DAESystem{RH, RO, ST<:(AbstractVector{var"#s16875"} where var"#s16875"<:Real), SD<:(AbstractVector{var"#s16874"} where var"#s16874"<:Real), DV<:(AbstractVector{var"#s16873"} where var"#s16873"<:Bool), IP<:(Union{var"#s16872", var"#s16632"} where {var"#s16872"<:Inport, var"#s16632"<:Nothing}), OP<:(Union{var"#s16631", var"#s16630"} where {var"#s16631"<:Outport, var"#s16630"<:Nothing}), var"4004", var"4005", var"4006", Symbol, var"4007", Float64, var"4008", var"4009", var"4010", var"4011", var"4012", var"4013"} <: AbstractDAESystem
Constructs a generic DAE system.
Example
julia> function sfuncdae(out, dx, x, u, t)
out[1] = x[1] + 1 - dx[1]
out[2] = (x[1] + 1) * x[2] + 2
end;
julia> ofuncdae(x, u, t) = x;
julia> x0 = [1., -1];
julia> dx0 = [2., 0.];
julia> DAESystem(righthandside=sfuncdae, readout=ofuncdae, state=x0, input=nothing, output=Outport(1), diffvars=[true, false], stateder=dx0)
DAESystem(righthandside:sfuncdae, readout:ofuncdae, state:[1.0, -1.0], t:0.0, input:nothing, output:Outport(numpins:1, eltype:Outpin{Float64}))
Causal.RobertsonSystem
— Typemutable struct RobertsonSystem{T1<:Real, T2<:Real, T3<:Real, RH, RO, IP<:(Union{var"#s16875", var"#s16874"} where {var"#s16875"<:Inport, var"#s16874"<:Nothing}), OP<:(Union{var"#s16873", var"#s16872"} where {var"#s16873"<:Outport, var"#s16872"<:Nothing}), T4<:(AbstractVector{var"#s16632"} where var"#s16632"<:Real), T5<:(AbstractVector{var"#s16631"} where var"#s16631"<:Real), T6<:(AbstractVector{var"#s16630"} where var"#s16630"<:Bool), var"4004", var"4005", var"4006", Symbol, var"4007", Float64, var"4008", var"4009", var"4010", var"4011", var"4012", var"4013"} <: AbstractDAESystem
Constructs a Robertson systme with the dynamcis
\[\begin{array}{l} \dot{x}_1 = -k_1 x_1 + k_3 x_2 x_3 \\[0.25cm] \dot{x}_2 = k_1 x_1 - k_2 x_2^2 - k_3 x_2 x_3 \\[0.25cm] 1 = x_1 + x_2 + x_3 �nd{array}\]
Causal.PendulumSystem
— Typemutable struct PendulumSystem{T1<:Real, T2<:Real, T3<:Real, T4<:Real, RH, RO, IP<:(Union{var"#s16875", var"#s16874"} where {var"#s16875"<:Inport, var"#s16874"<:Nothing}), OP<:(Union{var"#s16873", var"#s16872"} where {var"#s16873"<:Outport, var"#s16872"<:Nothing}), T5<:(AbstractVector{var"#s16632"} where var"#s16632"<:Real), T6<:(AbstractVector{var"#s16631"} where var"#s16631"<:Real), T7<:(AbstractVector{var"#s16630"} where var"#s16630"<:Bool), var"4004", var"4005", var"4006", Symbol, var"4007", Float64, var"4008", var"4009", var"4010", var"4011", var"4012", var"4013"} <: AbstractDAESystem
Constructs a Pendulum systme with the dynamics
\[\begin{array}{l} \dot{x}_1 = x_3 \\[0.25cm] \dot{x}_2 = x_4 \\[0.25cm] \dot{x}_3 = -\dfrac{F}{m l} x_1 \\[0.25cm] \dot{x}_4 = g \dfrac{F}{l} x_2 \\[0.25cm] 0 = x_1^2 + x_2^2 - l^2 \end{array}\]
where $F$ is the external force, $l$ is the length, $m$ is the mass and $g$ is the accelaration of gravity.
Causal.RLCSystem
— Typemutable struct RLCSystem{T1<:Real, T2<:Real, T3<:Real, RH, RO, IP<:(Union{var"#s16875", var"#s16874"} where {var"#s16875"<:Inport, var"#s16874"<:Nothing}), OP<:(Union{var"#s16873", var"#s16872"} where {var"#s16873"<:Outport, var"#s16872"<:Nothing}), T4<:(AbstractVector{var"#s16632"} where var"#s16632"<:Real), T5<:(AbstractVector{var"#s16631"} where var"#s16631"<:Real), T6<:(AbstractVector{var"#s16630"} where var"#s16630"<:Bool), var"4004", var"4005", var"4006", Symbol, var"4007", Float64, var"4008", var"4009", var"4010", var"4011", var"4012", var"4013"} <: AbstractDAESystem
Construsts a RLC system with the dynamics
\[\begin{array}{l} \dot{x}_1 = x_3 \\[0.25cm] \dot{x}_2 = x_4 \\[0.25cm] \dot{x}_3 = -\dfrac{F}{m l} x_1 \\[0.25cm] \dot{x}_4 = g \dfrac{F}{l} x_2 \\[0.25cm] 0 = x_1^2 + x_2^2 - l^2 \end{array}\]
where $F$ is the external force, $l$ is the length, $m$ is the mass and $g$ is the accelaration of gravity.