test_near_field.cc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "gtest/gtest.h"
  2. #include "../src/nmie-basic.hpp"
  3. #include "../src/nmie-nearfield.hpp"
  4. #include "test_cases.hpp"
  5. TEST(RunFieldCalculationPolar, HandlesInput) {
  6. nmie::MultiLayerMie<nmie::FloatType> nmie;
  7. EXPECT_THROW(nmie.RunFieldCalculationPolar(0), std::invalid_argument);
  8. EXPECT_THROW(nmie.RunFieldCalculationPolar(1,1,10,5), std::invalid_argument);
  9. double r = 60;
  10. // double r = 1500;
  11. nmie.SetLayersSize({r/2, r});
  12. nmie.SetLayersIndex({ {1.33,0}, {1.33,0}});
  13. nmie.RunMieCalculation();
  14. nmie.RunFieldCalculationPolar(1, 1,
  15. 0.5145*r,
  16. r*0.5148,
  17. 0, 3.14, 0, 0, true, 1);
  18. EXPECT_EQ(1, nmie.GetMaxTerms());
  19. EXPECT_FALSE(nmie.GetFieldConvergence());
  20. auto Eabs = nmie.GetFieldEabs();
  21. EXPECT_TRUE(std::isnan(static_cast<double>(Eabs[0])));
  22. }
  23. //#ifndef MULTI_PRECISION
  24. TEST(BulkSphere, HandlesInput) {
  25. nmie::MultiLayerMie<nmie::FloatType> nmie;
  26. for (const auto &data : parameters_bulk_sphere) {
  27. auto x = std::get<0>(data);
  28. auto m = std::get<1>(data);
  29. nmie.SetLayersSize({x});
  30. nmie.SetLayersIndex({m});
  31. nmie.SetMaxTerms(-1);
  32. // nmie.RunMieCalculation();
  33. // std::cout<<" test case: "<<std::get<2>(data)<<" Qsca="<<nmie.GetQsca()<<std::endl;
  34. nmie.RunFieldCalculationPolar(4,3,x,x*3, 0, static_cast<double>(nmie.PI_), 0, static_cast<double>(nmie.PI_),true, -1);
  35. auto Eabs = nmie.GetFieldEabs();
  36. for (auto &E:Eabs) E=nmie::pow2(E);
  37. // print(Eabs)
  38. EXPECT_TRUE(nmie.GetFieldConvergence())<<"Outside test for x="<<x<<" m="<<m<<" test case: "<<std::get<2>(data)<<std::endl;
  39. nmie.RunFieldCalculationPolar(4,10,x*0.01,x, 0, static_cast<double>(nmie.PI_), 0, static_cast<double>(nmie.PI_),true, -1);
  40. EXPECT_TRUE(nmie.GetFieldConvergence())<<"Inside test for x="<<x<<" m="<<m<<" test case: "<<std::get<2>(data)<<std::endl;
  41. }
  42. }
  43. //#endif
  44. int main(int argc, char **argv) {
  45. testing::InitGoogleTest(&argc, argv);
  46. return RUN_ALL_TESTS();
  47. }