Skip to content

Commit 93e2961

Browse files
author
NGC
authored
Merge pull request #29 from hfoote/indexing
added nlm indexer
2 parents 01602fc + e71f8ef commit 93e2961

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

EXPtools/utils/indexing.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,37 @@ def I(l, m):
3232
assert abs(m) <= l, "m must be less than or equal to l"
3333
return int(l * (l + 1) / 2) + abs(m)
3434

35+
def I_nlm(n, l, m, lmax):
36+
"""
37+
Calculate the index of a spherical harmonic element given the angular numbers n, l, and m .
38+
39+
Parameters
40+
----------
41+
n : int
42+
The radial number
43+
l : int
44+
The angular number
45+
m : int
46+
The magnetic quantum number, ranging from 0 to l.
47+
lmax : int
48+
The maximum value of l in the basis
49+
50+
Returns:
51+
--------
52+
idx : int
53+
The index corresponding to the specified angular numbers.
54+
"""
55+
assert isinstance(n, int) and isinstance(l, int) and isinstance(m, int), "all args must be integers"
56+
assert n >= 0, "n must be greater than 0"
57+
assert l >= 0, "l must be greater than 0"
58+
assert abs(m) <= l, "m must be less than or equal to l"
59+
60+
# determine the index of the n=n, l=0, m=0 term
61+
n_idx = int(total_terms(lmax)*n)
62+
63+
# add the number of indices to reach the desired l,m
64+
return I(l, m) + n_idx
65+
3566
def inverse_I(I):
3667
"""
3768
Calculate the angular numbers l and m given the index of a spherical harmonic element.

0 commit comments

Comments
 (0)