test_bulk_sphere.cc 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "gtest/gtest.h"
  2. #include "../src/nmie-impl.hpp"
  3. #include "../src/nmie-precision.hpp"
  4. TEST(BulkSphere, ArgPi) {
  5. std::vector<double> WLs{50, 80, 100,200, 400}; //nm
  6. double host_index = 2.;
  7. double core_radius = 100.; //nm
  8. double delta = 1e-5;
  9. nmie::MultiLayerMie<nmie::FloatType> nmie;
  10. nmie.SetLayersIndex({std::complex<double>(4,0)});
  11. for (auto WL:WLs) {
  12. nmie.SetLayersSize({2*nmie.PI_*host_index*core_radius/(WL+delta)});
  13. nmie.RunMieCalculation();
  14. double Qabs_p = std::abs(static_cast<double>(nmie.GetQabs()));
  15. nmie.SetLayersSize({2*nmie.PI_*host_index*core_radius/(WL-delta)});
  16. nmie.RunMieCalculation();
  17. double Qabs_m = std::abs(static_cast<double>(nmie.GetQabs()));
  18. nmie.SetLayersSize({2*nmie.PI_*host_index*core_radius/(WL)});
  19. nmie.RunMieCalculation();
  20. double Qabs = std::abs(static_cast<double>(nmie.GetQabs()));
  21. EXPECT_GT(Qabs_p+Qabs_m, Qabs);
  22. }
  23. }
  24. TEST(BulkSphere, HandlesInput) {
  25. nmie::MultiLayerMie<nmie::FloatType> nmie;
  26. // A list of tests for a bulk sphere from
  27. // Hong Du, "Mie-scattering calculation," Appl. Opt. 43, 1951-1956 (2004)
  28. // table 1: sphere size and refractive index
  29. // followed by resulting extinction and scattering efficiencies
  30. std::vector< std::tuple< double, std::complex<double>, double, double, char > >
  31. parameters_and_results
  32. {
  33. // x, {Re(m), Im(m)}, Qext, Qsca, test_name
  34. {0.099, {0.75,0}, 7.417859e-06, 7.417859e-06, 'a'},
  35. {0.101, {0.75,0}, 8.033538e-06, 8.033538e-06, 'b'},
  36. {10, {0.75,0}, 2.232265, 2.232265, 'c'},
  37. {1000, {0.75,0}, 1.997908, 1.997908, 'd'},
  38. // {100, {1.33,-1e-5}, 2.101321, 2.096594, 'e'},
  39. // {10000, {1.33,-1e-5}, 2.004089, 1.723857, 'f'},
  40. // {0.055, {1.5, -1}, 0.101491, 1.131687e-05, 'g'},
  41. // {0.056, {1.5, -1}, 0.1033467, 1.216311e-05, 'h'},
  42. // {100, {1.5, -1}, 2.097502, 1.283697, 'i'},
  43. // {10000, {1.5, -1}, 2.004368, 1.236574, 'j'},
  44. // {1, {10, -10}, 2.532993, 2.049405, 'k'},
  45. // {100, {10, -10,}, 2.071124, 1.836785, 'l'},
  46. // {10000, {10, -10}, 2.005914, 1.795393, 'm'},
  47. };
  48. for (const auto &data : parameters_and_results) {
  49. nmie.SetLayersSize({std::get<0>(data)});
  50. nmie.SetLayersIndex({std::get<1>(data)});
  51. // nmie.SetMaxTerms(150);
  52. nmie.RunMieCalculation();
  53. double Qext = static_cast<double>(nmie.GetQext());
  54. double Qsca = static_cast<double>(nmie.GetQsca());
  55. EXPECT_FLOAT_EQ(std::get<2>(data), Qext)
  56. << "Extinction of the bulk sphere, test case:" << std::get<4>(data)
  57. << "\nnmax_ = " << nmie.GetMaxTerms();
  58. EXPECT_FLOAT_EQ(std::get<3>(data), Qsca)
  59. << "Scattering of the bulk sphere, test case:" << std::get<4>(data);
  60. }
  61. }
  62. int main(int argc, char **argv) {
  63. testing::InitGoogleTest(&argc, argv);
  64. return RUN_ALL_TESTS();
  65. }