24 typedef std::complex<double>
cplx;
25 typedef std::complex<float>
cplx_f;
28 typedef _Complex
double cplx;
38#define SHTNS_INTERFACE 0x307A0
53#define SHT_NO_CS_PHASE (256*4)
54#define SHT_REAL_NORM (256*8)
66#define SHT_NATIVE_LAYOUT 0
67#define SHT_THETA_CONTIGUOUS 256
68#define SHT_PHI_CONTIGUOUS (256*2)
69#define SHT_SOUTH_POLE_FIRST (256*32)
71#define SHT_SCALAR_ONLY (256*16)
72#define SHT_LOAD_SAVE_CFG (256*64)
73#define SHT_ALLOW_GPU (256*128)
74#define SHT_ALLOW_PADDING (256*256)
75#define SHT_ROBERT_FORM (256*512)
76#define SHT_FP32 (256*1024)
81 const unsigned int nlm;
89 const unsigned short *
const li;
90 const unsigned short *
const mi;
91 const double *
const ct;
92 const double *
const st;
106#define LiM(shtns, l,im) ( (((im)*(2*shtns->lmax + 2 - ((im)+1)*shtns->mres))>>1) + (l) )
108#define LM(shtns, l,m) ( (((((unsigned short)(m))/shtns->mres)*(2*shtns->lmax + 2 - ((m)+shtns->mres)))>>1) + (l) )
111#define LM_LOOP( shtns, action ) { int lm=0; do { action } while(++lm < shtns->nlm); }
114#define LM_L_LOOP( shtns, action ) { int lm=0; do { int l=shtns->li[lm]; action } while(++lm < shtns->nlm); }
116#define LM_cplx(shtns, l, m) ( ((l) <= shtns->mmax) ? (l)*((l)+1)+(m) : shtns->mmax*(2*(l) - shtns->mmax) + (l)+(m) )
122#define NSPAT_ALLOC(shtns) (shtns->nspat)
127#define PHI_DEG(shtns, ip) (360./(shtns->nphi*shtns->mres))*(ip)
129#define PHI_RAD(shtns, ip) (2.*M_PI/(shtns->nphi*shtns->mres))*(ip)
135long nlm_calc(
long lmax,
long mmax,
long mres);
241int legendre_sphPlm_deriv_array(
shtns_cfg shtns,
const int lmax,
const int im,
const double x,
const double sint,
double *yl,
double *dyl);
308#define SH_to_grad_spat(shtns, S,Gt,Gp) SHsph_to_spat(shtns, S, Gt, Gp)
330void SHsphtor_to_spat_l(
shtns_cfg,
cplx *Slm,
cplx *Tlm,
double *Vt,
double *Vp,
int ltr);
331void SHsph_to_spat_l(
shtns_cfg,
cplx *Slm,
double *Vt,
double *Vp,
int ltr);
332void SHtor_to_spat_l(
shtns_cfg,
cplx *Tlm,
double *Vt,
double *Vp,
int ltr);
333void spat_to_SHsphtor_l(
shtns_cfg,
double *Vt,
double *Vp,
cplx *Slm,
cplx *Tlm,
int ltr);
335void spat_to_SHqst_l(
shtns_cfg,
double *Vr,
double *Vt,
double *Vp,
cplx *Qlm,
cplx *Slm,
cplx *Tlm,
int ltr);
336void SHqst_to_spat_l(
shtns_cfg,
cplx *Qlm,
cplx *Slm,
cplx *Tlm,
double *Vr,
double *Vt,
double *Vp,
int ltr);
339#define SH_to_grad_spat_l(shtns, S,Gt,Gp,ltr) SHsph_to_spat_l(shtns, S, Gt, Gp, ltr)
357#define SH_to_grad_spat_ml(shtns, im, S,Gt,Gp,ltr) SHsph_to_spat_ml(shtns, im, S, Gt, Gp, ltr)
367 double cost,
double phi,
double *vr,
double *vt,
double *vp);
369 double cost,
double phi,
double *vr,
double *vt,
double *vp);
372 double *vr,
int nphi,
int ltr,
int mtr);
374 double *vr,
double *vt,
double *vp,
int nphi,
int ltr,
int mtr);
void shtns_rotation_set_angle_axis(shtns_rot r, double theta, double Vx, double Vy, double Vz)
Defines a rotation of angle theta around axis of cartesian coordinates (Vx,Vy,Vz).
Definition sht_func.c:1511
void SH_Xrotate90(shtns_cfg, cplx *Qlm, cplx *Rlm)
rotate Qlm by 90 degrees around X axis and store the result in Rlm.
Definition sht_func.c:367
void SH_Yrotate(shtns_cfg, cplx *Qlm, double alpha, cplx *Rlm)
rotate Qlm around Y axis by arbitrary angle, using composition of rotations. Store the result in Rlm.
Definition sht_func.c:404
void shtns_rotation_apply_cplx(shtns_rot r, cplx *Zlm, cplx *Rlm)
apply rotation to the orthonormal spherical harmonic expansion Zlm of a complex-valued field,...
Definition sht_func.c:1977
void SH_Zrotate(shtns_cfg, cplx *Qlm, double alpha, cplx *Rlm)
Rotate a SH representation Qlm around the z-axis by angle alpha (in radians), which is the same as ro...
Definition sht_func.c:38
void shtns_rotation_destroy(shtns_rot r)
Release memory allocated for the rotation object.
Definition sht_func.c:1436
void shtns_rotation_set_angles_ZXZ(shtns_rot r, double alpha, double beta, double gamma)
Defines a rotation parameterized by the 3 intrinsic Euler angles with ZXZ convention.
Definition sht_func.c:1505
void SH_Yrotate90(shtns_cfg, cplx *Qlm, cplx *Rlm)
rotate Qlm by 90 degrees around Y axis and store the result in Rlm.
Definition sht_func.c:386
shtns_rot shtns_rotation_create(const int lmax, const int mmax, int norm)
Creation of a spherical harmonic rotation object for degrees and orders up to lmax and mmax respectiv...
Definition sht_func.c:1419
void shtns_rotation_set_angles_ZYZ(shtns_rot r, double alpha, double beta, double gamma)
Defines a rotation parameterized by the 3 intrinsic Euler angles with ZYZ convention.
Definition sht_func.c:1468
void shtns_rotation_apply_real(shtns_rot r, cplx *Qlm, cplx *Rlm)
apply rotation to the orthonormal spherical harmonic expansion Qlm of a real field,...
Definition sht_func.c:1695
int shtns_rotation_wigner_d_matrix(shtns_rot r, const int l, double *mx)
Generate spherical-harmonic rotation matrix for given degree l and orthonormal convention (Wigner-d m...
Definition sht_func.c:1612
int shtns_set_many(shtns_cfg shtns, int howmany, long spec_dist)
Sets the number of transforms to be performed together (batch). Must be called before shtns_set_grid ...
Definition sht_init.c:1561
void shtns_destroy(shtns_cfg)
free memory of given config, which cannot be used afterwards.
Definition sht_init.c:1268
int shtns_use_threads(int num_threads)
Enables multi-thread transform using OpenMP with num_threads (if available). Returns number of thread...
Definition sht_init.c:1605
int shtns_set_grid(shtns_cfg, enum shtns_type flags, double eps, int nlat, int nphi)
Precompute everything for a given spatial grid. Use for advanced initialization, after shtns_create.
Definition sht_init.c:1544
void * shtns_malloc(size_t bytes)
allocate appropriate CPU memory (pinned for gpu, aligned for avx, ...). Use shtns_free to free it.
Definition sht_init.c:1316
shtns_cfg shtns_create(int lmax, int mmax, int mres, enum shtns_norm norm)
Defines the sizes of the spectral description. Use for advanced initialization.
Definition sht_init.c:1100
void shtns_unset_grid(shtns_cfg)
unset the grid.
Definition sht_init.c:1258
void shtns_reset(void)
destroy all configs, free memory, and go back to initial state.
Definition sht_init.c:1310
shtns_cfg shtns_init(enum shtns_type flags, int lmax, int mmax, int mres, int nlat, int nphi)
Simple initialization of the spherical harmonic transforms of given size. Calls shtns_create and shtn...
Definition sht_init.c:1583
shtns_cfg shtns_create_with_grid(shtns_cfg, int mmax, int nofft)
Copy a given config but allow a different (smaller) mmax and the possibility to enable/disable fft.
Definition sht_init.c:1225
long nlm_cplx_calc(long lmax, long mmax, long mres)
compute number of spherical harmonics modes (l,m) to represent a complex-valued spatial field,...
Definition sht_init.c:106
int shtns_gauss_wts(shtns_cfg, double *wts)
fill the given array with Gauss weights. returns the number of weights written (0 if not a Gauss grid...
Definition sht_init.c:1621
long nlm_calc(long lmax, long mmax, long mres)
compute number of spherical harmonics modes (l,m) to represent a real-valued spatial field for given ...
Definition sht_init.c:98
void shtns_free(void *p)
free memory allocated with shtns_malloc
Definition sht_init.c:1320
void shtns_robert_form(shtns_cfg, int robert)
set the use of Robert form. If robert != 0, the vector synthesis returns a field multiplied by sin(th...
Definition sht_init.c:1592
int shtns_set_grid_auto(shtns_cfg, enum shtns_type flags, double eps, int nl_order, int *nlat, int *nphi)
Precompute everything and choose the optimal nlat and nphi for a given non-linear order.
Definition sht_init.c:1353
void SHqst_to_point(shtns_cfg, cplx *Qlm, cplx *Slm, cplx *Tlm, double cost, double phi, double *vr, double *vt, double *vp)
Evaluate vector SH representation Qlm at physical point defined by cost = cos(theta) and phi.
Definition sht_func.c:694
void SH_to_point_cplx(shtns_cfg, cplx *alm, double cost, double phi, cplx *z_out)
writes value to z_out.
Definition sht_func.c:541
void SH_to_lat(shtns_cfg shtns, cplx *Qlm, double cost, double *vr, int nphi, int ltr, int mtr)
synthesis at a given latitude, on nphi equispaced longitude points.
Definition sht_func.c:840
void SHqst_to_lat(shtns_cfg, cplx *Qlm, cplx *Slm, cplx *Tlm, double cost, double *vr, double *vt, double *vp, int nphi, int ltr, int mtr)
synthesis at a given latitude, on nphi equispaced longitude points.
Definition sht_func.c:757
double SH_to_point(shtns_cfg, cplx *Qlm, double cost, double phi)
Evaluate scalar SH representation Qlm at physical point defined by cost = cos(theta) and phi.
Definition sht_func.c:610
void SH_mul_mx(shtns_cfg, double *mx, cplx *Qlm, cplx *Rlm)
Apply a matrix involving l+1 and l-1 to an SH representation Qlm. Result stored in Rlm (must be diffe...
Definition sht_func.c:509
void st_dt_matrix(shtns_cfg, double *mx)
compute the matrix (stored in mx, a double array of size 2*NLM) required to apply sin(theta)*d/dtheta...
Definition sht_func.c:496
void mul_ct_matrix(shtns_cfg, double *mx)
compute the matrix (stored in mx, a double array of size 2*NLM) required to multiply an SH representa...
Definition sht_func.c:478
void SHqst_to_spat(shtns_cfg, cplx *Qlm, cplx *Slm, cplx *Tlm, double *Vr, double *Vt, double *Vp)
3D vector transform from radial-spheroidal-toroidal spectral components (see Radial - Spheroidal - To...
Definition sht_com.c:65
void SHtor_to_spat(shtns_cfg, cplx *Tlm, double *Vt, double *Vp)
transform toroidal spherical harmonic coefficients Tlm to the spatial theta and phi components (Vt,...
Definition sht_com.c:73
void SHqst_to_spat_cplx(shtns_cfg, cplx *Qlm, cplx *Slm, cplx *Tlm, cplx *Vr, cplx *Vt, cplx *Vp)
complex vector transform (3D).
Definition sht_func.c:1231
void SHsph_to_spat(shtns_cfg, cplx *Slm, double *Vt, double *Vp)
transform spheroidal spherical harmonic coefficients Slm to the spatial theta and phi components (Vt,...
Definition sht_com.c:77
void SHsphtor_to_spat(shtns_cfg, cplx *Slm, cplx *Tlm, double *Vt, double *Vp)
transform spheroidal-toroidal spherical harmonic coefficients (Slm,Tlm) to the spatial theta and phi ...
Definition sht_com.c:57
void spat_to_SHqst(shtns_cfg, double *Vr, double *Vt, double *Vp, cplx *Qlm, cplx *Slm, cplx *Tlm)
3D vector transform from spherical coordinates to radial-spheroidal-toroidal spectral components (see...
Definition sht_com.c:69
void SHsphtor_to_spat_cplx(shtns_cfg, cplx *Slm, cplx *Tlm, cplx *Vt, cplx *Vp)
transform spheroidal-toroidal spherical harmonic coefficients (Slm,Tlm) to the spatial theta and phi ...
Definition sht_func.c:1085
void spat_cplx_to_SHsphtor(shtns_cfg, cplx *Vt, cplx *Vp, cplx *Slm, cplx *Tlm)
transform the theta and phi components (Vt,Vp) of a complex valued vector into its spheroidal-toroida...
Definition sht_func.c:1160
void spat_to_SH(shtns_cfg shtns, double *Vr, cplx *Qlm)
transform the scalar field Vr into its spherical harmonic representation Qlm.
Definition sht_com.c:53
void SH_to_spat(shtns_cfg shtns, cplx *Qlm, double *Vr)
transform the spherical harmonic coefficients Qlm into its spatial representation Vr.
Definition sht_com.c:49
void spat_cplx_to_SHqst(shtns_cfg, cplx *Vr, cplx *Vt, cplx *Vp, cplx *Qlm, cplx *Slm, cplx *Tlm)
complex vector transform (3D).
Definition sht_func.c:1222
void SH_to_spat_cplx(shtns_cfg shtns, cplx *alm, cplx *z)
complex scalar synthesis.
Definition sht_func.c:1023
void spat_cplx_to_SH(shtns_cfg shtns, cplx *z, cplx *alm)
complex scalar analysis.
Definition sht_func.c:968
void spat_to_SHsphtor(shtns_cfg, double *Vt, double *Vp, cplx *Slm, cplx *Tlm)
transform the theta and phi components (Vt,Vp) of a vector into its spheroidal-toroidal spherical har...
Definition sht_com.c:61
struct shtns_rot_ * shtns_rot
pointer to data structure describing a rotation, returned by shtns_rotation_create().
Definition shtns.h:44
int im_from_lm(long lm, int lmax, int mres)
returns index im = m/mres where m is order of index lm into spherical harmonic array.
Definition sht_init.c:116
_Complex double cplx
double precision complex number data type
Definition shtns.h:28
const char * shtns_get_build_info(void)
get version and build information as a string (the same as the one printed by shtns_print_version())
Definition sht_init.c:920
double sh10_ct(shtns_cfg)
return the spherical harmonic representation of cos(theta) (l=1,m=0)
Definition sht_init.c:81
void shtns_verbose(int)
controls output during initialization: 0=no output (default), 1=some output, 2=degug (if compiled in)
Definition sht_init.c:51
void shtns_profiling(shtns_cfg shtns, int on)
on!=0: turn profiling on, on==0: turn off
Definition sht_init.c:173
void shtns_print_version(void)
print version information to stdout.
Definition sht_init.c:944
double spat_to_SH_time(shtns_cfg shtns, double *Vr, cplx *Qlm)
same as spat_to_SH() but with time recording; returns time in seconds
Definition sht_com.c:39
int legendre_sphPlm_array(shtns_cfg shtns, const int lmax, const int im, const double x, double *yl)
Compute values of legendre polynomials noramalized for spherical harmonics, for a range of l=m....
double shtns_profiling_read_time(shtns_cfg shtns, double *t1, double *t2)
read timers of last transform. total time is returned, time for legendre and fourier are put in t1 an...
Definition sht_init.c:180
void shtns_print_cfg(shtns_cfg)
print information about given config to stdout.
Definition sht_init.c:965
double shlm_e1(shtns_cfg, int l, int m)
return the l,m SH coefficient corresponding to unit energy.
Definition sht_init.c:89
double sh00_1(shtns_cfg)
return the spherical harmonic representation of 1 (l=0,m=0)
Definition sht_init.c:77
struct shtns_info * shtns_cfg
pointer to data structure describing an SHT, returned by shtns_init() or shtns_create().
Definition shtns.h:41
_Complex float cplx_f
single precision (float) complex number data type
Definition shtns.h:29
shtns_type
different SHT types and algorithms
Definition shtns.h:57
@ sht_quick_init
gauss grid, with minimum initialization time (useful for pre/post-processing)
Definition shtns.h:62
@ sht_reg_poles
quick initialization of a regular grid including poles (Clenshaw-Curtis quadrature)....
Definition shtns.h:63
@ sht_reg_dct
slow initialization of a regular grid (self-tuning). The grid is equispaced and avoids the poles (Féj...
Definition shtns.h:61
@ sht_auto
use fastest algorithm and grid. This currently implies using the Gauss grid and is thus the same as s...
Definition shtns.h:59
@ sht_reg_fast
quick initialization of a regular grid. The grid is the same as with sht_reg_dct
Definition shtns.h:60
@ sht_gauss_fly
legendre polynomials are recomputed on-the-fly for each transform (may be faster on some machines,...
Definition shtns.h:64
@ sht_gauss
use gaussian grid and quadrature. Allows on-the-fly or matrix-based algorithms.
Definition shtns.h:58
double sh11_st(shtns_cfg)
return the spherical harmonic representation of sin(theta)*cos(phi) (l=1,m=1)
Definition sht_init.c:85
shtns_norm
Different Spherical Harmonic normalizations. See also section Normalization for details.
Definition shtns.h:47
@ sht_fourpi
Geodesy and spectral analysis : 4.pi normalization.
Definition shtns.h:49
@ sht_orthonormal
orthonormalized spherical harmonics (default).
Definition shtns.h:48
@ sht_schmidt
Schmidt semi-normalized : 4.pi/(2l+1)
Definition shtns.h:50
double SH_to_spat_time(shtns_cfg shtns, cplx *Qlm, double *Vr)
same as SH_to_spat() but with time recording; returns time in seconds
Definition sht_com.c:32
const unsigned int nphi
number of spatial points in Phi direction (longitude)
Definition shtns.h:87
const double *const ct
cos(theta) array (size nlat)
Definition shtns.h:91
const unsigned short lmax
maximum degree (lmax) of spherical harmonics.
Definition shtns.h:82
const double *const st
sin(theta) array (size nlat)
Definition shtns.h:92
const unsigned short *const li
degree l for given mode index (size nlm) : li[lm]
Definition shtns.h:89
const unsigned short mmax
maximum order (mmax*mres) of spherical harmonics.
Definition shtns.h:83
const unsigned int nlm
total number of (l,m) spherical harmonics components.
Definition shtns.h:81
const unsigned int nlat_padded
number of spatial points in Theta direction, including padding.
Definition shtns.h:93
const unsigned int nlm_cplx
number of complex coefficients to represent a complex-valued spatial field.
Definition shtns.h:94
const unsigned short *const mi
order m for given mode index (size nlm) : mi[lm]
Definition shtns.h:90
const unsigned int nspat
number of real numbers that must be allocated in a spatial field.
Definition shtns.h:88
const unsigned short mres
the periodicity along the phi axis.
Definition shtns.h:84
const unsigned short nlat_2
half of spatial points in Theta direction (using (shtns.nlat+1)/2 allows odd shtns....
Definition shtns.h:85
const unsigned int nlat
number of spatial points in Theta direction (latitude) ...
Definition shtns.h:86