Skip to content

Commit 75e1641

Browse files
Use the dummy derivative to lower derivatives
1 parent 55bc7b3 commit 75e1641

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,11 @@ function _structural_simplify!(state::TearingState, io; simplify = false,
631631
end
632632
if fully_determined && dummy_derivative
633633
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 = ModelingToolkit.dummy_derivative(sys, state; simplify, mm, check_consistency)
634639
else
635640
sys = ModelingToolkit.tearing(sys, state; simplify, mm, check_consistency)
636641
end

test/structural_transformation/index_reduction.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,20 @@ 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 = [
164+
D(D(x)) ~ λ * x
165+
D(D(y)) ~ λ * y - g
166+
x^2 + y^2 ~ 1
167+
]
168+
@named pend = ODESystem(eqs,t)
169+
sys = complete(structural_simplify(pend; dummy_derivative = false))
170+
prob = ODEProblem(sys, [x => 1, y => 0, D(x) => 0.0], (0.0, 10.0), [g => 1], guesses ==> 0.0])
171+
sol = solve(prob,Rodas5P())
172+
@test SciMLBase.successful_retcode(sol)
173+
@test sol[x^2 + y^2][end] < 1.1
174+
end

0 commit comments

Comments
 (0)