QPMS
Electromagnetic multiple scattering library and toolkit.
indexing.h
Go to the documentation of this file.
1 
4 #ifndef QPMS_INDEXING_H
5 #define QPMS_INDEXING_H
6 
7 #include "qpms_types.h"
8 #include <math.h>
9 #include "optim.h"
10 
11 
12 
13 static inline qpms_y_t qpms_mn2y(qpms_m_t m, qpms_l_t n) {
14  return n * (n + 1) + m - 1;
15 }
16 
17 static inline qpms_lm_t qpms_y2n(qpms_y_t y) {
18  //return (sqrt(5+y)-2)/2; // the cast will truncate the fractional part, which is what we want
19  return sqrt(y+1);
20 }
21 
22 static inline qpms_m_t qpms_yn2m(qpms_y_t y, qpms_l_t n) {
23  return y-qpms_mn2y(0,n);
24 }
25 
26 static inline void qpms_y2mn_p(qpms_y_t y, qpms_m_t *m, qpms_l_t *n){
27  *m=qpms_yn2m(y,*n=qpms_y2n(y));
28 }
29 
30 static inline qpms_y_t qpms_lMax2nelem(qpms_l_t lmax){
31  return lmax * ((qpms_y_t)lmax + 2);
32 }
33 
34 // Scalar versions: they have a place for the 0, 0 term in the beginning
35 
36 static inline qpms_y_t qpms_mn2y_sc(qpms_m_t m, qpms_l_t n) {
37  return n * (n + 1) + m;
38 }
39 
40 static inline qpms_lm_t qpms_y2n_sc(qpms_y_t y) {
41  //return (sqrt(5+y)-2)/2; // the cast will truncate the fractional part, which is what we want
42  return sqrt(y);
43 }
44 
45 static inline qpms_m_t qpms_yn2m_sc(qpms_y_t y, qpms_l_t n) {
46  return y-qpms_mn2y_sc(0,n);
47 }
48 
49 static inline void qpms_y2mn_sc_p(qpms_y_t y, qpms_m_t *m, qpms_l_t *n){
50  *m=qpms_yn2m_sc(y,*n=qpms_y2n_sc(y));
51 }
52 
53 static inline qpms_y_t qpms_lMax2nelem_sc(qpms_l_t lmax){
54  return lmax * ((qpms_y_t)lmax + 2) + 1;
55 }
56 
57 // TODO maybe enable crashing / validity control by macro definitions...
58 
62  return t + 4 * qpms_mn2y_sc(m, n);
63 }
64 
66 static const qpms_uvswfi_t QPMS_UI_L00 = 0;
67 
69 
71  qpms_vswf_type_t *t, qpms_m_t *m, qpms_l_t *n) {
72  *t = u & 3;
73  qpms_y_sc_t y_sc = u / 4;
74  qpms_y2mn_sc_p(y_sc, m, n);
75  // Test validity
76  if (QPMS_UNLIKELY(*t == 3)) return QPMS_ERROR; // VSWF type code invalid, TODO WARN
77  if (QPMS_UNLIKELY(*t && !y_sc)) return QPMS_ERROR; // l == 0 for transversal wave, TODO WARN
78  return QPMS_SUCCESS;
79 }
80 
82 
84  qpms_vswf_type_t *t, qpms_y_t *y) {
85  *t = u & 3;
86  *y = u / 4 - 1;
87  if (QPMS_UNLIKELY(*t == 0 || *t == 3)) return QPMS_ERROR;
88  if (QPMS_UNLIKELY(*y < 0)) return QPMS_ERROR;
89  return QPMS_SUCCESS;
90 }
91 
93 
97  qpms_vswf_type_t *t, qpms_y_t *y) {
98  *t = u & 3;
99  *y = u / 4 - 1;
100  if (QPMS_UNLIKELY(*t == 3)) return QPMS_ERROR;
101  if (QPMS_UNLIKELY(*y < 0)) return QPMS_ERROR;
102  return QPMS_SUCCESS;
103 }
104 
108  qpms_uvswfi2tmn(u, &t,&m,&n);
109  return m;
110 }
111 
112 
113 #endif //QPMS_INDEXING_H
static qpms_errno_t qpms_uvswfi2ty(qpms_uvswfi_t u, qpms_vswf_type_t *t, qpms_y_t *y)
Conversion from universal VSWF index u to type and the traditional layout index (l > 0).
Definition: indexing.h:83
static qpms_errno_t qpms_uvswfi2tmn(qpms_uvswfi_t u, qpms_vswf_type_t *t, qpms_m_t *m, qpms_l_t *n)
Conversion from universal VSWF index u to type, order and degree.
Definition: indexing.h:70
static qpms_errno_t qpms_uvswfi2ty_l(qpms_uvswfi_t u, qpms_vswf_type_t *t, qpms_y_t *y)
Conversion from universal VSWF index u to type and the traditional (vector) layout index.
Definition: indexing.h:96
static const qpms_uvswfi_t QPMS_UI_L00
Constant denoting the l=0, m=0 longitudinal spherical vector wave.
Definition: indexing.h:66
static qpms_m_t qpms_uvswfi2m(qpms_uvswfi_t u)
Extract degree m from an universal VSWF index u.
Definition: indexing.h:106
static qpms_uvswfi_t qpms_tmn2uvswfi(qpms_vswf_type_t t, qpms_m_t m, qpms_l_t n)
Conversion from VSWF type, order and degree to universal index.
Definition: indexing.h:60
Macros for compiler optimisation.
Common qpms types.
size_t qpms_y_t
Type for the (l, m) multiindex of transversal (M or N -type) VSWFs.
Definition: qpms_types.h:44
int qpms_l_t
Type for spherical harmonic degree l.
Definition: qpms_types.h:27
qpms_vswf_type_t
Codes of the VSWF types (electric/N, magnetic/M, longitudinal/L).
Definition: qpms_types.h:62
unsigned long long qpms_uvswfi_t
Exhaustive index type for VSWF basis functions.
Definition: qpms_types.h:81
size_t qpms_y_sc_t
Type for the (l, m) multiindex of spherical harmonics, including (0, 0).
Definition: qpms_types.h:59
qpms_errno_t
Error codes / return values for certain numerical functions.
Definition: qpms_types.h:85
@ QPMS_ERROR
Unspecified error.
Definition: qpms_types.h:87
@ QPMS_SUCCESS
Success.
Definition: qpms_types.h:86
qpms_lm_t qpms_m_t
Type for spherical harmonic order m.
Definition: qpms_types.h:31