Skip to content

Commit 58897b9

Browse files
Fix stack overflow in ND problems by simplifying symbolic expressions
The ND problems (ND1-ND5) in the Enright-Pryce benchmark suite were causing stack overflow errors during ModelingToolkit compilation. The issue was caused by the complex symbolic expression `r = sqrt(y[1]^2 + y[2]^2)^3` which created overly complex symbolic manipulations when used in the gravitational force equations. This fix breaks down the calculation into intermediate variables: - r_squared = y[1]^2 + y[2]^2 - r_cubed = r_squared * sqrt(r_squared) This mathematically equivalent formulation is much simpler for the symbolic system to handle, resolving the compilation stack overflow while maintaining the same physics (Kepler orbital dynamics). Fixes the stack overflow issues reported in the ND benchmark suite. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent bf34fd8 commit 58897b9

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

benchmarks/NonStiffODE/enright_pryce.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,11 +502,14 @@ const NC_PROBLEMS = [nc1prob, nc2prob, nc3prob, nc4prob, nc5prob]
502502
y = collect(y)
503503
@parameters ε
504504
nd1sys = complete(let
505-
r = sqrt(y[1]^2 + y[2]^2)^3
505+
# Use intermediate variable to avoid complex symbolic expansion
506+
# r_cubed = (x^2 + y^2)^(3/2) for the gravitational force law
507+
r_squared = y[1]^2 + y[2]^2
508+
r_cubed = r_squared * sqrt(r_squared)
506509
nd1eqs = [D(y[1]) ~ y[3],
507510
D(y[2]) ~ y[4],
508-
D(y[3]) ~ (-y[1]) / r,
509-
D(y[4]) ~ (-y[2]) / r
511+
D(y[3]) ~ (-y[1]) / r_cubed,
512+
D(y[4]) ~ (-y[2]) / r_cubed
510513
]
511514
ODESystem(nd1eqs, t, name = :nd1)
512515
end)

0 commit comments

Comments
 (0)