Skip to content

Commit

Permalink
Fix JuliaRegistrator auto-merging; add @LuEdRaMo as co-author (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
PerezHz authored Apr 2, 2023
1 parent 0af6c0d commit 4747aad
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 57 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
110 changes: 55 additions & 55 deletions src/propagation.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
@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}
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"""
Expand All @@ -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
Expand All @@ -54,58 +54,58 @@ 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")
if recovered_sol_i == ss16ast_eph
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")
Expand All @@ -116,55 +116,55 @@ 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`.
- `dynamics::Function`: dynamical model function.
- `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

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)
Expand All @@ -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

Expand All @@ -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

2 comments on commit 4747aad

@PerezHz
Copy link
Owner Author

@PerezHz PerezHz commented on 4747aad Apr 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/80847

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.0 -m "<description of version>" 4747aad2c9b6f936cf9d2f14a62942d18abd6139
git push origin v0.3.0

Please sign in to comment.