Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ function collect_ivs_from_nested_operator!(ivs, x, target_op)
end

function iv_from_nested_derivative(x, op = Differential)
if iscall(x) && operation(x) == getindex
if iscall(x) &&
(operation(x) == getindex || operation(x) == real || operation(x) == imag)
iv_from_nested_derivative(arguments(x)[1], op)
elseif iscall(x)
operation(x) isa op ? iv_from_nested_derivative(arguments(x)[1], op) :
Expand Down Expand Up @@ -1204,6 +1205,7 @@ end
Find all the unknowns and parameters from the equations of a SDESystem or ODESystem. Return re-ordered equations, differential variables, all variables, and parameters.
"""
function process_equations(eqs, iv)
eltype(eqs) <: Vector && (eqs = vcat(eqs...))
eqs = collect(eqs)

diffvars = OrderedSet()
Expand Down Expand Up @@ -1237,8 +1239,8 @@ function process_equations(eqs, iv)
throw(ArgumentError("An ODESystem can only have one independent variable."))
diffvar in diffvars &&
throw(ArgumentError("The differential variable $diffvar is not unique in the system of equations."))
!(symtype(diffvar) === Real || eltype(symtype(diffvar)) === Real) &&
throw(ArgumentError("Differential variable $diffvar has type $(symtype(diffvar)). Differential variables should not be concretely typed."))
!has_diffvar_type(diffvar) &&
throw(ArgumentError("Differential variable $diffvar has type $(symtype(diffvar)). Differential variables should be of a continuous, non-concrete number type: Real, Complex, AbstractFloat, or Number."))
push!(diffvars, diffvar)
end
push!(diffeq, eq)
Expand All @@ -1250,6 +1252,13 @@ function process_equations(eqs, iv)
diffvars, allunknowns, ps, Equation[diffeq; algeeq; compressed_eqs]
end

function has_diffvar_type(diffvar)
st = symtype(diffvar)
st === Real || eltype(st) === Real || st === Complex || eltype(st) === Complex ||
st === Number || eltype(st) === Number || st === AbstractFloat ||
eltype(st) === AbstractFloat
end

"""
$(TYPEDSIGNATURES)

Expand Down
4 changes: 4 additions & 0 deletions test/odesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1589,6 +1589,10 @@ end
@variables Y(t)[1:3]::String
eq = D(Y) ~ [p, p, p]
@test_throws ArgumentError @mtkbuild osys = ODESystem([eq], t)

@variables X(t)::Complex
eq = D(X) ~ p - d * X
@test_nowarn @named osys = ODESystem([eq], t)
end

# Test `isequal`
Expand Down
Loading