example-minimal.cc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //**********************************************************************************//
  2. // Copyright (C) 2009-2015 Ovidio Pena <ovidio@bytesfall.com> // Copyright
  3. // (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 // it
  8. // under the terms of the GNU General Public License as published by // the
  9. // Free Software Foundation, either version 3 of the License, or // (at your
  10. // option) any later version. //
  11. // //
  12. // This program is distributed in the hope that it will be useful, // but
  13. // WITHOUT ANY WARRANTY; without even the implied warranty of //
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU
  15. // 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 // using
  19. // it, cite the following reference: //
  20. // [1] O. Pena and U. Pal, "Scattering of electromagnetic radiation by //
  21. // a multilayered sphere," Computer Physics Communications, // vol. 180,
  22. // Nov. 2009, pp. 2348-2354. //
  23. // //
  24. // You should have received a copy of the GNU General Public License // along
  25. // with this program. If not, see <http://www.gnu.org/licenses/>. //
  26. //**********************************************************************************//
  27. // This program evaluates absorption of a triple layered nanoparticle
  28. #include <cassert>
  29. #include <complex>
  30. #include <cstdio>
  31. #include <iomanip>
  32. #include <sstream>
  33. #include <string>
  34. #include "../src/nmie-applied-impl.hpp"
  35. int main(int, char**) {
  36. try {
  37. nmie::MultiLayerMieApplied<double> multi_layer_mie;
  38. const std::complex<double> epsilon_Si(18.4631066585, 0.6259727805);
  39. const std::complex<double> epsilon_Ag(-8.5014154589, 0.7585845411);
  40. const std::complex<double> index_Si = std::sqrt(epsilon_Si);
  41. const std::complex<double> index_Ag = std::sqrt(epsilon_Ag);
  42. double WL = 500; // nm
  43. double core_width = 5.27; // nm Si
  44. double inner_width = 8.22; // nm Ag
  45. double outer_width = 67.91; // nm Si
  46. core_width = 5.27; // nm Si
  47. inner_width = 8.22; // nm Ag
  48. outer_width = 67.91; // nm Si
  49. multi_layer_mie.AddTargetLayer(core_width, index_Si);
  50. multi_layer_mie.AddTargetLayer(inner_width, index_Ag);
  51. multi_layer_mie.AddTargetLayer(outer_width, index_Si);
  52. multi_layer_mie.SetWavelength(WL);
  53. multi_layer_mie.RunMieCalculation();
  54. double Qabs = multi_layer_mie.GetQabs();
  55. std::stringstream stream;
  56. stream << std::fixed << std::setprecision(10) << Qabs;
  57. auto Qabs_str = stream.str();
  58. printf("Qabs = %s\n", Qabs_str.c_str());
  59. assert(Qabs_str == "3.1415556911");
  60. } catch (const std::invalid_argument& ia) {
  61. // Will catch if multi_layer_mie fails or other errors.
  62. std::cerr << "Invalid argument: " << ia.what() << std::endl;
  63. return -1;
  64. }
  65. return 0;
  66. }