I re-wrote my astrodynamics functions with ModelingToolkit
. Now, when I call DifferentialEquations.solve(...)
in my wrapper function, it compiles every time. Is there any way to check what is compiling?
using StaticArrays
using AstrodynamicalModels
using DifferentialEquations
function propagate(r, v, T; kwargs...)
defaults = (; reltol=1e-14, abstol=1e-14, save_everystep=false)
options = merge(defaults, kwargs)
problem = ODEProblem(R2BP, MVector{6}(vcat(r,v)), (0.0, T), MVector{1}(398600.435))
solutions = solve(problem; options...)
end
r = randn(3) * 1e4
v = randn(3) * 1e3
T = 10_000.0
@time propagate(r,v,T) # 28.067676 seconds (93.98 M allocations: 5.404 GiB, 3.61% gc time)
@time propagate(r,v,T) # 7.187065 seconds (13.05 M allocations: 704.718 MiB, 1.34% gc time, 99.70% compilation time)
@time propagate(r,v,T) # 7.154281 seconds (13.06 M allocations: 705.808 MiB, 1.79% gc time, 99.43% compilation time)
If I don’t put the solver in a function, the behavior is fine.
using StaticArrays
using AstrodynamicalModels
using DifferentialEquations
defaults = (; reltol=1e-14, abstol=1e-14, save_everystep=false)
kwargs = (;)
options = merge(defaults, kwargs)
r = randn(3) * 1e4
v = randn(3) * 1e3
T = 10_000.0
problem = ODEProblem(R2BP, MVector{6}(vcat(r,v)), (0.0, T), MVector{1}(398600.435))
@time solutions = solve(problem; options...) # 15.728376 seconds (50.96 M allocations: 2.763 GiB, 4.17% gc time, 2.34% compilation time)
@time solutions = solve(problem; options...) # 0.012221 seconds (540.66 k allocations: 9.171 MiB)
@time solutions = solve(problem; options...) # 0.012453 seconds (540.66 k allocations: 9.171 MiB)
What am I doing wrong?