test-negative-epsilon.cc 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /**
  2. * @file test-negative-epsilon.cc
  3. * @author Konstantin Ladutenko <kostyfisik at gmail (.) com>
  4. * @date Mon Mar 9 13:21:37 2015
  5. *
  6. * @brief test negative epsilon case
  7. *
  8. // This file is part of scattnlay //
  9. // //
  10. // This program is free software: you can redistribute it and/or modify //
  11. // it under the terms of the GNU General Public License as published by //
  12. // the Free Software Foundation, either version 3 of the License, or //
  13. // (at your option) any later version. //
  14. // //
  15. // This program is distributed in the hope that it will be useful, //
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of //
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
  18. // GNU General Public License for more details. //
  19. // //
  20. // The only additional remark is that we expect that all publications //
  21. // describing work using this software, or all commercial products //
  22. // using it, cite the following reference: //
  23. // [1] O. Pena and U. Pal, "Scattering of electromagnetic radiation by //
  24. // a multilayered sphere," Computer Physics Communications, //
  25. // vol. 180, Nov. 2009, pp. 2348-2354. //
  26. // //
  27. // You should have received a copy of the GNU General Public License //
  28. // along with this program. If not, see <http://www.gnu.org/licenses/>. //
  29. *
  30. */
  31. #include "nmie.h"
  32. #include <stdio.h>
  33. template<class T> inline T pow2(const T value) {return value*value;};
  34. const double PI=3.14159265358979323846;
  35. nmie::MultiLayerMie multi_layer_mie_;
  36. double lambda_work_ = 3.75; // cm
  37. double a_ = 0.75*lambda_work_; // 2.8125 cm - size of PEC core
  38. double min_index_ = 1e-11;
  39. // ********************************************************************** //
  40. // ********************************************************************** //
  41. // ********************************************************************** //
  42. double EvaluateScatterOnlyIndex(std::vector<double> input) {
  43. double Qsca;
  44. std::vector<std::complex<double>> cindex;
  45. cindex.clear();
  46. double k = min_index_, n=min_index_;
  47. for (double epsilon : input) {
  48. // sqrt(epsilon) = n + i*k
  49. k = min_index_;
  50. n=min_index_;
  51. if (epsilon > 0.0) n=std::sqrt(epsilon);
  52. else k = std::sqrt(-epsilon);
  53. if (n < min_index_) n = min_index_;
  54. if (k < min_index_) k = min_index_;
  55. //printf("eps= %g, n=%g, k=%g\n", epsilon, n, k);
  56. cindex.push_back(std::complex<double>(n, k));
  57. }
  58. multi_layer_mie_.SetCoatingIndex(cindex);
  59. try {
  60. multi_layer_mie_.RunMieCalculations();
  61. Qsca = multi_layer_mie_.GetQsca();
  62. } catch( const std::invalid_argument &ia ) {
  63. Qsca = 0;
  64. printf("#");
  65. // Will catch if multi_layer_mie_ fails or other errors.
  66. //std::cerr << "Invalid argument: " << ia.what() << std::endl;
  67. }
  68. double total_r = multi_layer_mie_.GetTotalRadius();
  69. return Qsca*PI*pow2(total_r);
  70. }
  71. int main(int argc, char *argv[]) {
  72. try {
  73. // Only PEC target
  74. multi_layer_mie_.SetTargetPEC(a_);
  75. multi_layer_mie_.SetWavelength(lambda_work_);
  76. multi_layer_mie_.RunMieCalculations();
  77. double PEC_Qsca = multi_layer_mie_.GetQsca();
  78. double PEC_r = multi_layer_mie_.GetTotalRadius();
  79. double PEC_RCS = PEC_Qsca*PI*pow2(PEC_r);
  80. // PEC target covered with with air layer
  81. multi_layer_mie_.SetCoatingWidth({0.1});
  82. multi_layer_mie_.SetCoatingIndex({{1.0,0.0}});
  83. multi_layer_mie_.RunMieCalculations();
  84. double Qsca1 = multi_layer_mie_.GetQsca();
  85. double total_r1 = multi_layer_mie_.GetTotalRadius();
  86. double initial_RCS1 = Qsca1*PI*pow2(total_r1);
  87. printf("RCS = %g cm^2 with (r=%g) and RCS=%g cm^2 without (r=%g)air coating.\n",
  88. initial_RCS1, total_r1,
  89. PEC_RCS, PEC_r);
  90. //multi_layer_mie.SetMaxTermsNumber(150);
  91. // Bi-layer, inner layer = lossless metall.
  92. std::vector<std::complex<double>> cindex;
  93. cindex.clear();
  94. double n=min_index_;
  95. double k=std::sqrt(0.29);
  96. cindex.push_back(std::complex<double>(n, k));
  97. n=std::sqrt(24.6);
  98. k=min_index_;
  99. cindex.push_back(std::complex<double>(n, k));
  100. multi_layer_mie_.SetCoatingWidth({0.1,0.1});
  101. multi_layer_mie_.SetCoatingIndex(cindex);
  102. multi_layer_mie_.RunMieCalculations();
  103. double Qsca = multi_layer_mie_.GetQsca();
  104. double total_r = multi_layer_mie_.GetTotalRadius();
  105. double initial_RCS = Qsca*PI*pow2(total_r);
  106. printf("RCS=%g for bi-layer coating (total R=%g).\n", initial_RCS,total_r);
  107. n=1.0;
  108. k=min_index_;
  109. cindex.push_back(std::complex<double>(n, k));
  110. multi_layer_mie_.SetCoatingWidth({0.1,0.1,0.1});
  111. multi_layer_mie_.SetCoatingIndex(cindex);
  112. multi_layer_mie_.RunMieCalculations();
  113. Qsca = multi_layer_mie_.GetQsca();
  114. total_r = multi_layer_mie_.GetTotalRadius();
  115. initial_RCS = Qsca*PI*pow2(total_r);
  116. printf("RCS=%g for bi-layer+air coating (total R=%g).\n", initial_RCS,total_r);
  117. //multi_layer_mie_.SetMaxTermsNumber(15);
  118. multi_layer_mie_.SetCoatingWidth({0.1,0.1});
  119. printf("With %g coating= (26.24).\n",
  120. EvaluateScatterOnlyIndex({-0.29, 24.6}));
  121. multi_layer_mie_.SetCoatingWidth({0.1,0.1,0.1});
  122. printf("With %g coating> (26.24).\n",
  123. EvaluateScatterOnlyIndex({-0.29, 24.6, 1.0}));
  124. //multi_layer_mie_.SetMaxTermsNumber(-1);
  125. // 26.24: 25|| -0.29 +24.60
  126. // 28.48: 38|| -0.29 +24.60 +1.00
  127. } catch( const std::invalid_argument &ia ) {
  128. // Will catch if multi_layer_mie fails or other errors.
  129. std::cerr << "Invalid argument: " << ia.what() << std::endl;
  130. return -1;
  131. }
  132. return 0;
  133. }