Move MIN,MAX,SQ macros to a common header
[qpms.git] / qpms / qpms_specfunc.h
blob3c07a91d9a7ed2330d42d935c5ba44778685d55e
1 /*! \file qpms_specfunc.h
2 * \brief Various special and auxillary functions.
3 */
4 #ifndef QPMS_SPECFUNC_H
5 #define QPMS_SPECFUNC_H
6 #include "qpms_types.h"
7 #include <gsl/gsl_sf_legendre.h>
9 /******************************************************************************
10 * Spherical Bessel functions *
11 ******************************************************************************/
13 // TODO unify types
14 qpms_errno_t qpms_sph_bessel_fill(qpms_bessel_t typ, qpms_l_t lmax, complex double x, complex double *result_array);
18 typedef struct {
19 qpms_l_t lMax;
20 double *akn; // coefficients as in DLMF 10.49.1
21 //complex double *bkn; // coefficients of the derivatives
22 } qpms_sbessel_calculator_t;
24 qpms_sbessel_calculator_t *qpms_sbessel_calculator_init(void);
25 void qpms_sbessel_calculator_pfree(qpms_sbessel_calculator_t *c);
27 qpms_errno_t qpms_sbessel_calc_fill(qpms_sbessel_calculator_t *c, qpms_bessel_t typ, qpms_l_t lmax,
28 double x, complex double *result_array);
30 complex double qpms_sbessel_calc_h1(qpms_sbessel_calculator_t *c, qpms_l_t n, complex double x);
31 qpms_errno_t qpms_sbessel_calc_h1_fill(qpms_sbessel_calculator_t *c, qpms_l_t lmax,
32 complex double x, complex double *result_array);
35 /******************************************************************************
36 * Legendre functions and their "angular derivatives" *
37 ******************************************************************************/
40 * N.B. for the norm definitions, see
41 * https://www.gnu.org/software/gsl/manual/html_node/Associated-Legendre-Polynomials-and-Spherical-Harmonics.html
42 * ( gsl/specfunc/legendre_source.c and 7.24.2 of gsl docs
45 qpms_errno_t qpms_legendre_deriv_y_get(double **result, double **result_deriv, double x, qpms_l_t lMax,
46 gsl_sf_legendre_t lnorm, double csphase); // free() result and result_deriv yourself!
47 qpms_errno_t qpms_legendre_deriv_y_fill(double *where, double *where_deriv, double x,
48 qpms_l_t lMax, gsl_sf_legendre_t lnorm, double csphase);
51 double *qpms_legendre_y_get(double x, qpms_l_t lMax, qpms_normalisation_t norm);//NI
52 double *qpms_legendre0d_y_get(qpms_l_t lMax, qpms_normalisation_t norm); //NI
53 double *qpms_legendre_plus1d_y_get(qpms_l_t lMax, qpms_normalisation_t norm); //NI
54 double *qpms_legendre_minus1d_y_get(qpms_l_t lMax, qpms_normalisation_t norm); //NI
58 /// Array of Legendre and and auxillary \f$\pi_{lm}, \tau_{lm} \f$ functions.
59 /**
60 * See qpms_pitau_get() for definitions.
62 * The leg, pi, tau arrays are indexed using the standard qpms_mn2y() VSWF indexing.
64 typedef struct {
65 //qpms_normalisation_t norm;
66 qpms_l_t lMax;
67 //qpms_y_t nelem;
68 double *leg, *pi, *tau;
69 } qpms_pitau_t;
71 /// Returns an array of normalised Legendre and auxillary \f$\pi_{lm}, \tau_{lm} \f$ functions.
72 /**
73 * The normalised Legendre function here is defined as
74 * \f[
75 * \Fer[norm.]{l}{m} = \csphase^{-1}
76 * \sqrt{\frac{1}{l(l+1)}\frac{(l-m)!(2l+1)}{4\pi(l+m)!}},
77 * \f] i.e. obtained using `gsl_sf_legendre_array_e()` with
78 * `norm = GSL_SF_LEGENDRE_SPHARM` and divided by \f$ \sqrt{l(l+1)} \f$.
80 * The auxillary functions are defined as
81 * \f[
82 * \pi_{lm}(\cos \theta) = \frac{m}{\sin \theta} \Fer[norm.]{l}{m}(\cos\theta),\\
83 * \tau_{lm}(\cos \theta) = \frac{\ud}{\ud \theta} \Fer[norm.]{l}{m}(\cos\theta)
84 * \f]
85 * with appropriate limit expression used if \f$ \abs{\cos\theta} = 1 \f$.
87 * When done, don't forget to deallocate the memory using qpms_pitau_free().
90 qpms_pitau_t qpms_pitau_get(double theta, qpms_l_t lMax, double csphase);
92 /// Directly fills (pre-allocated) arrays of normalised Legendre and auxillary \f$\pi_{lm}, \tau_{lm} \f$ functions.
93 /**
94 * Arrays must be preallocated for `lMax * (lMax + 2)` elements. `NULL` targets are skipped.
95 * For details, see qpms_pitau_get().
97 qpms_errno_t qpms_pitau_fill(double *target_leg, double *target_pi, double *target_tau,
98 double theta, qpms_l_t lMax, double csphase);
100 /// Frees the dynamically allocated arrays from qpms_pitau_t.
101 void qpms_pitau_free(qpms_pitau_t);
103 //void qpms_pitau_pfree(qpms_pitau_t*);//NI
105 // Associated Legendre polynomial at zero argument (DLMF 14.5.1) DEPRECATED?
106 double qpms_legendre0(int m, int n);
107 // Associated Legendre polynomial derivative at zero argument (DLMF 14.5.2)
108 double qpms_legendred0(int m, int n);
110 #endif // QPMS_SPECFUNC_H