DAESystem

Full API

Causal.@def_dae_systemMacro
@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,inputandoutputis the initial state, initial value of differential variables, vector signifing differetial variables, input port and output port ofMyDAESystem`.

Warning

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
Warning

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();
source
Causal.DAESystemType
mutable struct DAESystem{RH, RO, ST<:(AbstractArray{var"#s301",1} where var"#s301"<:Real), SD<:(AbstractArray{var"#s300",1} where var"#s300"<:Real), DV<:(AbstractArray{var"#s299",1} where var"#s299"<:Bool), IP<:(Union{var"#s298", var"#s297"} where var"#s297"<:Nothing where var"#s298"<:Inport), OP<:(Union{var"#s296", var"#s295"} where var"#s295"<:Nothing where var"#s296"<:Outport), var"253", var"254", var"255", Symbol, var"256", Float64, var"257", var"258", var"259", var"260", var"261", var"262"} <: 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}))
source
Causal.RobertsonSystemType
mutable struct RobertsonSystem{T1<:Real, T2<:Real, T3<:Real, RH, RO, IP<:(Union{var"#s301", var"#s300"} where var"#s300"<:Nothing where var"#s301"<:Inport), OP<:(Union{var"#s299", var"#s298"} where var"#s298"<:Nothing where var"#s299"<:Outport), T4<:(AbstractArray{var"#s297",1} where var"#s297"<:Real), T5<:(AbstractArray{var"#s296",1} where var"#s296"<:Real), T6<:(AbstractArray{var"#s295",1} where var"#s295"<:Bool), var"253", var"254", var"255", Symbol, var"256", Float64, var"257", var"258", var"259", var"260", var"261", var"262"} <: 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}\]

source
Causal.PendulumSystemType
mutable struct PendulumSystem{T1<:Real, T2<:Real, T3<:Real, T4<:Real, RH, RO, IP<:(Union{var"#s301", var"#s300"} where var"#s300"<:Nothing where var"#s301"<:Inport), OP<:(Union{var"#s299", var"#s298"} where var"#s298"<:Nothing where var"#s299"<:Outport), T5<:(AbstractArray{var"#s297",1} where var"#s297"<:Real), T6<:(AbstractArray{var"#s296",1} where var"#s296"<:Real), T7<:(AbstractArray{var"#s295",1} where var"#s295"<:Bool), var"253", var"254", var"255", Symbol, var"256", Float64, var"257", var"258", var"259", var"260", var"261", var"262"} <: 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.

source
Causal.RLCSystemType
mutable struct RLCSystem{T1<:Real, T2<:Real, T3<:Real, RH, RO, IP<:(Union{var"#s301", var"#s300"} where var"#s300"<:Nothing where var"#s301"<:Inport), OP<:(Union{var"#s299", var"#s298"} where var"#s298"<:Nothing where var"#s299"<:Outport), T4<:(AbstractArray{var"#s297",1} where var"#s297"<:Real), T5<:(AbstractArray{var"#s296",1} where var"#s296"<:Real), T6<:(AbstractArray{var"#s295",1} where var"#s295"<:Bool), var"253", var"254", var"255", Symbol, var"256", Float64, var"257", var"258", var"259", var"260", var"261", var"262"} <: 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.

source