Skip to content

Commit 2ddd7a1

Browse files
committed
factor complete to _complete
1 parent 9c415dc commit 2ddd7a1

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

src/systems/abstractsystem.jl

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -734,17 +734,15 @@ function isinitial(p)
734734
end
735735

736736
"""
737-
$(TYPEDSIGNATURES)
738-
739-
Mark a system as completed. A completed system is a system which is done being
740-
defined/modified and is ready for structural analysis or other transformations.
741-
This allows for analyses and optimizations to be performed which require knowing
742-
the global structure of the system.
737+
Allow systems to dispatch `complete` but still get at the underlying functionality it
738+
implements in a uniform way.
743739
744-
One property to note is that if a system is complete, the system will no longer
745-
namespace its subsystems or variables, i.e. `isequal(complete(sys).v.i, v.i)`.
740+
Notes:
741+
- `allow_additional_ps = true` is used to allow additional parameters to be added to the
742+
system during completion (such as initial conditions).
746743
"""
747-
function complete(sys::AbstractSystem; split = true, flatten = true)
744+
function _complete(sys::AbstractSystem; split = true, flatten = true,
745+
allow_additional_ps = true)
748746
newunknowns = OrderedSet()
749747
newparams = OrderedSet()
750748
iv = has_iv(sys) ? get_iv(sys) : nothing
@@ -765,7 +763,9 @@ function complete(sys::AbstractSystem; split = true, flatten = true)
765763
@set! newsys.parent = complete(sys; split = false, flatten = false)
766764
end
767765
sys = newsys
768-
sys = add_initialization_parameters(sys)
766+
if allow_additional_ps
767+
sys = add_initialization_parameters(sys)
768+
end
769769
end
770770
if split && has_index_cache(sys)
771771
@set! sys.index_cache = IndexCache(sys)
@@ -801,6 +801,21 @@ function complete(sys::AbstractSystem; split = true, flatten = true)
801801
isdefined(sys, :complete) ? (@set! sys.complete = true) : sys
802802
end
803803

804+
"""
805+
$(TYPEDSIGNATURES)
806+
807+
Mark a system as completed. A completed system is a system which is done being
808+
defined/modified and is ready for structural analysis or other transformations.
809+
This allows for analyses and optimizations to be performed which require knowing
810+
the global structure of the system.
811+
812+
One property to note is that if a system is complete, the system will no longer
813+
namespace its subsystems or variables, i.e. `isequal(complete(sys).v.i, v.i)`.
814+
"""
815+
function complete(sys::AbstractSystem; split = true, flatten = true)
816+
_complete(sys; split, flatten)
817+
end
818+
804819
"""
805820
$(TYPEDSIGNATURES)
806821

test/odesystem.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,3 +1736,13 @@ end
17361736
@test obsfn_expr_oop isa Expr
17371737
@test obsfn_expr_iip isa Expr
17381738
end
1739+
1740+
@testset "`complete` with and without initial conditions" begin
1741+
@variables x(t)
1742+
@parameters p
1743+
@mtkbuild sys = ODESystem(D(x) ~ p * t, t)
1744+
@test issetequal(ModelingToolkit.get_ps(sys), [p, Initial(x)])
1745+
@named sys2 = ODESystem(D(x) ~ p * t, t)
1746+
sys2 = ModelingToolkit._complete(sys2; allow_additional_ps = false)
1747+
@test issetequal(ModelingToolkit.get_ps(sys2), [p])
1748+
end

0 commit comments

Comments
 (0)