From a4a53f4a70e5728ba038a212535b475e499eb9bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20A=2E=20P=C3=A9rez-Hern=C3=A1ndez?= Date: Mon, 1 Apr 2024 13:21:57 +0200 Subject: [PATCH 1/7] Update CI.yml --- .github/workflows/CI.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index de33a42..3eb8edf 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -4,8 +4,6 @@ on: paths-ignore: - 'LICENSE.md' - 'README.md' - tags: ['*'] - pull_request: concurrency: # Skip intermediate builds: always. # Cancel intermediate builds: only if it is a pull request build. From 46fb102c69009cf9203d92b4417cf8053fe9138d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20A=2E=20P=C3=A9rez-Hern=C3=A1ndez?= Date: Mon, 1 Apr 2024 11:59:30 +0200 Subject: [PATCH 2/7] Move TaylorInterpolantNSerialization over from NEOs --- Project.toml | 2 +- src/PlanetaryEphemeris.jl | 4 +- .../TaylorInterpolant.jl} | 80 +------------------ 3 files changed, 5 insertions(+), 81 deletions(-) rename src/{interpolation.jl => interpolation/TaylorInterpolant.jl} (81%) diff --git a/Project.toml b/Project.toml index 1ca3457..b56cf65 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "PlanetaryEphemeris" uuid = "d83715d0-7e5f-11e9-1a59-4137b20d8363" authors = ["Jorge A. Pérez Hernández", "Luis Benet", "Luis Eduardo Ramírez Montoya"] -version = "0.8.1" +version = "0.8.2" [deps] ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63" diff --git a/src/PlanetaryEphemeris.jl b/src/PlanetaryEphemeris.jl index 5f82e79..bb67b67 100644 --- a/src/PlanetaryEphemeris.jl +++ b/src/PlanetaryEphemeris.jl @@ -26,7 +26,9 @@ import JLD2: writeas include("constants.jl") include("jpl-de-430-431-earth-orientation-model.jl") include("initial_conditions.jl") -include("interpolation.jl") +include("interpolation/TaylorInterpolant.jl") +include("interpolation/PlanetaryEphemerisSerialization.jl") +include("interpolation/TaylorInterpolantNSerialization.jl") include("propagation.jl") include("osculating.jl") include("barycenter.jl") diff --git a/src/interpolation.jl b/src/interpolation/TaylorInterpolant.jl similarity index 81% rename from src/interpolation.jl rename to src/interpolation/TaylorInterpolant.jl index 300fb85..75d4692 100644 --- a/src/interpolation.jl +++ b/src/interpolation/TaylorInterpolant.jl @@ -206,7 +206,7 @@ function selecteph(eph::TaylorInterpolant, bodyind::Union{Int, AbstractVector{In end # Degrees of freedom N = numberofbodies(eph) - @assert all(bodyind .< N) "bodyind .< $N" + @assert all(bodyind .< N) "bodyind .< $N" idxs = nbodyind(N, bodyind) if euler idxs = vcat(idxs, 6N+1:6N+12) @@ -256,81 +256,3 @@ function auday2kmsec(pv) pv[4:6] /= daysec # (km, km/day) -> (km, km/sec) return pv end - -# Custom serialization - -@doc raw""" - PlanetaryEphemerisSerialization{T} - -Custom serialization struct to save a `TaylorInterpolant{T, T, 2}` to a `.jld2` file. - -# Fields -- `order::Int`: order of Taylor polynomials. -- `dims::Tuple{Int, Int}`: matrix dimensions. -- `t0::T`: initial time. -- `t::Vector{T}`: vector of times. -- `x::Vector{T}`: vector of coefficients. -""" -struct PlanetaryEphemerisSerialization{T} - order::Int - dims::Tuple{Int, Int} - t0::T - t::Vector{T} - x::Vector{T} -end - -# Tell JLD2 to save TaylorInterpolant{T, T, 2} as PlanetaryEphemerisSerialization{T} -writeas(::Type{TaylorInterpolant{T, T, 2}}) where {T<:Real} = PlanetaryEphemerisSerialization{T} - -# Convert method to write .jld2 files -function convert(::Type{PlanetaryEphemerisSerialization{T}}, eph::TaylorInterpolant{T, T, 2}) where {T <: Real} - # Taylor polynomials order - order = eph.x[1, 1].order - # Number of coefficients in each polynomial - k = order + 1 - # Matrix dimensions - dims = size(eph.x) - # Number of elements in matrix - N = dims[1] * dims[2] - # Vector of coefficients - x = Vector{T}(undef, k * N) - # Save coefficients - for i in 1:N - x[(i-1)*k+1 : i*k] = eph.x[i].coeffs - end - - return PlanetaryEphemerisSerialization{T}(order, dims, eph.t0, eph.t, x) -end - -# Convert method to read .jld2 files -function convert(::Type{TaylorInterpolant{T, T, 2}}, eph::PlanetaryEphemerisSerialization{T}) where {T<:Real} - # Taylor polynomials order - order = eph.order - # Number of coefficients in each polynomial - k = order + 1 - # Matrix dimensions - dims = eph.dims - # Number of elements in matrix - N = dims[1] * dims[2] - # Matrix of Taylor polynomials - x = Matrix{Taylor1{T}}(undef, dims[1], dims[2]) - # Reconstruct Taylor polynomials - for i in 1:N - x[i] = Taylor1{T}(eph.x[(i-1)*k+1 : i*k], order) - end - - return TaylorInterpolant{T, T, 2}(eph.t0, eph.t, x) -end - -@doc raw""" - Taylor1Serialization{T} - -Custom serialization struct used in previous versions (<= 0.4) of `PlanetaryEphemeris`. Currently, it is only used to -read old `.jld2` files. -""" -struct Taylor1Serialization{T} - x::Vector{T} -end - -# Convert method to read .jld2 files -convert(::Type{Taylor1{T}}, a::Taylor1Serialization{T}) where {T} = Taylor1{T}(a.x, length(a.x) - 1) From f1995d471fe1a413a7ba5d4ec5153cb76c36699d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20A=2E=20P=C3=A9rez-Hern=C3=A1ndez?= Date: Mon, 1 Apr 2024 12:09:17 +0200 Subject: [PATCH 3/7] Add missing files --- .../PlanetaryEphemerisSerialization.jl | 64 +++++++++ .../TaylorInterpolantNSerialization.jl | 123 ++++++++++++++++++ 2 files changed, 187 insertions(+) create mode 100644 src/interpolation/PlanetaryEphemerisSerialization.jl create mode 100644 src/interpolation/TaylorInterpolantNSerialization.jl diff --git a/src/interpolation/PlanetaryEphemerisSerialization.jl b/src/interpolation/PlanetaryEphemerisSerialization.jl new file mode 100644 index 0000000..67dd4bc --- /dev/null +++ b/src/interpolation/PlanetaryEphemerisSerialization.jl @@ -0,0 +1,64 @@ +# Custom serialization + +@doc raw""" + PlanetaryEphemerisSerialization{T} + +Custom serialization struct to save a `TaylorInterpolant{T, T, 2}` to a `.jld2` file. + +# Fields +- `order::Int`: order of Taylor polynomials. +- `dims::Tuple{Int, Int}`: matrix dimensions. +- `t0::T`: initial time. +- `t::Vector{T}`: vector of times. +- `x::Vector{T}`: vector of coefficients. +""" +struct PlanetaryEphemerisSerialization{T} + order::Int + dims::Tuple{Int, Int} + t0::T + t::Vector{T} + x::Vector{T} +end + +# Tell JLD2 to save TaylorInterpolant{T, T, 2} as PlanetaryEphemerisSerialization{T} +writeas(::Type{TaylorInterpolant{T, T, 2}}) where {T<:Real} = PlanetaryEphemerisSerialization{T} + +# Convert method to write .jld2 files +function convert(::Type{PlanetaryEphemerisSerialization{T}}, eph::TaylorInterpolant{T, T, 2}) where {T <: Real} + # Taylor polynomials order + order = eph.x[1, 1].order + # Number of coefficients in each polynomial + k = order + 1 + # Matrix dimensions + dims = size(eph.x) + # Number of elements in matrix + N = dims[1] * dims[2] + # Vector of coefficients + x = Vector{T}(undef, k * N) + # Save coefficients + for i in 1:N + x[(i-1)*k+1 : i*k] = eph.x[i].coeffs + end + + return PlanetaryEphemerisSerialization{T}(order, dims, eph.t0, eph.t, x) +end + +# Convert method to read .jld2 files +function convert(::Type{TaylorInterpolant{T, T, 2}}, eph::PlanetaryEphemerisSerialization{T}) where {T<:Real} + # Taylor polynomials order + order = eph.order + # Number of coefficients in each polynomial + k = order + 1 + # Matrix dimensions + dims = eph.dims + # Number of elements in matrix + N = dims[1] * dims[2] + # Matrix of Taylor polynomials + x = Matrix{Taylor1{T}}(undef, dims[1], dims[2]) + # Reconstruct Taylor polynomials + for i in 1:N + x[i] = Taylor1{T}(eph.x[(i-1)*k+1 : i*k], order) + end + + return TaylorInterpolant{T, T, 2}(eph.t0, eph.t, x) +end diff --git a/src/interpolation/TaylorInterpolantNSerialization.jl b/src/interpolation/TaylorInterpolantNSerialization.jl new file mode 100644 index 0000000..88c5924 --- /dev/null +++ b/src/interpolation/TaylorInterpolantNSerialization.jl @@ -0,0 +1,123 @@ +@doc raw""" + TaylorInterpolantNSerialization{T} + +Custom serialization struct to save a `TaylorInterpolant{T, TaylorN{T}, 2}` to a `.jld2` file. + +# Fields +- `vars::Vector{String}`: jet transport variables. +- `order::Int`: order of Taylor polynomials w.r.t time. +- `varorder::Int`: order of jet transport perturbations. +- `dims::Tuple{Int, Int}`: matrix dimensions. +- `t0::T`: initial time. +- `t::Vector{T}`: vector of times. +- `x::Vector{T}`: vector of coefficients. +""" +struct TaylorInterpolantNSerialization{T} + vars::Vector{String} + order::Int + varorder::Int + dims::Tuple{Int, Int} + t0::T + t::Vector{T} + x::Vector{T} +end + +# Tell JLD2 to save TaylorInterpolant{T, TaylorN{T}, 2} as TaylorInterpolantNSerialization{T} +writeas(::Type{TaylorInterpolant{T, TaylorN{T}, 2}}) where {T} = TaylorInterpolantNSerialization{T} + +# Convert method to write .jld2 files +function convert(::Type{TaylorInterpolantNSerialization{T}}, eph::TaylorInterpolant{T, TaylorN{T}, 2}) where {T} + # Variables + vars = TS.get_variable_names() + # Number of variables + n = length(vars) + # Matrix dimensions + dims = size(eph.x) + # Number of elements in matrix + N = length(eph.x) + # Taylor1 order + order = eph.x[1, 1].order + # Number of coefficients in each Taylor1 + k = order + 1 + # TaylorN order + varorder = eph.x[1, 1].coeffs[1].order + # Number of coefficients in each TaylorN + L = varorder + 1 + # Number of coefficients in each HomogeneousPolynomial + M = binomial(n + varorder, varorder) + # M = sum(binomial(n + i_3 - 1, i_3) for i_3 in 0:varorder) + + # Vector of coefficients + x = Vector{T}(undef, N * k * M) + + # Save coefficients + i = 1 + # Iterate over matrix elements + for i_1 in 1:N + # Iterate over Taylor1 coefficients + for i_2 in 1:k + # Iterate over TaylorN coefficients + for i_3 in 0:varorder + # Iterate over i_3 order HomogeneousPolynomial + for i_4 in 1:binomial(n + i_3 - 1, i_3) + x[i] = eph.x[i_1].coeffs[i_2].coeffs[i_3+1].coeffs[i_4] + i += 1 + end + end + end + end + + return TaylorInterpolantNSerialization{T}(vars, order, varorder, dims, eph.t0, eph.t, x) +end + +# Convert method to read .jld2 files +function convert(::Type{TaylorInterpolant{T, TaylorN{T}, 2}}, eph::TaylorInterpolantNSerialization{T}) where {T} + # Variables + vars = eph.vars + # Number of variables + n = length(vars) + # Matrix dimensions + dims = eph.dims + # Number of elements in matrix + N = dims[1] * dims[2] + # Taylor1 order + order = eph.order + # Number of coefficients in each Taylor1 + k = order + 1 + # TaylorN order + varorder = eph.varorder + # Number of coefficients in each TaylorN + L = varorder + 1 + # Number of coefficients in each HomogeneousPolynomial + M = binomial(n + varorder, varorder) + # M = sum(binomial(n + i_3 - 1, i_3) for i_3 in 0:varorder) + + # Set variables + if TS.get_variable_names() != vars + TS.set_variables(T, vars, order = varorder) + end + + # Matrix of Taylor polynomials + x = Matrix{Taylor1{TaylorN{T}}}(undef, dims[1], dims[2]) + + # Reconstruct Taylor polynomials + i = 1 + # Iterate over matrix elements + for i_1 in 1:N + # Reconstruct Taylor1s + Taylor1_coeffs = Vector{TaylorN{T}}(undef, k) + for i_2 in 1:k + # Reconstruct TaylorNs + TaylorN_coeffs = Vector{HomogeneousPolynomial{T}}(undef, L) + # Reconstruct HomogeneousPolynomials + for i_3 in 0:varorder + TaylorN_coeffs[i_3 + 1] = HomogeneousPolynomial(eph.x[i : i + binomial(n + i_3 - 1, i_3)-1], i_3) + i += binomial(n + i_3 - 1, i_3) + end + Taylor1_coeffs[i_2] = TaylorN(TaylorN_coeffs, varorder) + end + x[i_1] = Taylor1{TaylorN{T}}(Taylor1_coeffs, order) + end + + return TaylorInterpolant{T, TaylorN{T}, 2}(eph.t0, eph.t, x) +end \ No newline at end of file From 39aba75940e4595c29ba5f22c1b3b5831075a6e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20A=2E=20P=C3=A9rez-Hern=C3=A1ndez?= Date: Mon, 1 Apr 2024 15:38:13 +0200 Subject: [PATCH 4/7] Update tests --- src/dynamics/trivial.jl | 18 ++++++++++++++++++ test/propagation.jl | 22 ++++++++++++++++++---- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/dynamics/trivial.jl b/src/dynamics/trivial.jl index 4a62abb..35912a4 100644 --- a/src/dynamics/trivial.jl +++ b/src/dynamics/trivial.jl @@ -6,3 +6,21 @@ end nothing end + +@taylorize function freeparticle!(dq, q, params, t) + # N: number of bodies + # jd0: initial Julian date + local N, jd0 = params + Threads.@threads for j in 1:N + # Fill first 3N elements of dq with velocities + dq[3j-2] = q[3(N+j)-2] + dq[3j-1] = q[3(N+j)-1] + dq[3j ] = q[3(N+j) ] + end + Threads.@threads for i in 1:N + dq[3(N+i)-2] = zero(q[3(N+i)-2]) + dq[3(N+i)-1] = zero(q[3(N+i)-1]) + dq[3(N+i) ] = zero(q[3(N+i) ]) + end + nothing +end diff --git a/test/propagation.jl b/test/propagation.jl index 313ed23..a964612 100644 --- a/test/propagation.jl +++ b/test/propagation.jl @@ -68,19 +68,33 @@ using LinearAlgebra: norm @test iszero(zero(TaylorInterpolant{T, T, 2, SubArray{T, 1}, SubArray{Taylor1{T}, 2}})) @test iszero(zero(TaylorInterpolant{T, U, 2, SubArray{T, 1}, SubArray{Taylor1{U}, 2}})) # Test integration - sol = propagate(5, jd0, nyears, dense; dynamics=PlanetaryEphemeris.trivialdynamics!, order, abstol) - @test sol isa TaylorInterpolant{Float64,Float64,2} + sol = propagate(5, jd0, nyears, dense; dynamics=PlanetaryEphemeris.freeparticle!, order, abstol) + @test sol isa TaylorInterpolant{Float64, Float64, 2} q0 = initialcond(N, jd0) @test sol(sol.t0) == q0 @test sol.t0 == 0.0 @test length(sol.t) == size(sol.x, 1) + 1 @test length(q0) == size(sol.x, 2) dq = TaylorSeries.set_variables("dq", order=2, numvars=2) - tmid = sol.t0 + sol.t[1]/2 + tmid = sol.t0 + sol.t[2]/2 @test sol(tmid) isa Vector{Float64} @test sol(tmid + Taylor1(order)) isa Vector{Taylor1{Float64}} @test sol(tmid + dq[1] + dq[1]*dq[2]) isa Vector{TaylorN{Float64}} - @test sol(tmid + Taylor1([dq[1],dq[1]*dq[2]],order)) isa Vector{Taylor1{TaylorN{Float64}}} + @test sol(tmid + Taylor1([dq[1],dq[1]*dq[2]], order)) isa Vector{Taylor1{TaylorN{Float64}}} + sol1N = TaylorInterpolant(sol.t0, sol.t, sol.x .+ Taylor1(dq[1], 25)) + @test sol1N(sol.t0)() == sol(sol.t0) + @test sol1N(tmid)() == sol(tmid) + # Test PlanetaryEphemerisSerialization + jldsave("test.jld2"; sol) + sol_file = JLD2.load("test.jld2", "sol") + rm("test.jld2") + @test sol_file == sol + # Test TaylorInterpolantNSerialization + sol1N = TaylorInterpolant(sol.t0, sol.t, sol.x .* Taylor1(one(dq[1]), 25)) + jldsave("test.jld2"; sol1N) + sol1N_file = JLD2.load("test.jld2", "sol1N") + @test sol1N_file == sol1N + rm("test.jld2") end @testset "Propagation: DE430 dynamical model" begin From 136be6ee768f51c9de9448e23f153f72a1f4d142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20A=2E=20P=C3=A9rez-Hern=C3=A1ndez?= Date: Mon, 1 Apr 2024 23:15:57 +0200 Subject: [PATCH 5/7] Scattered fixes --- .../PlanetaryEphemerisSerialization.jl | 12 +- .../TaylorInterpolantNSerialization.jl | 15 +- src/propagation.jl | 2 +- test/propagation.jl | 190 +++++++++--------- 4 files changed, 115 insertions(+), 104 deletions(-) diff --git a/src/interpolation/PlanetaryEphemerisSerialization.jl b/src/interpolation/PlanetaryEphemerisSerialization.jl index 67dd4bc..cc5df78 100644 --- a/src/interpolation/PlanetaryEphemerisSerialization.jl +++ b/src/interpolation/PlanetaryEphemerisSerialization.jl @@ -21,10 +21,12 @@ struct PlanetaryEphemerisSerialization{T} end # Tell JLD2 to save TaylorInterpolant{T, T, 2} as PlanetaryEphemerisSerialization{T} -writeas(::Type{TaylorInterpolant{T, T, 2}}) where {T<:Real} = PlanetaryEphemerisSerialization{T} +function writeas(::Type{<:TaylorInterpolant{T, T, 2, Vector{T}, Matrix{Taylor1{T}}}}) where {T<:Real} + return PlanetaryEphemerisSerialization{T} +end # Convert method to write .jld2 files -function convert(::Type{PlanetaryEphemerisSerialization{T}}, eph::TaylorInterpolant{T, T, 2}) where {T <: Real} +function convert(::Type{PlanetaryEphemerisSerialization{T}}, eph::TaylorInterpolant{T, T, 2, Vector{T}, Matrix{Taylor1{T}}}) where {T <: Real} # Taylor polynomials order order = eph.x[1, 1].order # Number of coefficients in each polynomial @@ -44,7 +46,7 @@ function convert(::Type{PlanetaryEphemerisSerialization{T}}, eph::TaylorInterpol end # Convert method to read .jld2 files -function convert(::Type{TaylorInterpolant{T, T, 2}}, eph::PlanetaryEphemerisSerialization{T}) where {T<:Real} +function convert(::Type{TaylorInterpolant{T, T, 2, Vector{T}, Matrix{Taylor1{T}}}}, eph::PlanetaryEphemerisSerialization{T}) where {T<:Real} # Taylor polynomials order order = eph.order # Number of coefficients in each polynomial @@ -62,3 +64,7 @@ function convert(::Type{TaylorInterpolant{T, T, 2}}, eph::PlanetaryEphemerisSeri return TaylorInterpolant{T, T, 2}(eph.t0, eph.t, x) end + +function convert(::Type{TaylorInterpolant{T, T, 2}}, eph::PlanetaryEphemerisSerialization{T}) where {T<:Real} + return convert(TaylorInterpolant{T, T, 2, Vector{T}, Matrix{Taylor1{T}}}, eph) +end \ No newline at end of file diff --git a/src/interpolation/TaylorInterpolantNSerialization.jl b/src/interpolation/TaylorInterpolantNSerialization.jl index 88c5924..33c6c2d 100644 --- a/src/interpolation/TaylorInterpolantNSerialization.jl +++ b/src/interpolation/TaylorInterpolantNSerialization.jl @@ -22,11 +22,13 @@ struct TaylorInterpolantNSerialization{T} x::Vector{T} end -# Tell JLD2 to save TaylorInterpolant{T, TaylorN{T}, 2} as TaylorInterpolantNSerialization{T} -writeas(::Type{TaylorInterpolant{T, TaylorN{T}, 2}}) where {T} = TaylorInterpolantNSerialization{T} +# Tell JLD2 to save <:TaylorInterpolant{T, TaylorN{T}, 2} as TaylorInterpolantNSerialization{T} +function writeas(::Type{<:TaylorInterpolant{T, TaylorN{T}, 2, Vector{T}, Matrix{Taylor1{TaylorN{T}}}}}) where {T<:Real} + return TaylorInterpolantNSerialization{T} +end # Convert method to write .jld2 files -function convert(::Type{TaylorInterpolantNSerialization{T}}, eph::TaylorInterpolant{T, TaylorN{T}, 2}) where {T} +function convert(::Type{TaylorInterpolantNSerialization{T}}, eph::TaylorInterpolant{T, TaylorN{T}, 2, Vector{T}, Matrix{Taylor1{TaylorN{T}}}}) where {T} # Variables vars = TS.get_variable_names() # Number of variables @@ -45,7 +47,6 @@ function convert(::Type{TaylorInterpolantNSerialization{T}}, eph::TaylorInterpol L = varorder + 1 # Number of coefficients in each HomogeneousPolynomial M = binomial(n + varorder, varorder) - # M = sum(binomial(n + i_3 - 1, i_3) for i_3 in 0:varorder) # Vector of coefficients x = Vector{T}(undef, N * k * M) @@ -71,7 +72,7 @@ function convert(::Type{TaylorInterpolantNSerialization{T}}, eph::TaylorInterpol end # Convert method to read .jld2 files -function convert(::Type{TaylorInterpolant{T, TaylorN{T}, 2}}, eph::TaylorInterpolantNSerialization{T}) where {T} +function convert(::Type{TaylorInterpolant{T, TaylorN{T}, 2, Vector{T}, Matrix{Taylor1{TaylorN{T}}}}}, eph::TaylorInterpolantNSerialization{T}) where {T} # Variables vars = eph.vars # Number of variables @@ -120,4 +121,8 @@ function convert(::Type{TaylorInterpolant{T, TaylorN{T}, 2}}, eph::TaylorInterpo end return TaylorInterpolant{T, TaylorN{T}, 2}(eph.t0, eph.t, x) +end + +function convert(::Type{TaylorInterpolant{T, TaylorN{T}, 2}}, eph::PlanetaryEphemerisSerialization{T}) where {T<:Real} + return convert(TaylorInterpolant{T, TaylorN{T}, 2, Vector{T}, Matrix{Taylor1{TaylorN{T}}}}, eph) end \ No newline at end of file diff --git a/src/propagation.jl b/src/propagation.jl index 73ef53c..87a5a16 100644 --- a/src/propagation.jl +++ b/src/propagation.jl @@ -195,7 +195,7 @@ for V_dense in (:(Val{true}), :(Val{false})) maxsteps, parse_eqs) if $V_dense == Val{true} - return TaylorInterpolant{T, T, 2, SubArray{T,1}, SubArray{Taylor1{T},2}}(jd0 - J2000, sol[1], sol[3]) + return TaylorInterpolant{T, T, 2}(jd0 - J2000, sol[1], sol[3]) else return sol end diff --git a/test/propagation.jl b/test/propagation.jl index a964612..6da51aa 100644 --- a/test/propagation.jl +++ b/test/propagation.jl @@ -97,100 +97,100 @@ using LinearAlgebra: norm rm("test.jld2") end - @testset "Propagation: DE430 dynamical model" begin - - @show Threads.nthreads() - - # Float64 - - # Test integration - sol64 = propagate(100, jd0, nyears, dense; dynamics, order, abstol) - # Save solution - filename = selecteph2jld2(sol64, bodyind, nyears) - # Recovered solution - recovered_sol64 = JLD2.load(filename, "ss16ast_eph") - - @test selecteph(sol64, bodyind, euler = true, ttmtdb = true) == recovered_sol64 - - # Test selecteph - t0 = sol64.t0 + sol64.t[end]/3 - tf = sol64.t0 + 2*sol64.t[end]/3 - idxs = vcat(nbodyind(N, [su, ea, mo]), 6N+1:6N+13) - i_0 = searchsortedlast(sol64.t, t0) - i_f = searchsortedfirst(sol64.t, tf) - - subsol = selecteph(sol64, [su, ea, mo], t0, tf; euler = true, ttmtdb = true) - - @test subsol.t0 == sol64.t0 - @test subsol.t0 + subsol.t[1] ≤ t0 - @test subsol.t0 + subsol.t[end] ≥ tf - @test size(subsol.x) == (i_f - i_0, length(idxs)) - @test subsol.x == sol64.x[i_0:i_f-1, idxs] - @test subsol(t0) == sol64(t0)[idxs] - @test subsol(tf) == sol64(tf)[idxs] - - # Kernels URLs - LSK = "https://naif.jpl.nasa.gov/pub/naif/generic_kernels/lsk/naif0012.tls" - TTmTDBK = "https://ssd.jpl.nasa.gov/ftp/eph/planets/bsp/TTmTDB.de430.19feb2015.bsp" - SPK = "https://ssd.jpl.nasa.gov/ftp/eph/planets/bsp/de430_1850-2150.bsp" - - # Download kernels - Downloads.download(LSK, "naif0012.tls") - Downloads.download(SPK, "de430_1850-2150.bsp") - Downloads.download(TTmTDBK, "TTmTDB.de430.19feb2015.bsp") - - # Load kernels - furnsh("naif0012.tls", "de430_1850-2150.bsp", "TTmTDB.de430.19feb2015.bsp") - - ttmtdb_pe = TaylorInterpolant(sol64.t0, sol64.t, sol64.x[:, 6N+13]) # TT-TDB - posvel_pe_su = selecteph(sol64,su) # Sun - posvel_pe_ea = selecteph(sol64,ea) # Earth - posvel_pe_mo = selecteph(sol64,mo) # Moon - posvel_pe_ma = selecteph(sol64,6) # Mars - posvel_pe_ju = selecteph(sol64,7) # Jupiter - - ttmtdb_jpl(et) = spkgeo(1000000001, et, "J2000", 1000000000)[1][1] # TT-TDB - posvel_jpl_su(et) = kmsec2auday(spkgeo(10, et, "J2000", 0)[1]) # Sun - posvel_jpl_ea(et) = kmsec2auday(spkgeo(399, et, "J2000", 0)[1]) # Earth - posvel_jpl_mo(et) = kmsec2auday(spkgeo(301, et, "J2000", 0)[1]) # Moon - posvel_jpl_ma(et) = kmsec2auday(spkgeo(4, et, "J2000", 0)[1]) # Mars - posvel_jpl_ju(et) = kmsec2auday(spkgeo(5, et, "J2000", 0)[1]) # Jupiter - - tv = range(sol64.t0, sol64.t[end], 10) - for t in tv - et = t * daysec - @show t, et - @show abs(ttmtdb_jpl(et) - ttmtdb_pe(t)) - @show norm(posvel_jpl_su(et) - posvel_pe_su(t), Inf) - @show norm(posvel_jpl_ea(et) - posvel_pe_ea(t), Inf) - @show norm(posvel_jpl_mo(et) - posvel_pe_mo(t), Inf) - @show norm(posvel_jpl_ma(et) - posvel_pe_ma(t), Inf) - @show norm(posvel_jpl_ju(et) - posvel_pe_ju(t), Inf) - - @test abs(ttmtdb_jpl(et) - ttmtdb_pe(t)) < 1e-12 - @test norm(posvel_jpl_su(et) - posvel_pe_su(t), Inf) < 1e-14 - @test norm(posvel_jpl_ea(et) - posvel_pe_ea(t), Inf) < 1e-11 - @test norm(posvel_jpl_mo(et) - posvel_pe_mo(t), Inf) < 1e-11 - @test norm(posvel_jpl_ma(et) - posvel_pe_ma(t), Inf) < 1e-12 - @test norm(posvel_jpl_ju(et) - posvel_pe_ju(t), Inf) < 1e-13 - end - - # Remove files - rm.((filename, "naif0012.tls", "de430_1850-2150.bsp", "TTmTDB.de430.19feb2015.bsp")) - - # Float 128 - #= - # Test integration - sol128 = propagate(1, Float128(jd0), nyears, dense; dynamics = dynamics, order = order, abstol = abstol) - # Save solution - filename = selecteph2jld2(sol128, bodyind, nyears) - # Recovered solution - recovered_sol128 = JLD2.load(filename, "ss16ast_eph") - # Remove file - rm(filename) - - @test selecteph(sol128, bodyind, euler = true, ttmtdb = true) == recovered_sol128 - =# - end + # @testset "Propagation: DE430 dynamical model" begin + + # @show Threads.nthreads() + + # # Float64 + + # # Test integration + # sol64 = propagate(100, jd0, nyears, dense; dynamics, order, abstol) + # # Save solution + # filename = selecteph2jld2(sol64, bodyind, nyears) + # # Recovered solution + # recovered_sol64 = JLD2.load(filename, "ss16ast_eph") + + # @test selecteph(sol64, bodyind, euler = true, ttmtdb = true) == recovered_sol64 + + # # Test selecteph + # t0 = sol64.t0 + sol64.t[end]/3 + # tf = sol64.t0 + 2*sol64.t[end]/3 + # idxs = vcat(nbodyind(N, [su, ea, mo]), 6N+1:6N+13) + # i_0 = searchsortedlast(sol64.t, t0) + # i_f = searchsortedfirst(sol64.t, tf) + + # subsol = selecteph(sol64, [su, ea, mo], t0, tf; euler = true, ttmtdb = true) + + # @test subsol.t0 == sol64.t0 + # @test subsol.t0 + subsol.t[1] ≤ t0 + # @test subsol.t0 + subsol.t[end] ≥ tf + # @test size(subsol.x) == (i_f - i_0, length(idxs)) + # @test subsol.x == sol64.x[i_0:i_f-1, idxs] + # @test subsol(t0) == sol64(t0)[idxs] + # @test subsol(tf) == sol64(tf)[idxs] + + # # Kernels URLs + # LSK = "https://naif.jpl.nasa.gov/pub/naif/generic_kernels/lsk/naif0012.tls" + # TTmTDBK = "https://ssd.jpl.nasa.gov/ftp/eph/planets/bsp/TTmTDB.de430.19feb2015.bsp" + # SPK = "https://ssd.jpl.nasa.gov/ftp/eph/planets/bsp/de430_1850-2150.bsp" + + # # Download kernels + # Downloads.download(LSK, "naif0012.tls") + # Downloads.download(SPK, "de430_1850-2150.bsp") + # Downloads.download(TTmTDBK, "TTmTDB.de430.19feb2015.bsp") + + # # Load kernels + # furnsh("naif0012.tls", "de430_1850-2150.bsp", "TTmTDB.de430.19feb2015.bsp") + + # ttmtdb_pe = TaylorInterpolant(sol64.t0, sol64.t, sol64.x[:, 6N+13]) # TT-TDB + # posvel_pe_su = selecteph(sol64,su) # Sun + # posvel_pe_ea = selecteph(sol64,ea) # Earth + # posvel_pe_mo = selecteph(sol64,mo) # Moon + # posvel_pe_ma = selecteph(sol64,6) # Mars + # posvel_pe_ju = selecteph(sol64,7) # Jupiter + + # ttmtdb_jpl(et) = spkgeo(1000000001, et, "J2000", 1000000000)[1][1] # TT-TDB + # posvel_jpl_su(et) = kmsec2auday(spkgeo(10, et, "J2000", 0)[1]) # Sun + # posvel_jpl_ea(et) = kmsec2auday(spkgeo(399, et, "J2000", 0)[1]) # Earth + # posvel_jpl_mo(et) = kmsec2auday(spkgeo(301, et, "J2000", 0)[1]) # Moon + # posvel_jpl_ma(et) = kmsec2auday(spkgeo(4, et, "J2000", 0)[1]) # Mars + # posvel_jpl_ju(et) = kmsec2auday(spkgeo(5, et, "J2000", 0)[1]) # Jupiter + + # tv = range(sol64.t0, sol64.t[end], 10) + # for t in tv + # et = t * daysec + # @show t, et + # @show abs(ttmtdb_jpl(et) - ttmtdb_pe(t)) + # @show norm(posvel_jpl_su(et) - posvel_pe_su(t), Inf) + # @show norm(posvel_jpl_ea(et) - posvel_pe_ea(t), Inf) + # @show norm(posvel_jpl_mo(et) - posvel_pe_mo(t), Inf) + # @show norm(posvel_jpl_ma(et) - posvel_pe_ma(t), Inf) + # @show norm(posvel_jpl_ju(et) - posvel_pe_ju(t), Inf) + + # @test abs(ttmtdb_jpl(et) - ttmtdb_pe(t)) < 1e-12 + # @test norm(posvel_jpl_su(et) - posvel_pe_su(t), Inf) < 1e-14 + # @test norm(posvel_jpl_ea(et) - posvel_pe_ea(t), Inf) < 1e-11 + # @test norm(posvel_jpl_mo(et) - posvel_pe_mo(t), Inf) < 1e-11 + # @test norm(posvel_jpl_ma(et) - posvel_pe_ma(t), Inf) < 1e-12 + # @test norm(posvel_jpl_ju(et) - posvel_pe_ju(t), Inf) < 1e-13 + # end + + # # Remove files + # rm.((filename, "naif0012.tls", "de430_1850-2150.bsp", "TTmTDB.de430.19feb2015.bsp")) + + # # Float 128 + # #= + # # Test integration + # sol128 = propagate(1, Float128(jd0), nyears, dense; dynamics = dynamics, order = order, abstol = abstol) + # # Save solution + # filename = selecteph2jld2(sol128, bodyind, nyears) + # # Recovered solution + # recovered_sol128 = JLD2.load(filename, "ss16ast_eph") + # # Remove file + # rm(filename) + + # @test selecteph(sol128, bodyind, euler = true, ttmtdb = true) == recovered_sol128 + # =# + # end end From fe9240b2be6b2a28107011888da64592f04ab259 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20A=2E=20P=C3=A9rez-Hern=C3=A1ndez?= Date: Mon, 1 Apr 2024 23:31:59 +0200 Subject: [PATCH 6/7] Uncomment tests --- test/propagation.jl | 190 ++++++++++++++++++++++---------------------- 1 file changed, 95 insertions(+), 95 deletions(-) diff --git a/test/propagation.jl b/test/propagation.jl index 6da51aa..a964612 100644 --- a/test/propagation.jl +++ b/test/propagation.jl @@ -97,100 +97,100 @@ using LinearAlgebra: norm rm("test.jld2") end - # @testset "Propagation: DE430 dynamical model" begin - - # @show Threads.nthreads() - - # # Float64 - - # # Test integration - # sol64 = propagate(100, jd0, nyears, dense; dynamics, order, abstol) - # # Save solution - # filename = selecteph2jld2(sol64, bodyind, nyears) - # # Recovered solution - # recovered_sol64 = JLD2.load(filename, "ss16ast_eph") - - # @test selecteph(sol64, bodyind, euler = true, ttmtdb = true) == recovered_sol64 - - # # Test selecteph - # t0 = sol64.t0 + sol64.t[end]/3 - # tf = sol64.t0 + 2*sol64.t[end]/3 - # idxs = vcat(nbodyind(N, [su, ea, mo]), 6N+1:6N+13) - # i_0 = searchsortedlast(sol64.t, t0) - # i_f = searchsortedfirst(sol64.t, tf) - - # subsol = selecteph(sol64, [su, ea, mo], t0, tf; euler = true, ttmtdb = true) - - # @test subsol.t0 == sol64.t0 - # @test subsol.t0 + subsol.t[1] ≤ t0 - # @test subsol.t0 + subsol.t[end] ≥ tf - # @test size(subsol.x) == (i_f - i_0, length(idxs)) - # @test subsol.x == sol64.x[i_0:i_f-1, idxs] - # @test subsol(t0) == sol64(t0)[idxs] - # @test subsol(tf) == sol64(tf)[idxs] - - # # Kernels URLs - # LSK = "https://naif.jpl.nasa.gov/pub/naif/generic_kernels/lsk/naif0012.tls" - # TTmTDBK = "https://ssd.jpl.nasa.gov/ftp/eph/planets/bsp/TTmTDB.de430.19feb2015.bsp" - # SPK = "https://ssd.jpl.nasa.gov/ftp/eph/planets/bsp/de430_1850-2150.bsp" - - # # Download kernels - # Downloads.download(LSK, "naif0012.tls") - # Downloads.download(SPK, "de430_1850-2150.bsp") - # Downloads.download(TTmTDBK, "TTmTDB.de430.19feb2015.bsp") - - # # Load kernels - # furnsh("naif0012.tls", "de430_1850-2150.bsp", "TTmTDB.de430.19feb2015.bsp") - - # ttmtdb_pe = TaylorInterpolant(sol64.t0, sol64.t, sol64.x[:, 6N+13]) # TT-TDB - # posvel_pe_su = selecteph(sol64,su) # Sun - # posvel_pe_ea = selecteph(sol64,ea) # Earth - # posvel_pe_mo = selecteph(sol64,mo) # Moon - # posvel_pe_ma = selecteph(sol64,6) # Mars - # posvel_pe_ju = selecteph(sol64,7) # Jupiter - - # ttmtdb_jpl(et) = spkgeo(1000000001, et, "J2000", 1000000000)[1][1] # TT-TDB - # posvel_jpl_su(et) = kmsec2auday(spkgeo(10, et, "J2000", 0)[1]) # Sun - # posvel_jpl_ea(et) = kmsec2auday(spkgeo(399, et, "J2000", 0)[1]) # Earth - # posvel_jpl_mo(et) = kmsec2auday(spkgeo(301, et, "J2000", 0)[1]) # Moon - # posvel_jpl_ma(et) = kmsec2auday(spkgeo(4, et, "J2000", 0)[1]) # Mars - # posvel_jpl_ju(et) = kmsec2auday(spkgeo(5, et, "J2000", 0)[1]) # Jupiter - - # tv = range(sol64.t0, sol64.t[end], 10) - # for t in tv - # et = t * daysec - # @show t, et - # @show abs(ttmtdb_jpl(et) - ttmtdb_pe(t)) - # @show norm(posvel_jpl_su(et) - posvel_pe_su(t), Inf) - # @show norm(posvel_jpl_ea(et) - posvel_pe_ea(t), Inf) - # @show norm(posvel_jpl_mo(et) - posvel_pe_mo(t), Inf) - # @show norm(posvel_jpl_ma(et) - posvel_pe_ma(t), Inf) - # @show norm(posvel_jpl_ju(et) - posvel_pe_ju(t), Inf) - - # @test abs(ttmtdb_jpl(et) - ttmtdb_pe(t)) < 1e-12 - # @test norm(posvel_jpl_su(et) - posvel_pe_su(t), Inf) < 1e-14 - # @test norm(posvel_jpl_ea(et) - posvel_pe_ea(t), Inf) < 1e-11 - # @test norm(posvel_jpl_mo(et) - posvel_pe_mo(t), Inf) < 1e-11 - # @test norm(posvel_jpl_ma(et) - posvel_pe_ma(t), Inf) < 1e-12 - # @test norm(posvel_jpl_ju(et) - posvel_pe_ju(t), Inf) < 1e-13 - # end - - # # Remove files - # rm.((filename, "naif0012.tls", "de430_1850-2150.bsp", "TTmTDB.de430.19feb2015.bsp")) - - # # Float 128 - # #= - # # Test integration - # sol128 = propagate(1, Float128(jd0), nyears, dense; dynamics = dynamics, order = order, abstol = abstol) - # # Save solution - # filename = selecteph2jld2(sol128, bodyind, nyears) - # # Recovered solution - # recovered_sol128 = JLD2.load(filename, "ss16ast_eph") - # # Remove file - # rm(filename) - - # @test selecteph(sol128, bodyind, euler = true, ttmtdb = true) == recovered_sol128 - # =# - # end + @testset "Propagation: DE430 dynamical model" begin + + @show Threads.nthreads() + + # Float64 + + # Test integration + sol64 = propagate(100, jd0, nyears, dense; dynamics, order, abstol) + # Save solution + filename = selecteph2jld2(sol64, bodyind, nyears) + # Recovered solution + recovered_sol64 = JLD2.load(filename, "ss16ast_eph") + + @test selecteph(sol64, bodyind, euler = true, ttmtdb = true) == recovered_sol64 + + # Test selecteph + t0 = sol64.t0 + sol64.t[end]/3 + tf = sol64.t0 + 2*sol64.t[end]/3 + idxs = vcat(nbodyind(N, [su, ea, mo]), 6N+1:6N+13) + i_0 = searchsortedlast(sol64.t, t0) + i_f = searchsortedfirst(sol64.t, tf) + + subsol = selecteph(sol64, [su, ea, mo], t0, tf; euler = true, ttmtdb = true) + + @test subsol.t0 == sol64.t0 + @test subsol.t0 + subsol.t[1] ≤ t0 + @test subsol.t0 + subsol.t[end] ≥ tf + @test size(subsol.x) == (i_f - i_0, length(idxs)) + @test subsol.x == sol64.x[i_0:i_f-1, idxs] + @test subsol(t0) == sol64(t0)[idxs] + @test subsol(tf) == sol64(tf)[idxs] + + # Kernels URLs + LSK = "https://naif.jpl.nasa.gov/pub/naif/generic_kernels/lsk/naif0012.tls" + TTmTDBK = "https://ssd.jpl.nasa.gov/ftp/eph/planets/bsp/TTmTDB.de430.19feb2015.bsp" + SPK = "https://ssd.jpl.nasa.gov/ftp/eph/planets/bsp/de430_1850-2150.bsp" + + # Download kernels + Downloads.download(LSK, "naif0012.tls") + Downloads.download(SPK, "de430_1850-2150.bsp") + Downloads.download(TTmTDBK, "TTmTDB.de430.19feb2015.bsp") + + # Load kernels + furnsh("naif0012.tls", "de430_1850-2150.bsp", "TTmTDB.de430.19feb2015.bsp") + + ttmtdb_pe = TaylorInterpolant(sol64.t0, sol64.t, sol64.x[:, 6N+13]) # TT-TDB + posvel_pe_su = selecteph(sol64,su) # Sun + posvel_pe_ea = selecteph(sol64,ea) # Earth + posvel_pe_mo = selecteph(sol64,mo) # Moon + posvel_pe_ma = selecteph(sol64,6) # Mars + posvel_pe_ju = selecteph(sol64,7) # Jupiter + + ttmtdb_jpl(et) = spkgeo(1000000001, et, "J2000", 1000000000)[1][1] # TT-TDB + posvel_jpl_su(et) = kmsec2auday(spkgeo(10, et, "J2000", 0)[1]) # Sun + posvel_jpl_ea(et) = kmsec2auday(spkgeo(399, et, "J2000", 0)[1]) # Earth + posvel_jpl_mo(et) = kmsec2auday(spkgeo(301, et, "J2000", 0)[1]) # Moon + posvel_jpl_ma(et) = kmsec2auday(spkgeo(4, et, "J2000", 0)[1]) # Mars + posvel_jpl_ju(et) = kmsec2auday(spkgeo(5, et, "J2000", 0)[1]) # Jupiter + + tv = range(sol64.t0, sol64.t[end], 10) + for t in tv + et = t * daysec + @show t, et + @show abs(ttmtdb_jpl(et) - ttmtdb_pe(t)) + @show norm(posvel_jpl_su(et) - posvel_pe_su(t), Inf) + @show norm(posvel_jpl_ea(et) - posvel_pe_ea(t), Inf) + @show norm(posvel_jpl_mo(et) - posvel_pe_mo(t), Inf) + @show norm(posvel_jpl_ma(et) - posvel_pe_ma(t), Inf) + @show norm(posvel_jpl_ju(et) - posvel_pe_ju(t), Inf) + + @test abs(ttmtdb_jpl(et) - ttmtdb_pe(t)) < 1e-12 + @test norm(posvel_jpl_su(et) - posvel_pe_su(t), Inf) < 1e-14 + @test norm(posvel_jpl_ea(et) - posvel_pe_ea(t), Inf) < 1e-11 + @test norm(posvel_jpl_mo(et) - posvel_pe_mo(t), Inf) < 1e-11 + @test norm(posvel_jpl_ma(et) - posvel_pe_ma(t), Inf) < 1e-12 + @test norm(posvel_jpl_ju(et) - posvel_pe_ju(t), Inf) < 1e-13 + end + + # Remove files + rm.((filename, "naif0012.tls", "de430_1850-2150.bsp", "TTmTDB.de430.19feb2015.bsp")) + + # Float 128 + #= + # Test integration + sol128 = propagate(1, Float128(jd0), nyears, dense; dynamics = dynamics, order = order, abstol = abstol) + # Save solution + filename = selecteph2jld2(sol128, bodyind, nyears) + # Recovered solution + recovered_sol128 = JLD2.load(filename, "ss16ast_eph") + # Remove file + rm(filename) + + @test selecteph(sol128, bodyind, euler = true, ttmtdb = true) == recovered_sol128 + =# + end end From e541458439649bb9dca12fb910a926d7e5ad603e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20A=2E=20P=C3=A9rez-Hern=C3=A1ndez?= Date: Tue, 2 Apr 2024 11:43:14 +0200 Subject: [PATCH 7/7] Update tests --- test/propagation.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/propagation.jl b/test/propagation.jl index a964612..1cdb093 100644 --- a/test/propagation.jl +++ b/test/propagation.jl @@ -85,12 +85,14 @@ using LinearAlgebra: norm @test sol1N(sol.t0)() == sol(sol.t0) @test sol1N(tmid)() == sol(tmid) # Test PlanetaryEphemerisSerialization + @test JLD2.writeas(typeof(sol)) == PlanetaryEphemeris.PlanetaryEphemerisSerialization{Float64} jldsave("test.jld2"; sol) sol_file = JLD2.load("test.jld2", "sol") rm("test.jld2") @test sol_file == sol # Test TaylorInterpolantNSerialization sol1N = TaylorInterpolant(sol.t0, sol.t, sol.x .* Taylor1(one(dq[1]), 25)) + @test JLD2.writeas(typeof(sol1N)) == PlanetaryEphemeris.TaylorInterpolantNSerialization{Float64} jldsave("test.jld2"; sol1N) sol1N_file = JLD2.load("test.jld2", "sol1N") @test sol1N_file == sol1N