test_bulk_sphere.cc 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "gtest/gtest.h"
  2. #include "../src/nmie-impl.hpp"
  3. TEST(BulkSphere, HandlesInput) {
  4. nmie::MultiLayerMie<double> nmie;
  5. // A list of tests for a bulk sphere from
  6. // Hong Du, "Mie-scattering calculation," Appl. Opt. 43, 1951-1956 (2004)
  7. // table 1: sphere size and refractive index
  8. // followed by resulting extinction and scattering efficiencies
  9. std::vector< std::tuple< double, std::complex<double>, double, double, char > >
  10. parameters_and_results
  11. {
  12. // x, {Re(m), Im(m)}, Qext, Qsca, test_name
  13. {0.099, {0.75,0}, 7.417859e-06, 7.417859e-06, 'a'},
  14. {0.101, {0.75,0}, 8.033538e-06, 8.033538e-06, 'b'},
  15. {10, {0.75,0}, 2.232265, 2.232265, 'c'},
  16. {1000, {0.75,0}, 1.997908, 1.997908, 'd'},
  17. // {100, {1.33,-1e-5}, 2.101321, 2.096594, 'e'},
  18. // {10000, {1.33,-1e-5}, 2.004089, 1.723857, 'f'},
  19. // {0.055, {1.5, -1}, 0.101491, 1.131687e-05, 'g'},
  20. // {0.056, {1.5, -1}, 0.1033467, 1.216311e-05, 'h'},
  21. // {100, {1.5, -1}, 2.097502, 1.283697, 'i'},
  22. // {10000, {1.5, -1}, 2.004368, 1.236574, 'j'},
  23. // {1, {10, -10}, 2.532993, 2.049405, 'k'},
  24. // {100, {10, -10,}, 2.071124, 1.836785, 'l'},
  25. // {10000, {10, -10}, 2.005914, 1.795393, 'm'},
  26. };
  27. for (const auto &data : parameters_and_results) {
  28. nmie.SetLayersSize({std::get<0>(data)});
  29. nmie.SetLayersIndex({std::get<1>(data)});
  30. nmie.RunMieCalculation();
  31. double Qext = nmie.GetQext();
  32. double Qsca = nmie.GetQsca();
  33. EXPECT_FLOAT_EQ(std::get<2>(data), Qext)
  34. << "Extinction of the bulk sphere, test case:" << std::get<4>(data);
  35. EXPECT_FLOAT_EQ(std::get<3>(data), Qsca)
  36. << "Scattering of the bulk sphere, test case:" << std::get<4>(data);
  37. }
  38. }
  39. int main(int argc, char **argv) {
  40. testing::InitGoogleTest(&argc, argv);
  41. return RUN_ALL_TESTS();
  42. }