MOM_spherical_harmonics module reference

Laplace's spherical harmonic transforms (SHT)

Data Types

sht_CS

Control structure for spherical harmonic transforms

Functions/Subroutines

spherical_harmonics_forward

Calculates forward spherical harmonics transforms

spherical_harmonics_inverse

Calculates inverse spherical harmonics transforms

spherical_harmonics_init

Calculate precomputed coefficients

spherical_harmonics_end

Deallocate any variables allocated in spherical_harmonics_init

calc_lmax

Calculates the number of real elements (cosine) of spherical harmonics given maximum degree Nd.

order2index

Calculates the one-dimensional index number at (n=0, m=m), given order m and maximum degree Nd. It is sequenced with degree (n) changing first and order (m) changing second.

Detailed Description

Spherical harmonics

This module contains the subroutines to calculate spherical harmonic transforms (SHT), namely, forward transform of a two-dimensional field into a given number of spherical harmonic modes and its inverse transform. This module is primarily used to but not limited to calculate self-attraction and loading (SAL) term, which is mostly relevant to high frequency motions such as tides. Should other needs arise in the future, this API can be easily modified. Currently, the transforms are for t-cell fields only.

This module is stemmed from SAL calculation in Model for Prediction Across Scales (MPAS)-Ocean developed by Los Alamos National Laboratory and University of Michigan [[9] and [15]]. The algorithm for forward and inverse transforms loosely follows [73].

In forward transform, a two-dimensional physical field can be projected into a series of spherical harmonics. The spherical harmonic coefficient of degree n and order m for a field \(f(\theta, \phi)\) is calculated as follows:

\begin{equation*} f^m_n = \int^{2\pi}_{0}\int^{\pi}_{0}f(\theta,\phi)Y^m_n(\theta,\phi)\sin\theta d\theta d\phi \end{equation*}

and

\begin{equation*} Y^m_n(\theta,\phi) = P^m_n(\cos\theta)\exp(im\phi) \end{equation*}

where \(P^m_n(\cos \theta)\) is the normalized associated Legendre polynomial of degree n and order m. \(\phi\) is the longitude and \(\theta\) is the colatitude. Or, written in the discretized form:

\begin{equation*} f^m_n = \sum^{Nj}_{0}\sum^{Ni}_{0}f(i,j)Y^m_n(i,j)A(i,j)/r_e^2 \end{equation*}

where \(A\) is the area of the cell and \(r_e\) is the radius of the Earth.

In inverse transform, the first N degree spherical harmonic coefficients are used to reconstruct a two-dimensional physical field:

\begin{equation*} f(\theta,\phi) = \sum^N_{n=0}\sum^{n}_{m=-n}f^m_nY^m_n(\theta,\phi) \end{equation*}

The exponential coefficients are pre-computed and stored in the memory. The associated Legendre polynomials are computed "on-the-fly", using the recurrence relationships to avoid large memory usage and take the advantage of array vectorization.

The maximum degree of the spherical harmonics is a runtime parameter and the maximum used by all SHT applications. At the moment, it is only decided by SAL_HARMONICS_DEGREE.

The forward transforms involve a global summation. Runtime flag SHT_REPRODUCING_SUM controls whether this is done in a bit-wise reproducing way or not.

References:

Barton, K.N., Pal, N., Brus, S.R., Petersen, M.R., Arbic, B.K., Engwirda, D., Roberts, A.F., Westerink, J.J., Wirasaet, D. and Schindelegger, M., 2022. Global Barotropic Tide Modeling Using Inline Self‐Attraction and Loading in MPAS‐Ocean. Journal of Advances in Modeling Earth Systems, 14(11), p.e2022MS003207. https://doi.org/10.1029/2022MS003207

Brus, S.R., Barton, K.N., Pal, N., Roberts, A.F., Engwirda, D., Petersen, M.R., Arbic, B.K., Wirasaet, D., Westerink, J.J. and Schindelegger, M., 2023. Scalable self attraction and loading calculations for unstructured ocean tide models. Ocean Modelling, p.102160. https://doi.org/10.1016/j.ocemod.2023.102160

Schaeffer, N., 2013. Efficient spherical harmonic transforms aimed at pseudospectral numerical simulations. Geochemistry, Geophysics, Geosystems, 14(3), pp.751-758. https://doi.org/10.1002/ggge.20071

Type Documentation

type, public :: sht_CS

Control structure for spherical harmonic transforms

Parameters
  • initialized

    True if this control structure has been initialized.

  • ndegree

    Maximum degree of the spherical harmonics [nondim].

  • lmax

    Number of associated Legendre polynomials of nonnegative m [lmax=(ndegree+1)*(ndegree+2)/2] [nondim].

  • cos_clatT

    Precomputed cosine of colatitude at the t-cells [nondim].

  • Pmm

    Precomputed associated Legendre polynomials (m=n) at the t-cells [nondim].

  • cos_lonT

    Precomputed cosine factors at the t-cells [nondim].

  • sin_lonT

    Precomputed sine factors at the t-cells [nondim].

  • cos_lonT_wtd

    Precomputed area-weighted cosine factors at the t-cells [nondim]

  • sin_lonT_wtd

    Precomputed area-weighted sine factors at the t-cells [nondim]

  • a_recur

    Precomputed recurrence coefficients a [nondim].

  • b_recur

    Precomputed recurrence coefficients b [nondim].

  • reprod_sum

    True if use reproducible global sums

Functions/Subroutine Documentation

subroutine spherical_harmonics_forward(G, CS, var, Snm_Re, Snm_Im, Nd, tmp_scale)

Calculates forward spherical harmonics transforms

Parameters
  • G [in]

    The ocean's grid structure.

  • CS [inout]

    Control structure for SHT

  • var [in]

    Input 2-D variable in arbitrary mks units [a] or in arbitrary rescaled units [A ~> a] if tmp_scale is present

  • Snm_Re [out]

    SHT coefficients for the real modes (cosine) in the same arbitrary units as var [a] or [A ~> a]

  • Snm_Im [out]

    SHT coefficients for the imaginary modes (sine) in the same arbitrary units as var [a] or [A ~> a]

  • Nd [in]

    Maximum degree of the spherical harmonics overriding ndegree in the CS [nondim]

  • tmp_scale [in]

    A temporary rescaling factor to convert var to MKS units during the reproducing sums [a A-1 ~> 1]

Callees call graph
Callees of mom_spherical_harmonics::spherical_harmonics_forward calls cluster_mom_coms MOM_coms cluster_mom_coms_infra MOM_coms_infra cluster_mom_cpu_clock_infra MOM_cpu_clock_infra cluster_mom_error_handler MOM_error_handler cluster_mom_spherical_harmonics MOM_spherical_harmonics mom_coms::interface::reproducing_sum reproducing_sum (interface) mom_coms_infra::interface::sum_across_pes sum_across_PEs (interface) mom_cpu_clock_infra::cpu_clock_begin cpu_clock_begin mom_cpu_clock_infra::cpu_clock_end cpu_clock_end mom_error_handler::mom_error MOM_error mom_spherical_harmonics::calc_lmax calc_lmax mom_spherical_harmonics::order2index order2index mom_spherical_harmonics::spherical_harmonics_forward spherical_harmonics_forward mom_spherical_harmonics::spherical_harmonics_forward->mom_coms::interface::reproducing_sum mom_spherical_harmonics::spherical_harmonics_forward->mom_coms_infra::interface::sum_across_pes mom_spherical_harmonics::spherical_harmonics_forward->mom_cpu_clock_infra::cpu_clock_begin mom_spherical_harmonics::spherical_harmonics_forward->mom_cpu_clock_infra::cpu_clock_end mom_spherical_harmonics::spherical_harmonics_forward->mom_error_handler::mom_error mom_spherical_harmonics::spherical_harmonics_forward->mom_spherical_harmonics::calc_lmax mom_spherical_harmonics::spherical_harmonics_forward->mom_spherical_harmonics::order2index
Text view
Callers call graph
Callers of mom_spherical_harmonics::spherical_harmonics_forward calls cluster_mom_self_attr_load MOM_self_attr_load cluster_mom_spherical_harmonics MOM_spherical_harmonics mom_self_attr_load::calc_sal calc_SAL mom_spherical_harmonics::spherical_harmonics_forward spherical_harmonics_forward mom_self_attr_load::calc_sal->mom_spherical_harmonics::spherical_harmonics_forward
Text view
subroutine spherical_harmonics_inverse(G, CS, Snm_Re, Snm_Im, var, Nd)

Calculates inverse spherical harmonics transforms

Parameters
  • G [in]

    The ocean's grid structure.

  • CS [in]

    Control structure for SHT

  • Snm_Re [in]

    SHT coefficients for the real modes (cosine) in arbitrary units [a] or [A ~> a]

  • Snm_Im [in]

    SHT coefficients for the imaginary modes (sine) in the same arbitrary units as Snm_Re [a] or [A ~> a]

  • var [out]

    Output 2-D variable in the same arbitrary units as Snm_Re and Snm_Im [a] or [A ~> a]

  • Nd [in]

    Maximum degree of the spherical harmonics overriding ndegree in the CS [nondim]

Callees call graph
Callees of mom_spherical_harmonics::spherical_harmonics_inverse calls cluster_mom_cpu_clock_infra MOM_cpu_clock_infra cluster_mom_error_handler MOM_error_handler cluster_mom_spherical_harmonics MOM_spherical_harmonics mom_cpu_clock_infra::cpu_clock_begin cpu_clock_begin mom_cpu_clock_infra::cpu_clock_end cpu_clock_end mom_error_handler::mom_error MOM_error mom_spherical_harmonics::order2index order2index mom_spherical_harmonics::spherical_harmonics_inverse spherical_harmonics_inverse mom_spherical_harmonics::spherical_harmonics_inverse->mom_cpu_clock_infra::cpu_clock_begin mom_spherical_harmonics::spherical_harmonics_inverse->mom_cpu_clock_infra::cpu_clock_end mom_spherical_harmonics::spherical_harmonics_inverse->mom_error_handler::mom_error mom_spherical_harmonics::spherical_harmonics_inverse->mom_spherical_harmonics::order2index
Text view
Callers call graph
Callers of mom_spherical_harmonics::spherical_harmonics_inverse calls cluster_mom_self_attr_load MOM_self_attr_load cluster_mom_spherical_harmonics MOM_spherical_harmonics mom_self_attr_load::calc_sal calc_SAL mom_spherical_harmonics::spherical_harmonics_inverse spherical_harmonics_inverse mom_self_attr_load::calc_sal->mom_spherical_harmonics::spherical_harmonics_inverse
Text view
subroutine spherical_harmonics_init(G, param_file, CS)

Calculate precomputed coefficients

Parameters
  • G [in]

    The ocean's grid structure.

  • param_file [in]

    A structure indicating

  • CS [inout]

    Control structure for spherical harmonic transforms

Callees call graph
Callees of mom_spherical_harmonics::spherical_harmonics_init calls cluster_mom_cpu_clock_infra MOM_cpu_clock_infra cluster_mom_file_parser MOM_file_parser cluster_mom_spherical_harmonics MOM_spherical_harmonics mom_cpu_clock_infra::cpu_clock_id cpu_clock_id mom_file_parser::interface::get_param get_param (interface) mom_file_parser::interface::log_version log_version (interface) mom_spherical_harmonics::calc_lmax calc_lmax mom_spherical_harmonics::spherical_harmonics_init spherical_harmonics_init mom_spherical_harmonics::spherical_harmonics_init->mom_cpu_clock_infra::cpu_clock_id mom_spherical_harmonics::spherical_harmonics_init->mom_file_parser::interface::get_param mom_spherical_harmonics::spherical_harmonics_init->mom_file_parser::interface::log_version mom_spherical_harmonics::spherical_harmonics_init->mom_spherical_harmonics::calc_lmax
Text view
Callers call graph
Callers of mom_spherical_harmonics::spherical_harmonics_init calls cluster_mom_self_attr_load MOM_self_attr_load cluster_mom_spherical_harmonics MOM_spherical_harmonics mom_self_attr_load::sal_init SAL_init mom_spherical_harmonics::spherical_harmonics_init spherical_harmonics_init mom_self_attr_load::sal_init->mom_spherical_harmonics::spherical_harmonics_init
Text view
subroutine spherical_harmonics_end(CS)

Deallocate any variables allocated in spherical_harmonics_init

Parameters
  • CS [inout]

    Control structure for spherical harmonic transforms

Callers call graph
Callers of mom_spherical_harmonics::spherical_harmonics_end calls cluster_mom_self_attr_load MOM_self_attr_load cluster_mom_spherical_harmonics MOM_spherical_harmonics mom_self_attr_load::sal_end SAL_end mom_spherical_harmonics::spherical_harmonics_end spherical_harmonics_end mom_self_attr_load::sal_end->mom_spherical_harmonics::spherical_harmonics_end
Text view
function calc_lmax(Nd) result(lmax)

Calculates the number of real elements (cosine) of spherical harmonics given maximum degree Nd.

Parameters
  • lmax

    Number of real spherical harmonic modes [nondim]

  • Nd [in]

    Maximum degree [nondim]

Callers call graph
Callers of mom_spherical_harmonics::calc_lmax calls cluster_mom_self_attr_load MOM_self_attr_load cluster_mom_spherical_harmonics MOM_spherical_harmonics mom_self_attr_load::sal_init SAL_init mom_spherical_harmonics::calc_lmax calc_lmax mom_self_attr_load::sal_init->mom_spherical_harmonics::calc_lmax mom_spherical_harmonics::spherical_harmonics_forward spherical_harmonics_forward mom_spherical_harmonics::spherical_harmonics_forward->mom_spherical_harmonics::calc_lmax mom_spherical_harmonics::spherical_harmonics_init spherical_harmonics_init mom_spherical_harmonics::spherical_harmonics_init->mom_spherical_harmonics::calc_lmax
Text view
function order2index(m, Nd) result(l)

Calculates the one-dimensional index number at (n=0, m=m), given order m and maximum degree Nd. It is sequenced with degree (n) changing first and order (m) changing second.

Parameters
  • l

    One-dimensional index number [nondim]

  • m [in]

    Current order number [nondim]

  • Nd [in]

    Maximum degree [nondim]

Callers call graph
Callers of mom_spherical_harmonics::order2index calls cluster_mom_self_attr_load MOM_self_attr_load cluster_mom_spherical_harmonics MOM_spherical_harmonics mom_self_attr_load::calc_love_scaling calc_love_scaling [private/internal] mom_spherical_harmonics::order2index order2index mom_self_attr_load::calc_love_scaling->mom_spherical_harmonics::order2index mom_self_attr_load::calc_sal calc_SAL mom_self_attr_load::calc_sal->mom_spherical_harmonics::order2index mom_spherical_harmonics::spherical_harmonics_forward spherical_harmonics_forward mom_spherical_harmonics::spherical_harmonics_forward->mom_spherical_harmonics::order2index mom_spherical_harmonics::spherical_harmonics_inverse spherical_harmonics_inverse mom_spherical_harmonics::spherical_harmonics_inverse->mom_spherical_harmonics::order2index
Text view
API generated with Flint · Rendered from reStructuredText