Skip to content

Commit c988e2b

Browse files
refactor: default allow_algebraic to fully_determined
1 parent 4a7b12d commit c988e2b

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/systems/diffeqs/abstractodesystem.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,6 +1455,7 @@ function InitializationProblem{iip, specialize}(sys::AbstractSystem,
14551455
allow_incomplete = false,
14561456
force_time_independent = false,
14571457
algebraic_only = false,
1458+
allow_algebraic = nothing,
14581459
kwargs...) where {iip, specialize}
14591460
if !iscomplete(sys)
14601461
error("A completed system is required. Call `complete` or `structural_simplify` on the system before creating an `ODEProblem`")
@@ -1482,7 +1483,7 @@ function InitializationProblem{iip, specialize}(sys::AbstractSystem,
14821483
end
14831484

14841485
if simplify_system
1485-
isys = structural_simplify(isys; fully_determined)
1486+
isys = structural_simplify(isys; fully_determined, allow_algebraic)
14861487
end
14871488

14881489
meta = get_metadata(isys)

src/systems/systems.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,20 @@ topological sort of the observed equations in `sys`.
2525
### Optional Keyword Arguments:
2626
+ When `simplify=true`, the `simplify` function will be applied during the tearing
2727
process.
28-
+ `allow_symbolic=false`, `allow_algebraic=true`, `allow_parameter=true`, and
28+
+ `allow_symbolic=false`, `allow_algebraic=nothing`, `allow_parameter=true`, and
2929
`conservative=false` limit the coefficient types during tearing. In particular,
3030
`conservative=true` limits tearing to only solve for trivial linear systems where
3131
the coefficient has the absolute value of ``1``. `allow_symbolic` allows arbitrary
3232
symbolic coefficients. If it is false, `allow_algebraic` allows symbolic coefficients
3333
involving only algebraic variables and parameters. Otherwise, `allow_parameter` only
34-
allows coefficients containing parameters.
34+
allows coefficients containing parameters. `allow_algebraic` defaults to
35+
`fully_determined` if `nothing`.
3536
+ `fully_determined=true` controls whether or not an error will be thrown if the number
3637
of equations don't match the number of inputs, outputs, and equations.
3738
"""
3839
function structural_simplify(
3940
sys::AbstractSystem, io = nothing; additional_passes = [], simplify = false, split = true,
40-
allow_symbolic = false, allow_algebraic = true, allow_parameter = true, conservative = false,
41+
allow_symbolic = false, allow_algebraic = nothing, allow_parameter = true, conservative = false,
4142
fully_determined = true, kwargs...)
4243
isscheduled(sys) && throw(RepeatedStructuralSimplificationError())
4344
newsys′ = __structural_simplify(sys, io; simplify, allow_symbolic, allow_algebraic,

src/systems/systemstructure.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ end
693693

694694
function _structural_simplify!(state::TearingState, io; simplify = false,
695695
check_consistency = true, fully_determined = true, warn_initialize_determined = false,
696-
dummy_derivative = true, allow_symbolic = false,
696+
dummy_derivative = true, allow_symbolic = false, allow_algebraic = nothing,
697697
kwargs...)
698698
if fully_determined isa Bool
699699
check_consistency &= fully_determined
@@ -710,11 +710,18 @@ function _structural_simplify!(state::TearingState, io; simplify = false,
710710
else
711711
input_idxs = 0:-1 # Empty range
712712
end
713-
sys, mm = ModelingToolkit.alias_elimination!(state; allow_symbolic, kwargs...)
713+
# use `false` for alias elimination since it doesn't really care about `allow_alebraic`
714+
# anyway
715+
_allow_algebraic = something(allow_algebraic, false)
716+
sys, mm = ModelingToolkit.alias_elimination!(
717+
state; allow_symbolic, allow_algebraic = _allow_algebraic, kwargs...)
714718
if check_consistency
715719
fully_determined = ModelingToolkit.check_consistency(
716720
state, orig_inputs; nothrow = fully_determined === nothing)
717721
end
722+
if allow_algebraic === nothing
723+
allow_algebraic = fully_determined
724+
end
718725
if fully_determined && dummy_derivative
719726
sys = ModelingToolkit.dummy_derivative(
720727
sys, state; simplify, mm, check_consistency, allow_symbolic, kwargs...)

0 commit comments

Comments
 (0)