test_near_field.cc 3.0 KB

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