From 4747aad2c9b6f936cf9d2f14a62942d18abd6139 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20P=C3=A9rez?= Date: Sun, 2 Apr 2023 13:25:59 +0200 Subject: [PATCH] Fix JuliaRegistrator auto-merging; add @LuEdRaMo as co-author (#11) --- Project.toml | 3 +- README.md | 4 +- src/propagation.jl | 110 ++++++++++++++++++++++----------------------- 3 files changed, 60 insertions(+), 57 deletions(-) diff --git a/Project.toml b/Project.toml index 248c789..090c3b7 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "PlanetaryEphemeris" uuid = "d83715d0-7e5f-11e9-1a59-4137b20d8363" -authors = ["Jorge A. Pérez Hernández", "Luis Benet"] +authors = ["Jorge A. Pérez Hernández", "Luis Benet", "Luis Eduardo Ramírez Montoya"] version = "0.3.0" [deps] @@ -21,6 +21,7 @@ ArgParse = "1.1" AutoHashEquals = "0.2" JLD2 = "0.4" Quadmath = "0.5" +SnoopPrecompile = "1.0" TaylorIntegration = "0.11" TaylorSeries = "0.14" julia = "1.6" diff --git a/README.md b/README.md index 174723a..d104927 100644 --- a/README.md +++ b/README.md @@ -8,10 +8,12 @@ ephemeris dynamical model (Folkner et al., 2014), based on ## Authors -- [Jorge A. Pérez](https://www.linkedin.com/in/perezhz), +- [Jorge A. Pérez Hernández](https://github.com/PerezHz), Instituto de Ciencias Físicas, Universidad Nacional Autónoma de México (UNAM) - [Luis Benet](http://www.cicc.unam.mx/~benet/), Instituto de Ciencias Físicas, Universidad Nacional Autónoma de México (UNAM) +- [Luis Eduardo Ramírez Montoya](https://github.com/LuEdRaMo), +Facultad de Ciencias, Universidad Nacional Autónoma de México (UNAM) ## Installation diff --git a/src/propagation.jl b/src/propagation.jl index da13209..9ba9dc9 100644 --- a/src/propagation.jl +++ b/src/propagation.jl @@ -1,7 +1,7 @@ @doc raw""" Taylor1Serialization{T} -Specialized struct to save `Taylor1{T}` objects to `.jld2` files. +Specialized struct to save `Taylor1{T}` objects to `.jld2` files. """ struct Taylor1Serialization{T} x::Vector{T} @@ -9,9 +9,9 @@ end # Tell JLD2 to save Taylor1{T} as Taylor1Serialization{T} writeas(::Type{Taylor1{T}}) where {T} = Taylor1Serialization{T} -# Convert method to write .jld2 files +# Convert method to write .jld2 files convert(::Type{Taylor1Serialization{T}}, a::Taylor1{T}) where {T} = Taylor1Serialization{T}(a.coeffs) -# Convert method to read .jld2 files +# Convert method to read .jld2 files convert(::Type{Taylor1{T}}, a::Taylor1Serialization{T}) where {T} = Taylor1{T}(a.x, length(a.x) - 1) @doc raw""" @@ -24,26 +24,26 @@ Save the ephemeris, contained in `sseph`, of the bodies with indices `bodyind`, # Arguments -- `sseph::TaylorInterpolant`: ephemeris of all the bodies. +- `sseph::TaylorInterpolant`: ephemeris of all the bodies. - `bodyind::T`: indices of the bodies to be saved. - `tspan::S`: time span of the integration (positive -> forward integration / negative -> backward integration). - `N::Int`: total number of bodies. """ function selecteph2jld2(sseph::TaylorInterpolant, bodyind::T, tspan::S, N::Int) where {T <: AbstractVector{Int}, S <: Number} - + # Number of asteroids in sseph - nast = N - 11 + nast = N - 11 # indices of the positions and velocities of the bodies to be saved - indvec = nbodyind(N, bodyind) + indvec = nbodyind(N, bodyind) # Number of asteroids to be saved - nastout = length(bodyind) - 11 + nastout = length(bodyind) - 11 # Check nastout <= nast @assert nastout <= nast "Cannot save $nastout asteroids from ephemeris with $nast asteroids" # Prefix to distinguish between forward (p) / backward (m) integration - sgn_yrs = signbit(tspan) ? "m" : "p" + sgn_yrs = signbit(tspan) ? "m" : "p" # Number of years - nyrs_int = Int(abs(tspan)) - + nyrs_int = Int(abs(tspan)) + # Write output to .jld2 file # Name of the file @@ -54,10 +54,10 @@ function selecteph2jld2(sseph::TaylorInterpolant, bodyind::T, tspan::S, N::Int) println("Saving solution to file: ", ss16ast_fname) - # Open file + # Open file JLD2.jldopen(ss16ast_fname, "w") do file - # Write the ephemeris to file - write(file, "ss16ast_eph", ss16ast_eph) + # Write the ephemeris to file + write(file, "ss16ast_eph", ss16ast_eph) end # Check that written output is equal to original variable ss16ast_eph recovered_sol_i = JLD2.load(ss16ast_fname, "ss16ast_eph") @@ -65,47 +65,47 @@ function selecteph2jld2(sseph::TaylorInterpolant, bodyind::T, tspan::S, N::Int) println("Solution saved correctly") else println("Saved and recovered solution are not equal") - end + end - return nothing + return ss16ast_fname end @doc raw""" save2jld2andcheck(outfilename::String, sol) -Save `sol` in `outfilename` (.jld2) and check that recovered solution equals `sol`. +Save `sol` in `outfilename` (.jld2) and check that recovered solution equals `sol`. """ function save2jld2andcheck(outfilename::String, sol) println("Saving solution to file: ", outfilename) - # Open file + # Open file JLD2.jldopen(outfilename, "w") do file # Loop over solution variables for ind in eachindex(sol) - # Name of the variable + # Name of the variable varname = string(ind) println("Saving variable: ", varname) - # Write the varaible + # Write the variable write(file, varname, sol[ind]) end end - # Check that saved solution is equal to the original + # Check that saved solution is equal to the original println("Checking that all variables were saved correctly...") # Loop over solution variables for ind in eachindex(sol) - # Name of the variable + # Name of the variable varname = string(ind) # Read varname from files and assign recovered variable to recovered_sol_i recovered_sol_i = JLD2.load(outfilename, varname) # Check that varname was recovered succesfully if recovered_sol_i == sol[ind] println("Variable ", varname, " saved correctly" ) - else + else println("Recovered variable ", varname, " is not equal to the original" ) - end + end end println("Saved solution") @@ -116,39 +116,39 @@ end @doc raw""" day2sec(x::Matrix{Taylor1{U}}) where {U <: Number} -Convert `x` from days to seconds. +Convert `x` from days to seconds. """ function day2sec(x::Matrix{Taylor1{U}}) where {U <: Number} - - # Order of Taylor polynomials + + # Order of Taylor polynomials order = x[1, 1].order - # Matrix dimensions + # Matrix dimensions m, n = size(x) - # Taylor conversion variable + # Taylor conversion variable t = Taylor1(order) / daysec - # Allocate memory + # Allocate memory res = Matrix{Taylor1{U}}(undef, m, n) - # Iterate over the matrix + # Iterate over the matrix for j in 1:n for i in 1:m @inbounds res[i, j] = x[i, j](t) end end - return res + return res end @doc raw""" - propagate(maxsteps::Int, jd0::T, tspan::T, ::Val{false/true}; dynamics::Function = NBP_pN_A_J23E_J23M_J2S!, + propagate(maxsteps::Int, jd0::T, tspan::T, ::Val{false/true}; dynamics::Function = NBP_pN_A_J23E_J23M_J2S!, nast::Int = 343, order::Int = order, abstol::T = abstol, parse_eqs::Bool = true) where {T <: Real} -Integrate the Solar System via the Taylor method. +Integrate the Solar System via the Taylor method. -# Arguments +# Arguments - `maxsteps::Int`: maximum number of steps for the integration. - `jd0::T`: initial Julian date. -- `tspan::T`: time span of the integration (in Julian days). +- `tspan::T`: time span of the integration (in Julian days). - `::Val{false/true}`: whether to save the Taylor polynomials at each step (`true`) or not (`false`). - `output::Bool`: whether to write the output to a file (`true`) or not. - `ephfile::String`: name of the file where to save the solution if `ss16ast` is `false`. @@ -156,7 +156,7 @@ Integrate the Solar System via the Taylor method. - `nast::Int`: number of asteroids to be considered in the integration. - `ss16ast::Bool`: whether to save the solution using `selecteph2jld2` (`true`) or not. - `bodyind::AbstractVector{Int}`: indices of the bodies to be saved. -- `order::Int=order`: order of the Taylor expansions to be used in the integration. +- `order::Int=order`: order of the Taylor expansions to be used in the integration. - `abstol::T`: absolute tolerance. - `parse_eqs::Bool`: whether to use the specialized method of `jetcoeffs!` (`true`) created with `@taylorize` or not. """ propagate @@ -164,7 +164,7 @@ Integrate the Solar System via the Taylor method. for V_dense in (:(Val{true}), :(Val{false})) @eval begin - function propagate(maxsteps::Int, jd0::T, tspan::T, ::$V_dense; dynamics::Function = NBP_pN_A_J23E_J23M_J2S!, + function propagate(maxsteps::Int, jd0::T, tspan::T, ::$V_dense; dynamics::Function = NBP_pN_A_J23E_J23M_J2S!, nast::Int = 343, order::Int = order, abstol::T = abstol, parse_eqs::Bool = true) where {T <: Real} # Total number of bodies (Sun + 8 planets + Moon + Pluto + Asteroid) @@ -178,16 +178,16 @@ for V_dense in (:(Val{true}), :(Val{false})) # Parameters for dynamical function params = (N, jd0) - - + + # Final time of integration (days) tmax = t0 + tspan*yr - + # Integration sol_ = @time taylorinteg_threads(dynamics, q0, t0, tmax, order, abstol, $V_dense(), params, maxsteps = maxsteps, parse_eqs = parse_eqs) - - if $V_dense == Val{true} + + if $V_dense == Val{true} # Parameters for TaylorInterpolant @@ -203,27 +203,27 @@ for V_dense in (:(Val{true}), :(Val{false})) # Save ephemeris in TaylorInterpolant object sseph = TaylorInterpolant{T, T, 2}(et0, etv, sseph_x_et) - return sseph + return sseph else - + sol = (t = sol_[1][:], x = sol_[2][:, :]) - return sol + return sol + + end - end - - end + end - function propagate(maxsteps::Int, jd0::T1, tspan::T2, ::$V_dense; dynamics::Function = NBP_pN_A_J23E_J23M_J2S!, + function propagate(maxsteps::Int, jd0::T1, tspan::T2, ::$V_dense; dynamics::Function = NBP_pN_A_J23E_J23M_J2S!, nast::Int = 343, order::Int = order, abstol::T3 = abstol, parse_eqs::Bool = true) where {T1, T2, T3 <: Real} - - _jd0, _tspan, _abstol = promote(jd0, tspan, abstol) - return propagate(maxsteps, _jd0, _tspan, $V_dense(); dynamics = dynamics, nast = nast, order = order, + _jd0, _tspan, _abstol = promote(jd0, tspan, abstol) + + return propagate(maxsteps, _jd0, _tspan, $V_dense(); dynamics = dynamics, nast = nast, order = order, abstol = abstol, parse_eqs = parse_eqs) - end + end end -end +end