An acausal modeling framework for automatically parallelized scientific machine learning (SciML) in Julia. A computer algebra system for integrated symbolics for physics-informed machine learning and automated transformations of differential equations
I'm modeling the Circular Restricted Three-body Problem within AstrodynamicalModels.jl. I can create an ODEFunction from the ODESystem for a dense output, but only 14 elements are non-zero in the Jacobian, so I'd like to sparsify.
I think this is a bug? Sorry, I'm not super familiar with sparse math and could be missing something in the implementation / modeling syntax. Thanks for any guidance anyone can provide.
"""
A `ModelingToolkit.ODESystem` for the Circular Restricted Three-body Problem,
with the local linearization included in the state vector and dynamics.
"""
CR3BPWithSTM = let
@parameters t μ
@variables x(t) y(t) z(t) ẋ(t) ẏ(t) ż(t) Φ[1:6,1:6](t)
δ = Differential(t)
r = @SVector [x,y,z]
v = @SVector [ẋ,ẏ,ż]
# Potential energy of spacecraft (this code was symbolically generated with Symbolics.jl, then copied and pasted)
U = μ*(sqrt((μ + x - 1)^2 + y^2 + z^2)^-1) + (1//2) * (x^2) + (1//2) * (y^2) + (sqrt(y^2 + z^2 + (μ + x)^2)^-1)*(1 - μ)
# Hessian of potential energy
H = Symbolics.hessian(U, r)
eqs = let
LHS = [δ(Φ[i,j]) for j in 1:size(Φ,2) for i in 1:size(Φ,1)]
RHS = vec(vcat(
Matrix{Float64}(hcat(zeros(3,3), I(3))),
hcat(H, Float64[0 2 0; -2 0 0; 0 0 0])
) * Φ)
@assert length(LHS) == length(RHS) == 36 "If this assertion fails, please file an issue at https://github.com/cadojo/AstrodynamicalModels.jl!"
[LHS[i] ~ RHS[i] for i in 1:length(LHS)]
end
@named CR3BPWithSTM = ODESystem(vcat(equations(CR3BP)..., eqs...), t, vcat(r,v,Φ...), [μ])
end
"""
A `DifferentialEquations`-compatible `ODEFunction` for R2BP dynamics.
Note that this function has several methods, including an in-place
method! Function signatures follow `ModelingToolkit` and `DifferentialEquations`
conventions.
"""
CR3BPWithSTMVectorField = ODEFunction(CR3BPWithSTM; jac = true, tgrad = false, sparse = true)
I'm modeling the Circular Restricted Three-body Problem within AstrodynamicalModels.jl. I can create an
ODEFunction
from theODESystem
for a dense output, but only 14 elements are non-zero in the Jacobian, so I'd like to sparsify.I think this is a bug? Sorry, I'm not super familiar with sparse math and could be missing something in the implementation / modeling syntax. Thanks for any guidance anyone can provide.