test_bulk_sphere_multi_precision.cc 2.0 KB

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