1+ import logging
2+
13import numpy as np
24from scipy .special import erf , erfc
35
46from pttools .ssmtools .low_k import integration , intersection
57
8+ logger = logging .getLogger (__name__ )
9+
610
711def pow_gw_junction (
812 z : np .ndarray [tuple [int ], np .float64 ],
@@ -12,7 +16,8 @@ def pow_gw_junction(
1216 cs : float ,
1317 nu : float ,
1418 tau_star : float ,
15- tau_end : float ):
19+ tau_end : float ,
20+ HLf : float ):
1621 r"""
1722 Create the junction of the gravitational wave power spectrum between different regimes
1823 starting from the profiles in each regime.
@@ -22,19 +27,30 @@ def pow_gw_junction(
2227 :param Pgw_int: array of gravitational wave power spectrum values in the intermediate-frequency regime
2328 :param Pgw_high: array of gravitational wave power spectrum values in the high-frequency regime
2429 :param cs: sound speed, $0 < c_s < \frac{1}{\sqrt{3}}$
30+ :param nu: $\nu_\text{gdh2024}$
2531 :param tau_star: $\tau_* = \frac{\eta_*}{L_f}$
2632 :param tau_end: $\tau_{end} = \frac{\eta_{end}}{L_f}$
33+ :param HLf: $H L_f = r_*$
2734 :return: gravitational wave power spectrum values at the given momentum
2835 """
29- # z_star = 4*cs*np.pi * (1+nu) / HLf
36+ # if not (z.size and Pgw_low.size and Pgw_int.size and Pgw_high.size):
37+ # raise ValueError(
38+ # "Input arrays must not be empty. Got sizes: "
39+ # f"z={z.size}, Pgw_low={Pgw_low.size}, Pgw_int={Pgw_int.size}, Pgw_high={Pgw_high.size}"
40+ # )
41+
3042 difference = Pgw_high - Pgw_int
3143 index = np .where (difference > 0 )[0 ]
32- z_star = z [index [0 ]] # if len(index) > 0 else z_star
44+ if index .size :
45+ z_star = z [index [0 ]]
46+ else :
47+ z_star = 4 * cs * np .pi * (1 + nu ) / HLf
48+ logger .warning ("Using fallback z_star=%s for low-k junction." , z_star )
3349 z_cross = intersection .cross_z_junction (cs = cs , nu = nu , tau_star = tau_star , tau_end = tau_end )
3450
3551 term_low = 0.5 * erfc (2 * np .pi * tau_star * (z - z_cross )) * Pgw_low
36- term_int = 0.5 * (1 + erf (2 * np .pi * tau_star * (z - z_cross ))) * Pgw_int * 0.5 * erfc (
37- 2 * np .pi * tau_star * (z - z_star ))
52+ term_int = 0.5 * (1 + erf (2 * np .pi * tau_star * (z - z_cross ))) * Pgw_int * \
53+ 0.5 * erfc ( 2 * np .pi * tau_star * (z - z_star ))
3854 term_high = 0.5 * (1 + erf (2 * np .pi * tau_star * (z - z_star ))) * Pgw_high
3955
4056 return term_low + term_int + term_high
0 commit comments