Skip to content

Commit d691527

Browse files
feat: add Initial operator
1 parent 2cf6edc commit d691527

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/systems/abstractsystem.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,37 @@ function isscheduled(sys::AbstractSystem)
650650
end
651651
end
652652

653+
struct Initial <: Symbolics.Operator end
654+
Initial(x) = Initial()(x)
655+
SymbolicUtils.promote_symtype(::Type{Initial}, T) = T
656+
SymbolicUtils.isbinop(::Initial) = false
657+
Base.nameof(::Initial) = :Initial
658+
Base.show(io::IO, x::Initial) = print(io, "Initial")
659+
input_timedomain(::Initial, _ = nothing) = Continuous()
660+
output_timedomain(::Initial, _ = nothing) = Continuous()
661+
662+
function (f::Initial)(x)
663+
iw = Symbolics.iswrapped(x)
664+
x = unwrap(x)
665+
if iscall(x) && operation(x) isa Differential
666+
x = default_toterm(x)
667+
end
668+
iscall(x) && operation(x) isa Initial && return x
669+
result = if symbolic_type(x) == ArraySymbolic()
670+
Symbolics.array_term(f, toparam(x))
671+
elseif iscall(x) && operation(x) == getindex
672+
arr = arguments(x)[1]
673+
term(getindex, f(toparam(arr)), arguments(x)[2:end]...)
674+
else
675+
term(f, toparam(x))
676+
end
677+
result = toparam(result)
678+
if iw
679+
result = wrap(result)
680+
end
681+
return result
682+
end
683+
653684
"""
654685
$(TYPEDSIGNATURES)
655686

0 commit comments

Comments
 (0)