Skip to content

Commit

Permalink
📚 Apply new comment format
Browse files Browse the repository at this point in the history
  • Loading branch information
ronisbr committed Jan 21, 2024
1 parent 9363cb4 commit 94a4994
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 182 deletions.
13 changes: 5 additions & 8 deletions src/GravityModels/GravityModels.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
## Description #############################################################################
#
# Description
# ==========================================================================================
# Submodule to define the gravity model API.
#
# Submodule to define the gravity model API.
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
############################################################################################

module GravityModels

Expand All @@ -16,13 +13,13 @@ using SatelliteToolboxLegendre
using StaticArrays

############################################################################################
# Types
# Types #
############################################################################################

include("./types.jl")

############################################################################################
# Includes
# Includes #
############################################################################################

include("./api.jl")
Expand Down
41 changes: 17 additions & 24 deletions src/GravityModels/accelerations.jl
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
## Description #############################################################################
#
# Description
# ==========================================================================================
# Function to compute accelerations.
#
# Function to compute accelerations.
## References ##############################################################################
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# [1] Barthelmes, F (2013). Definition of Functions of the Geopotential and Their
# Calculation from Spherical Harmonic Models. Scientific Technical Report STR09/02.
# GeoForschungsZentrum (GFZ).
#
# References
# ==========================================================================================
#
# [1] Barthelmes, F (2013). Definition of Functions of the Geopotential and Their
# Calculation from Spherical Harmonic Models. Scientific Technical Report STR09/02.
# GeoForschungsZentrum (GFZ).
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
############################################################################################

"""
gravitational_acceleration(model::AbstractGravityModel{T}, r::AbstractVector, time::DateTime = DateTime("2000-01-01"); kwargs...) where T<:Number -> NTuple{3, T}
Expand Down Expand Up @@ -82,8 +76,7 @@ function gravitational_acceleration(
ϕ_gc = atan(r[3], ρ_gc)
λ_gc = atan(r[2], r[1])

# Acceleration represented in the ITRF
# ======================================================================================
# == Acceleration Represented in the ITRF ==============================================

# Compute the partial derivatives in spherical coordinate systems [1, p. 22] (eq. 120):
#
Expand Down Expand Up @@ -155,8 +148,7 @@ function gravity_acceleration(
dP::Union{Nothing, AbstractMatrix} = nothing
) where T<:Number

# Gravitational acceleration
# ======================================================================================
# == Gravitational Acceleration ========================================================

grav_itrf = gravitational_acceleration(
model,
Expand All @@ -168,12 +160,11 @@ function gravity_acceleration(
dP = dP
)

# Centripetal acceleration
# ======================================================================================
# == Centripetal acceleration ==========================================================
#
# The centripetal acceleration has the following value:
#
# cp_accel = ω² ⋅ r ⋅ cos(ϕ_gc),
# cp_accel = ω² r cos(ϕ_gc),
#
# where `ω` is the Earth's rotation rate, `r` is the distance from the Earth's center,
# and `ϕ_gc` is the geocentric latitude. Notice that:
Expand All @@ -190,7 +181,7 @@ function gravity_acceleration(
#
# Finally:
#
# cp_accel = ω² ρ_gc
# cp_accel = ω² ρ_gc

ρ²_gc = r[1]^2 + r[2]^2
r²_gc = ρ²_gc + r[3]^2
Expand All @@ -204,9 +195,11 @@ function gravity_acceleration(
# Applying the centrifugal potential in eq. 124 [1, p. 23] into eq. 120 [1, p. 22] and
# then converting from the UEN reference frame to ITRF, one gets:
#
# | ω² . r . cos(ϕ_gc) . cos(λ_gc) | | cos(λ_gc) |
# α_centrifugal = | 0 | = ω².r.cos(ϕ_gc) . | 0 |,
# | ω² . r . cos(ϕ_gc) . sin(λ_gc) | | sin(λ_gc) |
# ┌ ┐ ┌ ┐
# │ ω² r cos(ϕ_gc) cos(λ_gc) │ │ cos(λ_gc) │
# α_centrifugal = │ 0 │ = ω² r cos(ϕ_gc) │ 0 │,
# │ ω² r cos(ϕ_gc) sin(λ_gc) │ │ sin(λ_gc) │
# └ ┘ └ ┘
#
# where ω is the Earth rotation rate, cos(λ_gc) = r_x / √(r_x² + r_y²), and
# sin(λ_gc) = r_y / √(r_x² + r_y²).
Expand Down
9 changes: 3 additions & 6 deletions src/GravityModels/api.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
## Description #############################################################################
#
# Description
# ==========================================================================================
# Define the API functions for the gravity models.
#
# Define the API functions for the gravity models.
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
############################################################################################

"""
coefficients(model::AbstractGravityModel{T}, degree::Int, order::Int, time::DateTime = DateTime("2000-01-01")) where T<:Number -> T, T
Expand Down
39 changes: 13 additions & 26 deletions src/GravityModels/gravitational_field_derivative.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
## Description #############################################################################
#
# Description
# ==========================================================================================
# Function to compute the gravitational field derivative.
#
# Function to compute the gravitational field derivative.
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
############################################################################################

"""
gravitational_field_derivative(model::AbstractGravityModel{T}, r::AbstractVector, time::DateTime = DateTime("2000-01-01"); kwargs...) where T<:Number -> NTuple{3, T}
Expand Down Expand Up @@ -52,16 +49,14 @@ function gravitational_field_derivative(
dP::Union{Nothing, AbstractMatrix} = nothing
) where T<:Number

# Unpack gravity model data
# ======================================================================================
# == Unpack Gravity Model Data =========================================================

μ = gravity_constant(model)
R₀ = radius(model)
norm_type = coefficient_norm(model)
model_max_degree = maximum_degree(model)

# Process the inputs
# ======================================================================================
# == Process the Inputs ================================================================

# Check maximum degree value.
if (max_degree < 0) || (max_degree > model_max_degree)
Expand Down Expand Up @@ -119,8 +114,7 @@ function gravitational_field_derivative(
end
end

# Geocentric latitude and longitude
# ======================================================================================
# == Geocentric Latitude and Longitude =================================================

ρ²_gc = r[1]^2 + r[2]^2
r²_gc = ρ²_gc + r[3]^2
Expand All @@ -129,8 +123,7 @@ function gravitational_field_derivative(
ϕ_gc = atan(r[3], ρ_gc)
λ_gc = atan(r[2], r[1])

# Auxiliary variables
# ======================================================================================
# == Auxiliary Variables ===============================================================

# Sine and cosine of the geocentric longitude.
#
Expand All @@ -139,8 +132,7 @@ function gravitational_field_derivative(
sin_λ, cos_λ = sincos(λ_gc)
sin_2λ, cos_2λ = sincos(2λ_gc)

# First derivative of the non-spherical portion of the gravitational field
# ======================================================================================
# == First Derivative of the Non-Spherical Portion of the Gravitational Field ==========

∂U_∂r = T(1) # ........................................... Derivative w.r.t. the radius
∂U_∂ϕ = T(0) # .............................. Derivative w.r.t. the geocentric latitude
Expand All @@ -163,8 +155,7 @@ function gravitational_field_derivative(
aux_∂U_∂ϕ = T(0)
aux_∂U_∂λ = T(0)

# Sine and cosine with m = 1
# ==================================================================================
# == Sine and Cosine with m = 1 ====================================================
#
# This values will be used to update recursively `sin(m * λ_gc)` and
# `cos(m * λ_gc)`, reducing the computational burden.
Expand All @@ -180,31 +171,27 @@ function gravitational_field_derivative(
cos_m_1λ = +cos_λ # cos(-1 * λ_gc)
cos_m_2λ = +cos_2λ # cos(-2 * λ_gc)

# Compute the contributions when `m ∈ [1, min(n, m_max)]`
# ==================================================================================
# == Compute the Contributions When `m ∈ [1, min(n, m_max)]` =======================

for m in 0:min(n, m_max)
# Compute recursively `sin(m * λ_gc)` and `cos(m * λ_gc)`.
sin_mλ = 2cos_λ * sin_m_1λ - sin_m_2λ
cos_mλ = 2cos_λ * cos_m_1λ - cos_m_2λ

# Get the spherical harmonics coefficients
# ==============================================================================
# == Get the Spherical Harmonics Coefficients ==================================

clm, slm = coefficients(model, n, m, time)

CcSs_nm = clm * cos_mλ + slm * sin_mλ
ScCs_nm = slm * cos_mλ - clm * sin_mλ

# Compute the contributions for `m`
# ==============================================================================
# == Compute the Contributions for `m` =========================================

aux_∂U_∂r += P[n+1, m+1] * CcSs_nm
aux_∂U_∂ϕ += dP[n+1, m+1] * CcSs_nm
aux_∂U_∂λ += m * P[n+1, m+1] * ScCs_nm

# Update the values for the next step
# ==============================================================================
# == Update the Values for the Next Step =======================================

sin_m_2λ = sin_m_1λ
sin_m_1λ = sin_mλ
Expand Down
9 changes: 3 additions & 6 deletions src/GravityModels/types.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
## Description #############################################################################
#
# Description
# ==========================================================================================
# Types and structures for gravity models.
#
# Types and structures for gravity models.
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
############################################################################################

export AbstractGravityModel

Expand Down
8 changes: 4 additions & 4 deletions src/SatelliteToolboxGravityModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using Scratch
import Base: show

############################################################################################
# Submodules
# Submodules #
############################################################################################

include("./GravityModels/GravityModels.jl")
Expand All @@ -17,20 +17,20 @@ export GravityModels
export AbstractGravityModel

############################################################################################
# Types
# Types #
############################################################################################

include("./types.jl")

############################################################################################
# Constants
# Constants #
############################################################################################

const _D = Crayon(reset = true)
const _B = crayon"bold"

############################################################################################
# Includes
# Includes #
############################################################################################

include("./icgem/api.jl")
Expand Down
9 changes: 3 additions & 6 deletions src/icgem/api.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
## Description #############################################################################
#
# Description
# ==========================================================================================
# Functions related to the gravity model API.
#
# Functions related to the gravity model API.
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
############################################################################################

function GravityModels.coefficients(model::IcgemFile, degree::Int, order::Int, time::DateTime)
return icgem_coefficients(model, degree, order, time)
Expand Down
20 changes: 7 additions & 13 deletions src/icgem/compute.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
## Description #############################################################################
#
# Description
# ==========================================================================================
# Functions to compute the gravity model coefficients of a ICGEM file.
#
# Functions to compute the gravity model coefficients of a ICGEM file.
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
############################################################################################

"""
icgem_coefficients(model::IcgemFile{T}, degree::Int, order::Int, t::DateTime) where T<:Number -> T, T
Expand Down Expand Up @@ -37,7 +34,7 @@ function icgem_coefficients(
end

############################################################################################
# Private Functions
# Private Functions #
############################################################################################

# Compute the coefficients `Clm` and `Slm` for a coefficient of type `IcgemGfcCoefficient`.
Expand All @@ -56,16 +53,14 @@ function _compute_icgem_coefficient(
# Elapsed time from coefficients epoch [year].
Δt = T(Dates.value(t - coefficient.time) / 1000 / 86400 / 365)

# Trend
# ======================================================================================
# == Trend =============================================================================

if coefficient.has_trend
clm += coefficient.trend_clm * Δt
slm += coefficient.trend_slm * Δt
end

# asin
# ======================================================================================
# == asin ==============================================================================

for c in coefficient.asin_coefficients
A_clm, A_slm, p = c
Expand All @@ -75,8 +70,7 @@ function _compute_icgem_coefficient(
slm += A_slm * aux
end

# acos
# ======================================================================================
# == acos ==============================================================================

for c in coefficient.acos_coefficients
A_clm, A_slm, p = c
Expand Down
9 changes: 3 additions & 6 deletions src/icgem/fetch.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
## Description #############################################################################
#
# Description
# ==========================================================================================
# Function to fetch and store the ICGEM files.
#
# Function to fetch and store the ICGEM files.
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
############################################################################################

export fetch_icgem_file

Expand Down
Loading

0 comments on commit 94a4994

Please sign in to comment.