Skip to content

Commit 97c5324

Browse files
committed
feat: add
1 parent c412cd7 commit 97c5324

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

src/ModelingToolkit.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ export toexpr, get_variables
286286
export simplify, substitute
287287
export build_function
288288
export modelingtoolkitize
289-
export generate_initializesystem, Initial
289+
export generate_initializesystem, Initial, isInitial
290290

291291
export alg_equations, diff_equations, has_alg_equations, has_diff_equations
292292
export get_alg_eqs, get_diff_eqs, has_alg_eqs, has_diff_eqs

src/systems/abstractsystem.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,22 @@ function add_initialization_parameters(sys::AbstractSystem)
717717
return sys
718718
end
719719

720+
"""
721+
Returns true if the variable or parameter `var` is of the form `Initial(x)`.
722+
"""
723+
function isInitial(var)
724+
var = unwrap(var)
725+
if iscall(var)
726+
operation(var) isa Initial && return true
727+
if operation(var) === getindex
728+
operation(arguments(var)[1]) isa Initial && return true
729+
end
730+
else
731+
return false
732+
end
733+
return false
734+
end
735+
720736
"""
721737
$(TYPEDSIGNATURES)
722738

test/variable_utils.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,16 @@ end
145145
@test isequal(parse_variable(sys, str), var)
146146
end
147147
end
148+
149+
@testset "isInitial" begin
150+
t = ModelingToolkit.to_nounits
151+
@variables x(t) z(t)[1:5]
152+
@parameters a b c[1:4]
153+
@test isInitial(Initial(z))
154+
@test isInitial(Initial(x))
155+
@test isInitial(Initial(a))
156+
@test isInitial(Initial(z[1]))
157+
@test isInitial(Initial(c[4]))
158+
@test !isInitial(c)
159+
@test !isInitial(x)
160+
end

0 commit comments

Comments
 (0)