d-SEAMS
Install
Output
Methods
Docs
Engine & CLI
Python
Rust
Julia
R
Lua / Fennel
Fortran
PLUMED
linkcell
Wiki
Cite
GitHub
seams-core
v2.14.0
libyodaLib, the C++ engine of d-SEAMS
Toggle main menu visibility
Loading...
Searching...
No Matches
ylm_cartesian.hpp
Go to the documentation of this file.
1
#ifndef SEAMS_YLM_CARTESIAN_H_
2
#define SEAMS_YLM_CARTESIAN_H_
3
4
// Closed-form complex Y_lm for l = 3 and l = 6 as real polynomials in the
5
// unit-vector components. The phase convention matches harmonicPair and
6
// ylmAllTrig: phi = atan2(dx, dy), so e^{i phi} = (y + i x) / rho and
7
// sin(theta)^|m| e^{i m phi} = (y + i x)^|m| with no inverse sine or
8
// cosine. Norms are the Condon-Shortley constants used by normQ3/normQ6.
9
10
#include <
solid_ylm.hpp
>
11
12
#include <cmath>
13
14
namespace
seams
{
15
namespace
ylm
{
16
17
inline
constexpr
double
N3
[4] = {
18
0x1.7e21efc0768b0p-2,
// 0.25 * sqrt(7/pi)
19
0x1.4aefbf05f1305p-2,
// 0.125 * sqrt(21/pi)
20
0x1.05a0d7164496dp+0,
// 0.25 * sqrt(105/(2 pi))
21
0x1.ab3cb8d675a30p-2
// 0.125 * sqrt(35/pi)
22
};
23
24
inline
constexpr
double
N4
[5] = {
25
0x1.b14c2f863e924p-4,
// 0.1875 * sqrt(1/pi)
26
0x1.e471027d29b68p-2,
// 0.375 * sqrt(5/pi)
27
0x1.568d44c02929cp-2,
// 0.375 * sqrt(5/(2 pi))
28
0x1.406d8aa0d83a4p+0,
// 0.375 * sqrt(35/pi)
29
0x1.c5274a45d91d8p-2
// 0.1875 * sqrt(35/(2 pi))
30
};
31
32
inline
constexpr
double
N6
[7] = {
33
0x1.046123cc5b3b1p-4,
// 0.03125 * sqrt(13/pi)
34
0x1.a5dce8e510806p-2,
// 0.0625 * sqrt(273/(2 pi))
35
0x1.4d830dc3746c6p-2,
// 0.015625 * sqrt(1365/pi)
36
0x1.4d830dc3746c6p-1,
// 0.03125 * sqrt(1365/pi)
37
0x1.6d58113f224e2p-2,
// 0.09375 * sqrt(91/(2 pi))
38
0x1.ac67615af3632p+0,
// 0.09375 * sqrt(1001/pi)
39
0x1.eead9a142c943p-2
// 0.015625 * sqrt(3003/pi)
40
};
41
42
// Associated-Legendre amplitude without the azimuthal factor, in the
43
// hard-coded table convention (the sin^|m| factor is carried by w^m).
44
template
<
class
T>
45
inline
T
legendrePoly
(
int
orderL,
int
absM,
const
T *zpow) {
46
if
(orderL == 3) {
47
switch
(absM) {
48
case
0:
49
return
T(5) * zpow[3] - T(3) * zpow[1];
50
case
1:
51
return
T(5) * zpow[2] - T(1);
52
case
2:
53
return
zpow[1];
54
default
:
55
return
T(1);
56
}
57
}
58
switch
(absM) {
59
case
0:
60
return
T(231) * zpow[6] - T(315) * zpow[4] + T(105) * zpow[2] - T(5);
61
case
1:
62
return
T(33) * zpow[5] - T(30) * zpow[3] + T(5) * zpow[1];
63
case
2:
64
return
T(33) * zpow[4] - T(18) * zpow[2] + T(1);
65
case
3:
66
return
T(11) * zpow[3] - T(3) * zpow[1];
67
case
4:
68
return
T(11) * zpow[2] - T(1);
69
case
5:
70
return
zpow[1];
71
default
:
72
return
T(1);
73
}
74
}
75
76
// x, y, z are components of a unit vector. re/im hold 2*l+1 values,
77
// m = -l .. +l. l is 3 or 6.
78
template
<
class
T>
79
inline
void
evalUnit
(
int
orderL, T x, T y, T z, T *re, T *im) {
80
T wre[7];
81
T wim[7];
82
T zpow[7];
83
wre[0] = T(1);
84
wim[0] = T(0);
85
zpow[0] = T(1);
86
for
(
int
m = 1; m <= orderL; ++m) {
87
const
T prevRe = wre[m - 1];
88
const
T prevIm = wim[m - 1];
89
wre[m] = prevRe * y - prevIm * x;
90
wim[m] = prevRe * x + prevIm * y;
91
zpow[m] = zpow[m - 1] * z;
92
}
93
const
double
*norm = (orderL == 3) ?
N3
:
N6
;
94
for
(
int
m = 0; m <= orderL; ++m) {
95
const
T amp = T(norm[m]) *
legendrePoly
(orderL, m, zpow);
96
const
int
ineg = orderL - m;
97
const
int
ipos = orderL + m;
98
re[ineg] = amp * wre[m];
99
im[ineg] = -amp * wim[m];
100
const
T signedAmp = (m & 1) ? -amp : amp;
101
re[ipos] = signedAmp * wre[m];
102
im[ipos] = signedAmp * wim[m];
103
}
104
}
105
106
// Displacement, not necessarily a unit vector. A zero vector writes
107
// zeros and returns false so the caller can drop the bond.
108
inline
bool
ylmReal
(
int
orderL,
double
dx,
double
dy,
double
dz,
double
*re,
109
double
*im) {
110
const
int
nComp = 2 * orderL + 1;
111
const
double
r2 = dx * dx + dy * dy + dz * dz;
112
if
(!(r2 > 0.0) || (orderL != 3 && orderL != 4 && orderL != 6)) {
113
for
(
int
m = 0; m < nComp; ++m) {
114
re[m] = 0.0;
115
im[m] = 0.0;
116
}
117
return
false
;
118
}
119
// Even l: r^l is a power of r2. l = 3 keeps one square root.
120
double
inv;
121
if
(orderL == 6) {
122
const
double
r4 = r2 * r2;
123
inv = 1.0 / (r4 * r2);
124
}
else
if
(orderL == 4) {
125
inv = 1.0 / (r2 * r2);
126
}
else
{
127
inv = 1.0 / (r2 * std::sqrt(r2));
128
}
129
const
double
*norm = (orderL == 3) ?
N3
: (orderL == 4) ?
N4
:
N6
;
130
solid::eval
(orderL, dx, dy, dz, r2, inv, norm, re, im);
131
return
true
;
132
}
133
134
}
// namespace ylm
135
}
// namespace seams
136
137
#endif
seams::solid::eval
void eval(int orderL, T x, T y, T z, T r2, T inv, const double *norm, T *re, T *im)
Definition
solid_ylm.hpp:20
seams::ylm
Definition
ylm_batch.hpp:7
seams::ylm::legendrePoly
T legendrePoly(int orderL, int absM, const T *zpow)
Definition
ylm_cartesian.hpp:45
seams::ylm::N3
constexpr double N3[4]
Definition
ylm_cartesian.hpp:17
seams::ylm::N6
constexpr double N6[7]
Definition
ylm_cartesian.hpp:32
seams::ylm::ylmReal
bool ylmReal(int orderL, double dx, double dy, double dz, double *re, double *im)
Definition
ylm_cartesian.hpp:108
seams::ylm::N4
constexpr double N4[5]
Definition
ylm_cartesian.hpp:24
seams::ylm::evalUnit
void evalUnit(int orderL, T x, T y, T z, T *re, T *im)
Definition
ylm_cartesian.hpp:79
seams
Definition
cpu_features.hpp:30
solid_ylm.hpp
src
include
internal
ylm_cartesian.hpp