diff --git a/tests/test_attenuation_functions.py b/tests/test_attenuation_functions.py new file mode 100644 index 0000000..ad9d5e4 --- /dev/null +++ b/tests/test_attenuation_functions.py @@ -0,0 +1,30 @@ +import pytest + +from pg_rad.physics import get_mass_attenuation_coeff + + +@pytest.mark.parametrize("energy,mu", [ + (1.00000E-03, 3.606E+03), + (1.00000E-02, 5.120E+00), + (1.00000E-01, 1.541E-01), + (1.00000E+00, 6.358E-02), + (1.00000E+01, 2.045E-02) +]) +def test_exact_attenuation_retrieval(energy, mu): + """ + Test if retrieval of values that are exactly in the table is correct. + """ + func_mu = get_mass_attenuation_coeff(energy) + assert pytest.approx(func_mu, rel=1E-6) == mu + + +@pytest.mark.parametrize("energy,mu", [ + (0.662, 0.0778), + (1.25, 0.06) +]) +def test_attenuation_interpolation(energy, mu): + """ + Test Cs-137 and Co-60 mass attenuation coefficients. + """ + interp_mu = get_mass_attenuation_coeff(energy) + assert pytest.approx(interp_mu, rel=1E-2) == mu diff --git a/tests/test_fluence_rate.py b/tests/test_fluence_rate.py new file mode 100644 index 0000000..710b2fb --- /dev/null +++ b/tests/test_fluence_rate.py @@ -0,0 +1,41 @@ +from math import dist, exp, pi + +import pytest + +from pg_rad.isotopes import CS137 +from pg_rad.landscape import Landscape +from pg_rad.objects import PointSource + + +@pytest.fixture +def phi_ref(): + A = 100 # MBq + b = 0.851 + mu_mass_air = 0.0778 # cm^2/g + air_density = 1.243 # kg/m^3 + r = dist((0, 0, 0), (10, 10, 0)) # m + + A *= 1E9 # Convert to Bq + mu_mass_air *= 0.1 # Convert to m^2/kg + + mu_air = mu_mass_air * air_density # [m^2/kg] x [kg/m^3] = [m^-1] + + # [s^-1] x exp([m^-1] x [m]) / [m^-2] = [s^-1 m^-2] + phi = A * b * exp(-mu_air * r) / (4 * pi * r**2) + return phi + + +@pytest.fixture +def test_landscape(): + landscape = Landscape() + source = PointSource( + pos=(0, 0, 0), + activity=100E9, + isotope=CS137) + landscape.add_sources(source) + return landscape + + +def test_single_source_fluence(phi_ref, test_landscape): + phi = test_landscape.calculate_fluence_at((10, 10, 0)) + assert pytest.approx(phi, rel=1E-3) == phi_ref