diff --git a/src/Blocks/continuous.jl b/src/Blocks/continuous.jl index 81a78aa0a..de76b19cd 100644 --- a/src/Blocks/continuous.jl +++ b/src/Blocks/continuous.jl @@ -20,7 +20,7 @@ Initial value of integrator state ``x`` can be set with `x` @mtkmodel Integrator begin @extend u, y = siso = SISO() @variables begin - x(t) = 0.0, [description = "State of Integrator"] + x(t), [guess = 0.0, description = "State of Integrator"] end @parameters begin k = 1, [description = "Gain"] @@ -65,7 +65,7 @@ Initial value of the state ``x`` can be set with `x`. @mtkmodel Derivative begin @extend u, y = siso = SISO() @variables begin - x(t) = 0.0, [description = "Derivative-filter state"] + x(t), [guess = 0.0, description = "Derivative-filter state"] end @parameters begin T = T, [description = "Time constant"] @@ -122,7 +122,7 @@ See also [`SecondOrder`](@ref) lowpass = true end @variables begin - x(t) = 0.0, [description = "State of FirstOrder filter"] + x(t), [guess = 0.0, description = "State of FirstOrder filter"] end @parameters begin T = T, [description = "Time constant"] @@ -545,7 +545,7 @@ linearized around the operating point `x₀, u₀`, we have `y0, u0 = h(x₀, u end @named input = RealInput(nin = nu) @named output = RealOutput(nout = ny) - @variables x(t)[1:nx]=x [ + @variables x(t)[1:nx]=x [ # FIXME: should it be guess = x, not default? description = "State variables of StateSpace system $name" ] # pars = @parameters A=A B=B C=C D=D # This is buggy @@ -618,7 +618,7 @@ See also [`StateSpace`](@ref) which handles MIMO systems, as well as [ControlSys @parameters a_end = ifelse(a[end] > 100 * symbolic_eps(sqrt(a' * a)), a[end], 1.0) pars = [collect(b); a; collect(bb); d; a_end] - @variables begin + @variables begin # FIXME: should it be guesses, not default? x(t)[1:nx] = zeros(nx), [description = "State of transfer function on controller canonical form"] x_scaled(t)[1:nx] = collect(x) * a_end, [description = "Scaled vector x"] diff --git a/src/Blocks/utils.jl b/src/Blocks/utils.jl index 10ad0261f..f6d72cdec 100644 --- a/src/Blocks/utils.jl +++ b/src/Blocks/utils.jl @@ -115,36 +115,47 @@ Connector with an array of output signals of type Real. """ RealOutputArray """ - SISO(;name, u_start = 0.0, y_start = 0.0) + SISO(;name, u_guess = 0.0, y_guess = 0.0) Single input single output (SISO) continuous system block. # Parameters: - - `u_start`: Initial value for the input - - `y_start`: Initial value for the output + - `u_guess`: Initial value for the input + - `y_guess`: Initial value for the output """ -@mtkmodel SISO begin - @parameters begin - u_start = 0.0 - y_start = 0.0 +@component function SISO(; name, u_start = nothing, y_start = nothing, u_guess = 0.0, y_guess = 0.0) + if u_start !== nothing + Base.depwarn( + "The keyword argument `u_start` is deprecated. Use `u_guess` instead.", :u_start) + u_guess = u_start end - @variables begin - u(t) = u_start, [description = "Input of SISO system"] - y(t) = y_start, [description = "Output of SISO system"] + if y_start !== nothing + Base.depwarn( + "The keyword argument `y_start` is deprecated. Use `u_guess` instead.", :y_start) + y_guess = y_start end - @components begin - input = RealInput(guess = u_start) - output = RealOutput(guess = y_start) + pars = @parameters begin + u_guess = u_guess + y_guess = y_guess end - @equations begin + vars = @variables begin + u(t), [guess = u_guess, description = "Input of SISO system"] + y(t), [guess = y_guess, description = "Output of SISO system"] + end + + @named input = RealInput(guess = u_guess) + @named output = RealOutput(guess = y_guess) + + eqs = [ u ~ input.u y ~ output.u - end + ] + return ODESystem(eqs, t, vars, pars; name = name, systems = [input, output]) end """ - MIMO(; name, nin = 1, nout = 1, u_start = zeros(nin), y_start = zeros(nout)) + MIMO(; name, nin = 1, nout = 1, u_guess = zeros(nin), y_guess = zeros(nout)) Base class for a multiple input multiple output (MIMO) continuous system block. @@ -152,15 +163,26 @@ Base class for a multiple input multiple output (MIMO) continuous system block. - `nin`: Input dimension - `nout`: Output dimension - - `u_start`: Initial value for the input + - `u_guess`: Initial value for the input - `y_start`: Initial value for the output """ -@component function MIMO(; name, nin = 1, nout = 1, u_start = zeros(nin), - y_start = zeros(nout)) - @named input = RealInput(nin = nin, guess = u_start) - @named output = RealOutput(nout = nout, guess = y_start) - @variables(u(t)[1:nin]=u_start, [description = "Input of MIMO system $name"], - y(t)[1:nout]=y_start, [description = "Output of MIMO system $name"],) +@component function MIMO(; name, nin = 1, nout = 1, u_start = nothing, y_start = nothing, u_guess = nin > 1 ? zeros(nin) : 0.0, y_guess = nout > 1 ? zeros(nout) : 0.0) + if u_start !== nothing + Base.depwarn( + "The keyword argument `u_start` is deprecated. Use `u_guess` instead.", :u_start) + u_guess = u_start + end + if y_start !== nothing + Base.depwarn( + "The keyword argument `y_start` is deprecated. Use `y_guess` instead.", :y_start) + y_guess = y_start + end + @named input = RealInputArray(nin = nin, guess = u_guess) + @named output = RealOutputArray(nout = nout, guess = y_guess) + @variables begin + u(t)[1:nin], [guess = u_guess, description = "Input of MIMO system $name"] + y(t)[1:nout], [guess = y_guess, description = "Output of MIMO system $name"] + end eqs = [ [u[i] ~ input.u[i] for i in 1:nin]..., [y[i] ~ output.u[i] for i in 1:nout]... diff --git a/src/Thermal/HeatTransfer/ideal_components.jl b/src/Thermal/HeatTransfer/ideal_components.jl index fc6858bbf..70dfe446c 100644 --- a/src/Thermal/HeatTransfer/ideal_components.jl +++ b/src/Thermal/HeatTransfer/ideal_components.jl @@ -24,8 +24,8 @@ Lumped thermal element storing heat C, [description = "Heat capacity of element"] end @variables begin - T(t) = 273.15 + 20 - der_T(t) + T(t), [guess = 273.15 + 20] + der_T(t), [guess = 0.0] end @equations begin diff --git a/src/Thermal/utils.jl b/src/Thermal/utils.jl index e2a991494..fe50d4c7d 100644 --- a/src/Thermal/utils.jl +++ b/src/Thermal/utils.jl @@ -1,6 +1,6 @@ @connector HeatPort begin T(t) = 273.15 + 20.0 - Q_flow(t), [connect = Flow] + Q_flow(t) = 0.0, [connect = Flow] end Base.@doc """ HeatPort(; name, T = 273.15 + 20.0, Q_flow = 0.0) @@ -35,8 +35,8 @@ flow rate through the element from `port_a` to `port_b`, `Q_flow`. port_b = HeatPort() end @variables begin - dT(t) - Q_flow(t) + dT(t) = 0.0 + Q_flow(t) = 0.0 end @equations begin dT ~ port_a.T - port_b.T @@ -69,8 +69,8 @@ flow rate through the element from `solid` to `fluid`, `Q_flow`. fluid = HeatPort() end @variables begin - dT(t) - Q_flow(t) + dT(t) = 0.0 + Q_flow(t) = 0.0 end @equations begin dT ~ solid.T - fluid.T