From 90fa9c3fe671184b4d381eb5345be8c59cdd09d6 Mon Sep 17 00:00:00 2001 From: Fredrik Bagge Carlson Date: Fri, 28 Jan 2022 17:46:58 +0100 Subject: [PATCH] Closes #399 --- src/types/TransferFunction.jl | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/types/TransferFunction.jl b/src/types/TransferFunction.jl index 29175158a..21cb41812 100644 --- a/src/types/TransferFunction.jl +++ b/src/types/TransferFunction.jl @@ -1,12 +1,10 @@ struct TransferFunction{TE, S<:SisoTf{T} where T} <: LTISystem{TE} matrix::Matrix{S} timeevol::TE - nu::Int - ny::Int function TransferFunction{TE,S}(matrix::Matrix{S}, timeevol::TE) where {S,TE} # Validate size of input and output names ny, nu = size(matrix) - return new{TE,S}(matrix, timeevol, nu, ny) + return new{TE,S}(matrix, timeevol) end end function TransferFunction(matrix::Matrix{S}, timeevol::TE) where {TE<:TimeEvolution, T<:Number, S<:SisoTf{T}} @@ -35,6 +33,22 @@ Base.size(G::TransferFunction) = size(G.matrix) Base.eltype(::Type{S}) where {S<:TransferFunction} = S Base.zero(G::TransferFunction{TE,S}) where {TE,S} = tf(zeros(numeric_type(S), size(G)), G.timeevol) # can not create a zero of a discrete system from the type alone, the sampletime is not stored. +function Base.getproperty(G::TransferFunction, s::Symbol) + s ∈ fieldnames(typeof(G)) && return getfield(G, s) + if s === :ny + return size(G, 1) + elseif s === :nu + return size(G, 2) + elseif s === :Ts + if isdiscrete(G) + return timeevol(G).Ts + else + @warn "Getting time 0.0 for non-discrete systems is deprecated. Check `isdiscrete` before trying to access time." + return 0.0 + end + throw(ArgumentError("$(typeof(G)) has no property named $s")) + end +end function Base.getindex(G::TransferFunction{TE,S}, inds...) where {TE,S<:SisoTf} if size(inds, 1) != 2