Public Types | Public Member Functions | List of all members
SpherepackIterator Class Reference

Iterates over spectral coefficients stored in SPHEREPACK format. More...

#include <SpherepackIterator.hpp>

Public Types

enum  CoefficientArray { a, b }
 SPHEREPACK has two coefficient variables, 'a' and 'b', that hold the cos(m*phi) and sin(m*phi) parts of the spectral coefficients.

Public Member Functions

 SpherepackIterator (size_t l_max_input, size_t m_max_input, size_t stride=1)
size_t l_max () const noexcept
size_t m_max () const noexcept
size_t n_th () const noexcept
size_t n_ph () const noexcept
size_t stride () const noexcept
size_t spherepack_array_size () const noexcept
 Size of a SPHEREPACK coefficient array (a and b combined), not counting stride. For non-unit stride, the size of the array should be spherepack_array_size()*stride.
SpherepackIteratoroperator++ () noexcept
 operator bool () const noexcept
size_t operator() () const noexcept
 Current index into a SPHEREPACK coefficient array.
size_t l () const noexcept
 Current values of l and m.
size_t m () const noexcept
CoefficientArray coefficient_array () const noexcept
 Whether the iterator points to an element of 'a' or 'b', i.e. points to the cos(m*phi) or sin(m*phi) part of a spectral coefficient.
SpherepackIteratorreset () noexcept
 Reset iterator back to beginning value. Returns *this.
SpherepackIteratorset (size_t l_input, size_t m_input, CoefficientArray coefficient_array_input) noexcept
 Set iterator to specific value of l, m, array. Returns *this.
SpherepackIteratorset (size_t l_input, int m_input) noexcept
 Same as 'set' above, but assumes CoefficientArray is 'a' for m>=0 and 'b' for m<0. This is useful when converting between true spherical harmonics (which allow negative values of m) and SPHEREPACK coefficients (which have only positive values of m, but two arrays for sin(m*phi) and cos(m*phi) parts).

Detailed Description

Iterates over spectral coefficients stored in SPHEREPACK format.


The internal SPHEREPACK ordering is not intuitive, so SpherepackIterator exists for the purpose of iterating over an array containing SPHEREPACK coefficients and determining the (l,m) of each entry in the array.

SPHEREPACK expands \(f(\theta,\phi)\) as

\[ f(\theta,\phi) = \frac{1}{2} \sum_{l=0}^{l_{max}} \bar{P}_l^0 a(0,l) + \sum_{m=1}^{m_{max}} \sum_{l=m}^{l_{max}} \bar{P}_l^m \left( a(m,l) \cos(m \phi) - b(m,l) \sin(m \phi)\right) \]

where \(a(m,l)\) and \(b(m,l)\) are the SPHEREPACK spectral coefficients, and \(\bar{P}_l^m\) are unit-orthonormal associated Legendre polynomials:

\[ \bar{P}_l^m = (-1)^m \sqrt{\frac{(2l+1)(l-m)!}{2(l+m)!}} P_l^m, \]

where \(P_l^m\) are the associated Legendre polynomials as defined for example in Jackson "Classical Electrodynamics".


const size_t l_max = 4;
const size_t m_max = 2;
const size_t stride = 5;
SpherepackIterator iter(l_max, m_max, stride);
// Allocate space for a SPHEREPACK array
std::vector<double> array(iter.spherepack_array_size() * stride);
// Set each array element equal to l+m for real part
// and l-m for imaginary part.
size_t i = 0;
for (iter.reset(); iter; ++iter, ++i) {
if (iter.coefficient_array() == SpherepackIterator::CoefficientArray::a) {
array[iter()] = iter.l() + iter.m();
} else {
array[iter()] = iter.l() - iter.m();
CHECK(iter.l() == test_l[i]);
CHECK(iter.m() == test_m[i]);
CHECK(iter() == test_index[i]);

The documentation for this class was generated from the following files: