Skip to content

Commit 0d14c93

Browse files
refactor: remove vars, vars!
1 parent 83dc56b commit 0d14c93

File tree

1 file changed

+0
-84
lines changed

1 file changed

+0
-84
lines changed

src/utils.jl

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -426,90 +426,6 @@ function isvariable(x)
426426
hasmetadata(x, VariableSource) || iscall(x) && operation(x) === getindex && isvariable(arguments(x)[1])::Bool
427427
end
428428

429-
"""
430-
vars(x; op=Differential)
431-
432-
Return a `Set` containing all variables in `x` that appear in
433-
434-
- differential equations if `op = Differential`
435-
436-
Example:
437-
438-
```
439-
t = ModelingToolkit.t_nounits
440-
@variables u(t) y(t)
441-
D = Differential(t)
442-
v = ModelingToolkit.vars(D(y) ~ u)
443-
v == Set([D(y), u])
444-
```
445-
"""
446-
function vars(exprs::SymbolicT; op = Differential)
447-
iscall(exprs) ? vars([exprs]; op = op) : Set([exprs])
448-
end
449-
vars(exprs::Num; op = Differential) = vars(unwrap(exprs); op)
450-
vars(exprs::Symbolics.Arr; op = Differential) = vars(unwrap(exprs); op)
451-
function vars(exprs; op = Differential)
452-
if hasmethod(iterate, Tuple{typeof(exprs)})
453-
foldl((x, y) -> vars!(x, unwrap(y); op = op), exprs; init = Set())
454-
else
455-
vars!(Set(), unwrap(exprs); op)
456-
end
457-
end
458-
vars(eq::Equation; op = Differential) = vars!(Set(), eq; op = op)
459-
function vars!(vars, eq::Equation; op = Differential)
460-
(vars!(vars, eq.lhs; op = op); vars!(vars, eq.rhs; op = op); vars)
461-
end
462-
function vars!(vars, O::AbstractSystem; op = Differential)
463-
for eq in equations(O)
464-
vars!(vars, eq; op)
465-
end
466-
return vars
467-
end
468-
function vars!(vars, O; op = Differential)
469-
if isvariable(O)
470-
if iscall(O) && operation(O) === getindex && iscalledparameter(first(arguments(O)))
471-
O = first(arguments(O))
472-
end
473-
if iscalledparameter(O)
474-
f = getcalledparameter(O)
475-
push!(vars, f)
476-
for arg in arguments(O)
477-
if symbolic_type(arg) == NotSymbolic() && arg isa AbstractArray
478-
for el in arg
479-
vars!(vars, unwrap(el); op)
480-
end
481-
else
482-
vars!(vars, arg; op)
483-
end
484-
end
485-
return vars
486-
end
487-
return push!(vars, O)
488-
end
489-
if symbolic_type(O) == NotSymbolic() && O isa AbstractArray
490-
for arg in O
491-
vars!(vars, unwrap(arg); op)
492-
end
493-
return vars
494-
end
495-
!iscall(O) && return vars
496-
497-
operation(O) isa op && return push!(vars, O)
498-
499-
if operation(O) === (getindex)
500-
arr = first(arguments(O))
501-
iscall(arr) && operation(arr) isa op && return push!(vars, O)
502-
isvariable(arr) && return push!(vars, O)
503-
end
504-
505-
isvariable(operation(O)) && push!(vars, O)
506-
for arg in arguments(O)
507-
vars!(vars, arg; op = op)
508-
end
509-
510-
return vars
511-
end
512-
513429
function collect_operator_variables(sys::AbstractSystem, args...)
514430
collect_operator_variables(equations(sys), args...)
515431
end

0 commit comments

Comments
 (0)