Tests of the code
Contents
Tests of the code¶
This notebook is designed to document some simple tests of the photon-ALP propagation code ALPro. Most of these tests can be run by running
python -m unittest alpro.test
from the command line.
[1]:
%matplotlib inline
import alpro
import matplotlib.pyplot as plt
alpro.util.set_default_plot_params()
1. Single Domain Test¶
First, let’s compare an idealised pure polarization state solution to the analytic solution given by
The model here is a single domain of width \(10~{\rm kpc}\), with uniform field \(B=10 \mu{\rm G}\) oriented along the \(y\)-axis. The polarization state is \((0,1,0)\) and we use energies from \(1-10~{\rm keV}\).
This test also checks for agreement within a relative tolerance of \(10^{-6}\) between the theoretical and numerical calculations.
[2]:
test = alpro.test.RunTest()
test.test_analytic(subplot=111)
2. Discretisation Test¶
In our second test, we repeat the above test, but now compare a single domain to a discretised uniform field. Specifically the result from 1 uniform cell of size \(L\) to \(10\) uniform cells of size \(L/10\). This should give an identical result. The parameters and procedure are identical to our first test.
[3]:
test.test_discretise(subplot=111)
3. Libanov field model v Marsh¶
This tests a uniform field model from Libanov & Troitsky (2021), which is originally described by Gourgouliatos et al. (2010), against M. C. David Marsh’s code. This test uses a large scale uniform field and energies in the GeV regime. The field components are given by
where \(\alpha\) solves a transcendental equation and is approximately given by \(\alpha= 5.76\). The function \(f(r)\) is given by
The form of the field is plotted below, before we plot the ALP result. Note that this is now the survival probability on a linear axis. We find cosmetically perfect agreement between our results and Marsh. the Libanov results are smoothed with the Fermi response which is presumably the reason for the difference, but the overall form is similar.
[4]:
test.test_marsh(subplot=111)
4. Massive Fourier Formalism¶
[5]:
test.test_fourier_massive(subplot=111)
/Users/matthews/Library/Python/3.7/lib/python/site-packages/alpro/test.py:153: RuntimeWarning: invalid value encountered in greater
select = (P1 > 1e-7)
6. Domain Field Test v Analytic¶
This tests a cell-based domain model against an analytic solution computed by Pierluca Carenza.
[7]:
import numpy as np
def setup_carenza_model():
s = alpro.Survival("custom")
s.init_model()
r, f = np.genfromtxt("../data/Bfield_Carenza.dat", unpack=True)
s.set_params(g=1e-12 * 1e-9, mass=1e-11)
s.domain.deltaL = r[1:] - r[:-1]
s.domain.r = r[:-1]
s.domain.rcen = 0.5 * (r[1:] + r[:-1])
s.domain.ne = np.zeros_like(s.domain.r)
s.domain.Bx = f[:-1] * 1e-6
s.domain.By = np.zeros_like (s.domain.Bx)
s.domain.B = np.sqrt(s.domain.Bx**2 + s.domain.By **2)
s.domain.phi = np.arctan2(s.domain.Bx,s.domain.By)
return (s)
energies,P = np.genfromtxt("../data/Prob_Carenza.dat", unpack=True)
s = setup_carenza_model()
Pcode, _ = s.propagate(s.domain, energies, pol="x")
# make the default plot and overplot Pierluca's solution
s.default_plot()
plt.plot(energies, P, c="C1", ls="--", label="Carenza analytic")
Warning: Custom model specified - make sure get_B & density methods are populated or domain set manually!
[7]:
[<matplotlib.lines.Line2D at 0x13763a890>]