Skip to content

Commit a07e8e3

Browse files
authored
Merge pull request #2203 from Keno/kf/tearingsingle
tearing: Heuristically attempt to assign equations with single solvab…
2 parents 9c58a2a + 17448ed commit a07e8e3

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/structural_transformation/bipartite_tearing/modia_tearing.jl

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,22 @@ function tearEquations!(ict::IncrementalCycleTracker, Gsolvable, es::Vector{Int}
3232
end
3333
end
3434
end
35-
for eq in es # iterate only over equations that are not in eSolvedFixed
36-
vs = Gsolvable[eq]
37-
if check_der
38-
# if there're differentiated variables, then only consider them
39-
try_assign_eq!(ict, vs, v_active, eq, isder)
40-
if has_der[]
41-
has_der[] = false
42-
continue
35+
# Heuristic: As a first pass, try to assign any equations that only have one
36+
# solvable variable.
37+
for only_single_solvable in (true, false)
38+
for eq in es # iterate only over equations that are not in eSolvedFixed
39+
vs = Gsolvable[eq]
40+
((length(vs) == 1) only_single_solvable) && continue
41+
if check_der
42+
# if there're differentiated variables, then only consider them
43+
try_assign_eq!(ict, vs, v_active, eq, isder)
44+
if has_der[]
45+
has_der[] = false
46+
continue
47+
end
4348
end
49+
try_assign_eq!(ict, vs, v_active, eq)
4450
end
45-
try_assign_eq!(ict, vs, v_active, eq)
4651
end
4752

4853
return ict

test/nonlinearsystem.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ D = Differential(t)
113113
@named subsys = convert_system(ODESystem, lorenz1, t)
114114
@named sys = ODESystem([D(subsys.x) ~ subsys.x + subsys.x], t, systems = [subsys])
115115
sys = structural_simplify(sys)
116-
u0 = [subsys.x => 1, subsys.z => 2.0]
116+
u0 = [subsys.x => 1, subsys.z => 2.0, subsys.y => 1.0]
117117
prob = ODEProblem(sys, u0, (0, 1.0), [subsys.σ => 1, subsys.ρ => 2, subsys.β => 3])
118-
sol = solve(prob, Rodas5())
119-
@test sol[subsys.x] + sol[subsys.y] - sol[subsys.z] sol[subsys.u]
118+
sol = solve(prob, FBDF(), reltol = 1e-7, abstol = 1e-7)
119+
@test sol[subsys.x] + sol[subsys.y] - sol[subsys.z]sol[subsys.u] atol=1e-7
120120
@test_throws ArgumentError convert_system(ODESystem, sys, t)
121121

122122
@parameters t σ ρ β

0 commit comments

Comments
 (0)