Coverage for yasfpy/functions/t_entry.py: 83%
29 statements
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-15 20:36 +0100
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-15 20:36 +0100
1import sys, os
3sys.path.append(os.getcwd())
4import yasfpy.log as log
6from scipy.special import spherical_jn, spherical_yn
9def t_entry(tau, l, k_medium, k_sphere, radius, field_type="scattered"):
10 """
11 Computes an entry in the T Matrix for a given l, k, and tau
13 **Note**: scipy.special has also derivative function. Why is it not the same?
14 Example:
15 Now: djx = x * spherical_jn(l-1, x) - l * jx
16 Possible: djx = spherical_jn(l, x, derivative=True)
17 """
18 m = k_sphere / k_medium
19 x = k_medium * radius
20 mx = k_sphere * radius
22 jx = spherical_jn(l, x)
23 jmx = spherical_jn(l, mx)
24 hx = spherical_jn(l, x) + 1j * spherical_yn(l, x)
26 djx = x * spherical_jn(l - 1, x) - l * jx
27 djmx = mx * spherical_jn(l - 1, mx) - l * jmx
28 dhx = x * (spherical_jn(l - 1, x) + 1j * spherical_yn(l - 1, x)) - l * hx
30 if (field_type, tau) == ("scattered", 1):
31 return -(jmx * djx - jx * djmx) / (jmx * dhx - hx * djmx) # -b
32 elif (field_type, tau) == ("scattered", 2):
33 return -(m**2 * jmx * djx - jx * djmx) / (
34 m**2 * jmx * dhx - hx * djmx
35 ) # -a
36 elif (field_type, tau) == ("internal", 1):
37 return (jx * dhx - hx * djx) / (jmx * dhx - hx * djmx) # c
38 elif (field_type, tau) == ("internal", 2):
39 return (m * jx * dhx - m * hx * djx) / (m**2 * jmx * dhx - hx * djmx) # d
40 elif (field_type, tau) == ("ratio", 1):
41 return (jx * dhx - hx * djx) / -(jmx * djx - jx * djmx) # c / -b
42 elif (field_type, tau) == ("ratio", 2):
43 return (m * jx * dhx - m * hx * djx) / -(
44 m**2 * jmx * djx - jx * djmx
45 ) # d / -a
46 else:
47 logger = log.scattering_logger("t_entry")
48 logger.warning("Not a valid field type provided. Returning None!")
49 return None