Skip to content

Commit ef8171a

Browse files
Merge pull request #2510 from SciML/dd
Expose a non dummy derivative index lowering
2 parents 78ec2b2 + e9d5259 commit ef8171a

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

src/structural_transformation/StructuralTransformations.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export tearing, partial_state_selection, dae_index_lowering, check_consistency
5454
export dummy_derivative
5555
export build_torn_function, build_observed_function, ODAEProblem
5656
export sorted_incidence_matrix,
57-
pantelides!, tearing_reassemble, find_solvables!,
57+
pantelides!, pantelides_reassemble, tearing_reassemble, find_solvables!,
5858
linear_subsys_adjmat!
5959
export tearing_assignments, tearing_substitution
6060
export torn_system_jacobian_sparsity

src/systems/systemstructure.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ end
616616

617617
function _structural_simplify!(state::TearingState, io; simplify = false,
618618
check_consistency = true, fully_determined = true, warn_initialize_determined = false,
619+
dummy_derivative = true,
619620
kwargs...)
620621
check_consistency &= fully_determined
621622
has_io = io !== nothing
@@ -628,7 +629,13 @@ function _structural_simplify!(state::TearingState, io; simplify = false,
628629
if check_consistency
629630
ModelingToolkit.check_consistency(state, orig_inputs)
630631
end
631-
if fully_determined
632+
if fully_determined && dummy_derivative
633+
sys = ModelingToolkit.dummy_derivative(sys, state; simplify, mm, check_consistency)
634+
elseif fully_determined
635+
var_eq_matching = pantelides!(state; finalize = false, kwargs...)
636+
sys = pantelides_reassemble(state, var_eq_matching)
637+
state = TearingState(sys)
638+
sys, mm = ModelingToolkit.alias_elimination!(state; kwargs...)
632639
sys = ModelingToolkit.dummy_derivative(sys, state; simplify, mm, check_consistency)
633640
else
634641
sys = ModelingToolkit.tearing(sys, state; simplify, mm, check_consistency)

test/structural_transformation/index_reduction.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,19 @@ let sys = structural_simplify(pendulum2)
155155
@test sol.retcode == ReturnCode.Success
156156
@test norm(sol[x] .^ 2 + sol[y] .^ 2 .- 1) < 1e-2
157157
end
158+
159+
let
160+
@parameters g
161+
@variables x(t) [state_priority = 10] y(t) λ(t)
162+
163+
eqs = [D(D(x)) ~ λ * x
164+
D(D(y)) ~ λ * y - g
165+
x^2 + y^2 ~ 1]
166+
@named pend = ODESystem(eqs, t)
167+
sys = complete(structural_simplify(pend; dummy_derivative = false))
168+
prob = ODEProblem(
169+
sys, [x => 1, y => 0, D(x) => 0.0], (0.0, 10.0), [g => 1], guesses ==> 0.0])
170+
sol = solve(prob, Rodas5P())
171+
@test SciMLBase.successful_retcode(sol)
172+
@test sol[x^2 + y^2][end] < 1.1
173+
end

0 commit comments

Comments
 (0)