test_bulk_sphere.cc 3.0 KB

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