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
11 changes: 11 additions & 0 deletions docs/src/tutorials/initialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -536,3 +536,14 @@ sol[α * x - β * x * y]
```@example init
plot(sol)
```

## Summary of Initialization API

```@docs; canonical=false
Initial
isinitial
generate_initializesystem
initialization_equations
guesses
defaults
```
2 changes: 1 addition & 1 deletion src/ModelingToolkit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export toexpr, get_variables
export simplify, substitute
export build_function
export modelingtoolkitize
export generate_initializesystem, Initial
export generate_initializesystem, Initial, isinitial

export alg_equations, diff_equations, has_alg_equations, has_diff_equations
export get_alg_eqs, get_diff_eqs, has_alg_eqs, has_diff_eqs
Expand Down
16 changes: 16 additions & 0 deletions src/systems/abstractsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@
"""
Initial(x)

The `Initial` operator. Used by initializaton to store constant constraints on variables

Check warning on line 625 in src/systems/abstractsystem.jl

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"initializaton" should be "initialization".
of a system. See the documentation section on initialization for more information.
"""
struct Initial <: Symbolics.Operator end
Expand Down Expand Up @@ -717,6 +717,22 @@
return sys
end

"""
Returns true if the parameter `p` is of the form `Initial(x)`.
"""
function isinitial(p)
p = unwrap(p)
if iscall(p)
operation(p) isa Initial && return true
if operation(p) === getindex
operation(arguments(p)[1]) isa Initial && return true
end
else
return false
end
return false
end

"""
$(TYPEDSIGNATURES)

Expand Down
13 changes: 13 additions & 0 deletions test/variable_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,16 @@ end
@test isequal(parse_variable(sys, str), var)
end
end

@testset "isinitial" begin
t = ModelingToolkit.t_nounits
@variables x(t) z(t)[1:5]
@parameters a b c[1:4]
@test isinitial(Initial(z))
@test isinitial(Initial(x))
@test isinitial(Initial(a))
@test isinitial(Initial(z[1]))
@test isinitial(Initial(c[4]))
@test !isinitial(c)
@test !isinitial(x)
end
Loading