example-get-Mie.cc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //**********************************************************************************//
  2. // Copyright (C) 2009-2015 Ovidio Pena <ovidio@bytesfall.com> //
  3. // Copyright (C) 2013-2015 Konstantin Ladutenko <kostyfisik@gmail.com> //
  4. // //
  5. // This file is part of scattnlay //
  6. // //
  7. // This program is free software: you can redistribute it and/or modify //
  8. // it under the terms of the GNU General Public License as published by //
  9. // the Free Software Foundation, either version 3 of the License, or //
  10. // (at your option) any later version. //
  11. // //
  12. // This program is distributed in the hope that it will be useful, //
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of //
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
  15. // GNU General Public License for more details. //
  16. // //
  17. // The only additional remark is that we expect that all publications //
  18. // describing work using this software, or all commercial products //
  19. // using it, cite the following reference: //
  20. // [1] O. Pena and U. Pal, "Scattering of electromagnetic radiation by //
  21. // a multilayered sphere," Computer Physics Communications, //
  22. // vol. 180, Nov. 2009, pp. 2348-2354. //
  23. // //
  24. // You should have received a copy of the GNU General Public License //
  25. // along with this program. If not, see <http://www.gnu.org/licenses/>. //
  26. //**********************************************************************************//
  27. // This program returns expansion coefficents of Mie series
  28. #include <complex>
  29. #include <cstdio>
  30. #include "../src/nmie-applied.h"
  31. int main(int argc, char *argv[]) {
  32. try {
  33. nmie::MultiLayerMieApplied multi_layer_mie;
  34. const std::complex<double> epsilon_Si(18.4631066585, 0.6259727805);
  35. const std::complex<double> epsilon_Ag(-8.5014154589, 0.7585845411);
  36. const std::complex<double> index_Si = std::sqrt(epsilon_Si);
  37. const std::complex<double> index_Ag = std::sqrt(epsilon_Ag);
  38. const double WL=500; //nm
  39. double core_width = 5.27; //nm Si
  40. double inner_width = 8.22; //nm Ag
  41. double outer_width = 67.91; //nm Si
  42. //bool isSiAgSi = true;
  43. bool isSiAgSi = false;
  44. if (isSiAgSi) {
  45. multi_layer_mie.AddTargetLayer(core_width, index_Si);
  46. multi_layer_mie.AddTargetLayer(inner_width, index_Ag);
  47. multi_layer_mie.AddTargetLayer(outer_width, index_Si);
  48. } else {
  49. inner_width = 31.93; //nm Ag
  50. outer_width = 4.06; //nm Si
  51. multi_layer_mie.AddTargetLayer(inner_width, index_Ag);
  52. multi_layer_mie.AddTargetLayer(outer_width, index_Si);
  53. }
  54. multi_layer_mie.SetWavelength(WL);
  55. multi_layer_mie.RunMieCalculation();
  56. double Qabs = multi_layer_mie.GetQabs();
  57. printf("Qabs = %g\n", Qabs);
  58. std::vector< std::vector<std::complex<double> > > aln, bln, cln, dln;
  59. multi_layer_mie.GetExpanCoeffs(aln, bln, cln, dln);
  60. for (int l = 0; l<aln.size(); ++l) {
  61. int n = 0;
  62. printf("aln[%i][%i] = %g, %gi)\n", l, n, aln[l][n].real(), aln[l][n].imag());
  63. printf("bln[%i][%i] = %g, %gi)\n", l, n, bln[l][n].real(), bln[l][n].imag());
  64. printf("cln[%i][%i] = %g, %gi)\n", l, n, cln[l][n].real(), cln[l][n].imag());
  65. printf("dln[%i][%i] = %g, %gi)\n", l, n, dln[l][n].real(), dln[l][n].imag());
  66. }
  67. } catch( const std::invalid_argument& ia ) {
  68. // Will catch if multi_layer_mie fails or other errors.
  69. std::cerr << "Invalid argument: " << ia.what() << std::endl;
  70. return -1;
  71. }
  72. return 0;
  73. }