GW_models

GW_models.py is a Python routine that contains analytical and semi-analytical models of cosmological GW backgrounds.

Currently part of the cosmoGW code:

https://github.com/cosmoGW/cosmoGW/ https://github.com/cosmoGW/cosmoGW/blob/main/src/cosmoGW/GW_models.py

Note

For full documentation, visit Read the Docs.

To use it, first install cosmoGW:

pip install cosmoGW

Author

Dates

Contributors

  • Antonino Midiri, Simona Procacci, Madeline Salomé, Isak Stomberg

References

  • [RoperPol:2022iel]: A. Roper Pol, C. Caprini, A. Neronov, D. Semikoz, “The gravitational wave signal from primordial magnetic fields in the Pulsar Timing Array frequency band,” Phys. Rev. D 105, 123502 (2022), arXiv:2201.05630.

  • [RoperPol:2023bqa]: A. Roper Pol, A. Neronov, C. Caprini, T. Boyer, D. Semikoz, “LISA and γ-ray telescopes as multi-messenger probes of a first-order cosmological phase transition,arXiv:2307.10744 (2023).

  • [RoperPol:2023dzg]: A. Roper Pol, S. Procacci, C. Caprini, “Characterization of the gravitational wave spectrum from sound waves within the sound shell model,” Phys. Rev. D 109, 063531 (2024), arXiv:2308.12943.

  • [Hindmarsh:2019phv]: M. Hindmarsh, M. Hijazi, “Gravitational waves from first order cosmological phase transitions in the Sound Shell Model,” JCAP 12 (2019), 062, arXiv:1909.10040.

  • [Caprini:2024gyk]: A. Roper Pol, I. Stomberg, C. Caprini, R. Jinno, T. Konstandin, H. Rubira, “Gravitational waves from first-order phase transitions: from weak to strong,” JHEP 07 (2025), 217, arxiv:2409.03651.

  • [RoperPol:2025b]: A. Roper Pol, A. Midiri, M. Salomé, C. Caprini, “Modeling the gravitational wave spectrum from slowly decaying sources in the early Universe: constant-in-time and coherent-decay models,” in preparation

  • [RoperPol:2025a]: A. Roper Pol, S. Procacci, A. S. Midiri, C. Caprini, “Irrotational fluid perturbations from first-order phase transitions,” in preparation

Comments

RoperPol:2022iel/RoperPol:2023dzg and RoperPol:2025b/RoperPol:2025b consider spectral functions defined such that the average squared field corresponds to

\[ \begin{align}\begin{aligned}\langle v^2 \rangle \propto A k_\ast \int \zeta(K) dK, \quad {\rm \ in \ RoperPol:2022iel},\\\langle v^2 \rangle \propto A \int \zeta(K) d \ln K, \quad {\rm \ in \ RoperPol:2025b}.\end{aligned}\end{align} \]

The first convention can be chosen in the following functions if dlogK is set to False, while the second one is assumed when dlogK is True

cosmoGW.GW_models.Delta2_cit_aver(k, tini=1.0, tfin=10000.0, expansion=True)

Compute D^2(k, t) averaged over t0 for constant-in-time GW source.

Parameters

karray_like

Wave numbers.

tinifloat, optional

Initial time (default 1).

tfinfloat, optional

Final time.

expansionbool, optional

Include expansion of Universe (default is True).

Returns

D2ndarray

D^2(k, t) averaged over t0.

References

RoperPol:2022iel, RoperPol:2023dzg

cosmoGW.GW_models.Delta_cit(t, k, tini=1.0, tfin=10000.0, expansion=True)

Compute Delta(k, t) used in the analytical calculations of the GW spectrum when assuming a constant sourcing stress spectrum, i.e., Pi(k, t1, t2) = Pi(k)

Parameters

tarray_like

Times.

karray_like

Wave numbers.

tinifloat, optional

Initial time of sourcing (default 1).

tfinfloat, optional

Final time of sourcing (default 1e4).

expansionbool, optional

Include expansion of Universe (default is True).

Returns

Dndarray

Delta function values.

References

RoperPol:2022iel, RoperPol:2023dzg

cosmoGW.GW_models.EPi_correlators(k, a=5, b=0.6666666666666666, alp=2, tp='all', zeta=False, hel=False, norm=True, dlogk=True, model='dbpl', kk=None, EK_p=None)

Compute spectrum of projected or unprojected stresses from the two-point correlator of the source (Gaussian assumption).

Computes vortical, compressional, helical, and mixed components.

References

RoperPol:2025a, RoperPol:2022iel (eqs 11 and 20) for vortical fields, and RoperPol:2023dzg for compressional ones.

Parameters

karray_like

Wave numbers.

afloat

Low-k slope, \(k^a\) (default 5)

bfloat

High-k slope, \(k^{-b}\) (default 2/3).

alpfloat

Smoothness of transition, \(\alpha\) (default 2).

tpstr

Type of sourcing field (‘vort’, ‘comp’, ‘hel’ or ‘mix’ available)

zetabool

Integrate convolution over \(z \in (-1, 1)\).

helbool

Compute helical stresses.

normbool

Normalize spectrum to peak at kpeak with amplitude A.

dlogkbool

Use spectrum per unit log(k).

modelstr

Model for source spectrum (‘dbpl’ or ‘input’).

kkarray_like, optional

Wave numbers for input model.

EK_parray_like, optional

Spectrum for input model.

Returns

pindarray

Spectrum of anisotropic stresses.

cosmoGW.GW_models.K2int(dtfin, K0=1.0, dt0=11, b=0.0, expansion=False, beta=array([-20., -19.98666222, -19.97332444, ..., 19.97332444, 19.98666222, 20.], shape=(3000,)))

Compute integrated kinetic energy density squared for a power law,

\[K(\Delta t) = K_0 \left(\frac{\Delta t}{\Delta t_0}\right)^{-b},\]

where \(\Delta t\) and \(\Delta t_0\) represent time intervals, \(K_0\) is the amplitude at the end of the phase transition, and \(\Delta t_0 = 11\) is a numerical parameter of the fit.

Based on the results of Higgsless simulations of Caprini:2024gyk, see equation 2.27.

It determines the amplitude of GWs in the locally stationary UETC describing the decay of compressional sources, see equation 2.33,

\[K_{\rm int}^2 = \int K^2 (t) d t.\]

Parameters

dtfinfloat

Duration of sourcing (in units of \(1/\beta\) or \(1/H_\ast\) if expansion is False or True).

K0float, optional

Amplitude \(K_0\) at end of phase transition.

dt0float, optional

Numerical parameter \(\Delta t_0\) for fit.

bfloat, optional

Power law exponent.

expansionbool, optional

Consider expanding Universe.

betafloat, optional

Nucleation rate normalized to Hubble time, \(\beta/H_\ast\).

Returns

K2intfloat

Integrated squared kinetic energy density.

References

Caprini:2024gyk

cosmoGW.GW_models.OmGW_ssm_HH19(k, EK, Np=3000, Nk=1000, plot=False, cs2=0.3333333333333333)

Compute normalized GW spectrum \(\Omega(k)\) using Hindmarsh:2019phv sound-shell model under the delta assumption for the ‘stationary’ term (see appendix B of RoperPol:2023dzg for details).

The resulting GW spectrum is

\[\Omega_{\rm GW} (k) = \frac{3 \pi}{8 c_{\rm s}} \times \Gamma^2 \times (k/k_\ast)^2 \times (\Omega_\ast/{\cal A})^2 \times T_{\rm GW} \times \Omega (k).\]

where \(\Omega_\ast = \langle v^2 \rangle = v_{\rm rms}^2\) and \(\cal A = \int \zeta(K) d \ln k\) (using the normalization of RoperPol:2025a for \(\zeta\)).

Parameters

karray_like

Wave numbers.

EKarray_like

Kinetic spectrum.

Npint, optional

Number of p discretizations.

Nkint, optional

Number of k discretizations.

plotbool, optional

Plot interpolated spectrum.

cs2float, optional

Speed of sound squared.

Returns

kpndarray

Wave numbers.

Ommndarray

GW spectrum.

References

Hindmarsh:2019phv, RoperPol:2023dzg (appendix B, eq. B3)

cosmoGW.GW_models.TGW_func(s, Oms=0.1, lf=0.01, N=2, cs2=0.3333333333333333, expansion=True, tdecay='eddy', tp='magnetic')

Compute the logarithmic envelope of the GW template in the constant-in-time model for the unequal time correlator, \({\cal T}_{\rm GW}\).

It is obtained from integrating the Green’s function in the constant-in-time model, validated in RoperPol:2022iel and described for other sources in RoperPol:2025b

The function TGW_func determines two regimes, frequencies below and above an inverse duration,

\[f_{\rm br} = 1/\delta t_{\rm fin},\]

as used in RoperPol:2023bqa, EPTA:2023xxk, Caprini:2024hue. However, the original reference RoperPol:2022iel used

\[k_{\rm br} = f_{\rm br}/(2\pi) = 1/\delta t_{\rm fin},\]

such that \(\delta t_{\rm fin} = \delta t_{\rm fin}/(2\pi)\), and relates \(\delta t_{\rm fin}\) to the decay time (considered the eddy turnover time) as

\[\delta t_{\rm finm} = N \delta t_{\rm decay} = N/(v_A k_*) = N R_*/(2\pi v_A)\]

Hence, we will consider

\[f_{\rm br} = 1/\delta t_{\rm fin} = \frac{1}{2\pi \delta t_{\rm fin}} = \frac{v_{\rm A}}{N R_\ast} \delta t_{\rm fin}.\]

Main references are:

  • RoperPol:2022iel, equation 24

  • RoperPol:2023bqa, equation 15

  • EPTA:2023xxk, equation 21

  • Caprini:2024hue, equation 2.17

  • RoperPol:2025b

Parameters

sarray_like

Frequencies normalized by characteristic scale.

Omsfloat, optional

Source energy density.

lffloat, optional

Characteristic scale fraction.

Nint, optional

Source duration/eddy turnover ratio.

cs2float, optional

Speed of sound squared.

expansionbool, optional

Include expansion of Universe.

tdecaystr, optional

Decay time model (‘eddy’).

tpstr, optional

Source type (‘magnetic’, ‘kinetic’, ‘max’).

Returns

TGWndarray

Logarithmic function for spectral shape.

References

RoperPol:2022iel (eq. 24), RoperPol:2023bqa (eq. 15), Caprini:2024hue (eq. 2.17), EPTA:2023xxk (eq. 21).

cosmoGW.GW_models.compute_Delta_mn(t, k, p, ptilde, cs2=0.3333333333333333, m=1, n=1, tini=1.0, expansion=True)

Compute integrated Green’s functions and stationary UETC Delta_mn for the sound shell model.

Parameters

tfloat

Time.

kfloat

Wave number k.

pfloat

Wave number p.

ptildefloat

Second wave number \(\tilde{p} = |k - p|\).

cs2float, optional

Speed of sound squared (default 1/3).

m, nint, optional

Indices for Delta_mn.

tinifloat, optional

Initial time.

expansionbool, optional

Include expansion of Universe.

Returns

Delta_mnndarray

Integrated Green’s function.

References

RoperPol:2023dzg, eqs.56-59

cosmoGW.GW_models.compute_kin_spec_ssm(z, vws, fp, l=None, sp='sum', type_n='exp', cs2=0.3333333333333333, min_qbeta=-4, max_qbeta=5, Nqbeta=1000, min_TT=-1, max_TT=3, NTT=5000, corr=False, dens=True, normbeta=True)

Compute kinetic power spectral density for the sound-shell model.

Kinetic spectra computed for the sound-shell model from \(f' (z)\) and \(l(z)\) functions. \(f'\) and \(l\) functions need to be previously computed from the self-similar fluid perturbations induced by expanding bubbles using hydro_bubbles module.

Parameters

zarray_like

Values of z.

vwsarray_like

Wall velocities.

fparray_like

\(f'(z)\) from hydro_bubbles.

larray_like, optional

\(l(z)\) from hydro_bubbles (if lz is True)

spstr, optional

Type of function for kinetic spectrum.

type_nstr, optional

Nucleation history (‘exp’, ‘sim’).

cs2float, optional

Speed of sound squared (default 1/3).

min_qbeta, max_qbeta, Nqbetaint, optional

Wave number range and discretization.

min_TT, max_TT, NTTint, optional

Lifetime range and discretization.

corrbool, optional

Correct Rstar beta with max(vw, cs) (default False)

densbool, optional

Return power spectral density (True) or kinetic spectrum (False).

normbetabool, optional

Normalize k with beta (True) or Rstar (False).

Returns

qbetandarray

Wave number normalized.

Pvndarray

Power spectral density or kinetic spectrum if dens is True or False.

References

Equations (32)-(37) of RoperPol:2023dzg, RoperPol:2025a

cosmoGW.GW_models.effective_ET_correlator_stat(k, EK, tfin, Np=3000, Nk=1000, plot=False, expansion=True, kstar=1.0, extend=False, largek=3, smallk=-3, tini=1.0, cs2=0.3333333333333333, terms='all', inds_m=None, inds_n=None)

Compute normalized GW spectrum \(\zeta_{\rm GW}(k)\) from velocity field spectrum for compressional anisotropic stresses, assuming stationary UETC (e.g., sound waves under the sound-shell model).

Parameters

karray_like

Wave numbers.

EKarray_like

Kinetic spectrum.

tfinfloat

Final time.

Npint, optional

Number of p discretizations.

Nkint, optional

Number of k discretizations.

plotbool, optional

Plot interpolated spectrum.

expansionbool, optional

Include expansion of Universe.

kstarfloat, optional

Peak position of the kinetic spectrum.

extendbool, optional

Extend wave number array.

largek, smallkint, optional

Range for extended k (in log10).

tinifloat, optional

Initial time of GW production.

cs2float, optional

Speed of sound squared (default 1/3).

termsstr, optional

Terms to compute (‘all’).

inds_m, inds_nlist, optional

Indices for Delta_mn.

corr_Delta_0bool, optional

Correct Delta_0.

Returns

kpndarray

Wave numbers.

Ommndarray

Normalized GW spectrum, \(\zeta_{\rm GW}(k)\).

References

RoperPol:2023dzg, eq. 93