27#include <gsl/gsl_sf_legendre.h>
30static double sph_cnsts[16] = {
32 0.28209479177387814347403972578,
34 0.48860251190291992158638462283, 0.48860251190291992158638462283,
35 0.48860251190291992158638462283,
37 1.09254843059207907054338570580, 1.09254843059207907054338570580,
38 0.31539156525252000603089369029, 1.09254843059207907054338570580,
39 0.54627421529603953527169285290,
41 0.59004358992664351034561027754, 2.89061144264055405538938015439,
42 0.45704579946446573615802069691, 0.37317633259011539141439591319,
43 0.45704579946446573615802069691, 1.44530572132027702769469007719,
44 0.59004358992664351034561027754};
46void oct_ylm_base(
const double *r,
const double *x,
const double *y,
47 const double *z,
const fint *
l,
const fint *m,
double *ylm);
55void FC_FUNC_(oct_ylm, OCT_YLM)(
const fint *np,
const double *x,
56 const double *y,
const double *z,
const fint *
l,
57 const fint *m,
double *restrict ylm) {
59 for (
int ip = 0; ip < np[0]; ip++)
60 ylm[ip] = sph_cnsts[0];
64 for (
int ip = 0; ip < np[0]; ip++) {
66 double rr =
sqrt(x[ip] * x[ip] + y[ip] * y[ip] + z[ip] * z[ip]);
68 oct_ylm_base(&rr, &x[ip], &y[ip], &z[ip],
l, m, &ylm[ip]);
72void FC_FUNC_(oct_ylm_vector, OCT_YLM_VECTOR)(
const fint *np,
const double *xx,
73 const double *rr,
const fint *
l,
75 double *restrict ylm) {
77 for (
int ip = 0; ip < np[0]; ip++)
78 ylm[ip] = sph_cnsts[0];
82 for (
int ip = 0; ip < np[0]; ip++) {
84 oct_ylm_base(&rr[ip], &xx[ip * 3], &xx[ip * 3 + 1], &xx[ip * 3 + 2],
l, m,
89void oct_ylm_base(
const double *r,
const double *x,
const double *y,
90 const double *z,
const fint *
l,
const fint *m,
double *ylm) {
92 double r2, r3, rr, rx, ry, rz, cosphi, sinphi, cosm, sinm, phase;
108 ylm[0] = -sph_cnsts[1] * rr * y[0];
111 ylm[0] = sph_cnsts[2] * rr * z[0];
114 ylm[0] = -sph_cnsts[3] * rr * x[0];
120 ylm[0] = sph_cnsts[4] * x[0] * y[0] / r2;
123 ylm[0] = -sph_cnsts[5] * y[0] * z[0] / r2;
126 ylm[0] = sph_cnsts[6] * (3.0 * z[0] * z[0] / r2 - 1.0);
129 ylm[0] = -sph_cnsts[7] * x[0] * z[0] / r2;
132 ylm[0] = sph_cnsts[8] * (x[0] * x[0] - y[0] * y[0]) / r2;
139 ylm[0] = sph_cnsts[9] * ((3.0 * x[0] * x[0] - y[0] * y[0]) * y[0]) / r3;
142 ylm[0] = sph_cnsts[10] * (x[0] * y[0] * z[0]) / r3;
145 ylm[0] = sph_cnsts[11] * (y[0] * (5.0 * z[0] * z[0] - r2)) / r3;
148 ylm[0] = sph_cnsts[12] * (z[0] * (5.0 * z[0] * z[0] - 3.0 * r2)) / r3;
151 ylm[0] = sph_cnsts[13] * (x[0] * (5.0 * z[0] * z[0] - r2)) / r3;
154 ylm[0] = sph_cnsts[14] * ((x[0] * x[0] - y[0] * y[0]) * z[0]) / r3;
157 ylm[0] = sph_cnsts[15] * ((x[0] * x[0] - 3.0 * y[0] * y[0]) * x[0]) / r3;
181 for (
i = 0;
i < abs(m[0]);
i++) {
182 double a = cosm, b = sinm;
183 cosm = a * cosphi - b * sinphi;
184 sinm = a * sinphi + b * cosphi;
186 phase = m[0] < 0 ? sinm : cosm;
187 phase = m[0] == 0 ? phase :
sqrt(2.0) * phase;
190 rz = rz < DBL_MIN ? DBL_MIN : rz;
192 rr = gsl_sf_legendre_sphPlm(
l[0], abs(m[0]), rz);
double hypot(double __x, double __y) __attribute__((__nothrow__
double sqrt(double __x) __attribute__((__nothrow__