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
— TypeDAESystem(; righthandside, readout, state, stateder, diffvars, input, output)
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
— TypeRobertsonSystem()
Constructs a Robertson systme with the dynamcis
Causal.PendulumSystem
— TypePendulumSystem()
Constructs a Pendulum systme with the dynamics
where $F$ is the external force, $l$ is the length, $m$ is the mass and $g$ is the accelaration of gravity.
Causal.RLCSystem
— TypeRLCSystem()
Construsts a RLC system with the dynamics
where $F$ is the external force, $l$ is the length, $m$ is the mass and $g$ is the accelaration of gravity.