|
21 | 21 | """ |
22 | 22 |
|
23 | 23 | from .. import Quantity, index_ratio, size_parameter, np, mie |
24 | | -from numpy.testing import assert_almost_equal, assert_array_almost_equal, assert_approx_equal |
| 24 | +from numpy.testing import (assert_almost_equal, assert_array_almost_equal, |
| 25 | + assert_approx_equal, assert_allclose) |
25 | 26 | from pint.errors import DimensionalityError |
26 | 27 | import pytest |
27 | 28 |
|
@@ -441,6 +442,49 @@ def test_pis_taus(): |
441 | 442 | assert_almost_equal(taus, taus_v) |
442 | 443 |
|
443 | 444 |
|
| 445 | +def test_differential_cross_section(): |
| 446 | + """ |
| 447 | + Tests that the differential cross-sections from diff_scat_complex_medium() |
| 448 | + and calc_ang_dist() are the same for a non-absorbing medium. |
| 449 | + """ |
| 450 | + # set parameters |
| 451 | + wavelen = Quantity("400.0 nm") |
| 452 | + n_particle = Quantity(1.5, "") |
| 453 | + n_matrix = Quantity(1.0, "") |
| 454 | + radius = Quantity(150.0, "nm") |
| 455 | + theta = Quantity(np.linspace(0, np.pi, 1000), "rad") |
| 456 | + distance = Quantity(10000.0, "nm") |
| 457 | + |
| 458 | + m = index_ratio(n_particle, n_matrix) |
| 459 | + k = 2*np.pi*n_matrix/wavelen |
| 460 | + x = size_parameter(wavelen, n_matrix, radius) |
| 461 | + |
| 462 | + # With far-field Mie solutions |
| 463 | + I_par_cad, I_perp_cad = mie.calc_ang_dist(m, x, theta) |
| 464 | + |
| 465 | + # With Mie solutions at surface of particle (but neglecting near-fields) |
| 466 | + kd = (k*distance).to("").magnitude |
| 467 | + I_par_scat, I_perp_scat = mie.diff_scat_intensity_complex_medium(m, x, theta, |
| 468 | + kd) |
| 469 | + |
| 470 | + # calc_ang_dist returns dimensionless differential cross-sections (times |
| 471 | + # k^2). As noted in diff_scat_intensity_complex_medium(), this function |
| 472 | + # returns dimensionless values (scaled by k^2) muliplied by a factor of |
| 473 | + # 1/kd^2 for a non-absorbing medium. Therefore the |
| 474 | + # diff_scat_intensity_complex_medium() results are the dimensional |
| 475 | + # cross-sections scaled by 1/d^2, where d is the distance at which the |
| 476 | + # calculation is done. In short, both functions return dimensionless |
| 477 | + # cross-sections, but the ones returned by |
| 478 | + # diff_scat_intensity_complex_medium() need to be multiplied by a factor of |
| 479 | + # kd^2 to compare them to those of calc_ang_dist() |
| 480 | + # |
| 481 | + # since both of these functions rely on the same routine to calculate the |
| 482 | + # amplitude scattering matrix, they should give results to within |
| 483 | + # floating-point precision |
| 484 | + assert_allclose(I_par_scat*kd**2, I_par_cad, rtol=1e-14) |
| 485 | + assert_allclose(I_perp_scat*kd**2, I_perp_cad, rtol=1e-14) |
| 486 | + |
| 487 | + |
444 | 488 | def test_cross_section_complex_medium(): |
445 | 489 |
|
446 | 490 | # test that the cross sections calculated with the Mie solutions in absorbing |
|
0 commit comments