example-eval-force.cc 4.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //**********************************************************************************//
  2. // Copyright (C) 2009-2016 Ovidio Pena <ovidio@bytesfall.com> //
  3. // Copyright (C) 2013-2016 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 evaluates forces acting on the nanoparticle under irradiaton.
  28. #include <complex>
  29. #include <cstdio>
  30. #include <string>
  31. #include <iostream>
  32. #include "../src/nmie.hpp"
  33. #include "../src/nmie-impl.hpp"
  34. #include "../src/nmie-applied.hpp"
  35. #include "../src/nmie-applied-impl.hpp"
  36. #include "../src/shell-generator.hpp"
  37. int main(int argc, char *argv[]) {
  38. try {
  39. const double pi = 3.1415926535897932384626433832795;
  40. nmie::MultiLayerMieApplied<double> multi_layer_mie;
  41. // const std::complex<double> epsilon_Si(18.4631066585, 0.6259727805);
  42. // const std::complex<double> epsilon_Ag(-8.5014154589, 0.7585845411);
  43. // const std::complex<double> index_Si = std::sqrt(epsilon_Si);
  44. const std::complex<double> index_Si(2.0);
  45. // const std::complex<double> index_Ag = std::sqrt(epsilon_Ag);
  46. double WL=500; //nm
  47. // double core_width = 5.27; //nm Si
  48. // double inner_width = 8.22; //nm Ag
  49. double outer_width = 67.91; //nm Si
  50. // core_width = 5.27; //nm Si
  51. // inner_width = 8.22; //nm Ag
  52. //outer_width = WL/(2.0*pi); //nm Si
  53. outer_width = 50; //nm Si
  54. // multi_layer_mie.AddTargetLayer(core_width, index_Si);
  55. // multi_layer_mie.AddTargetLayer(inner_width, index_Ag);
  56. multi_layer_mie.AddTargetLayer(outer_width, index_Si);
  57. multi_layer_mie.SetWavelength(WL);
  58. multi_layer_mie.RunMieCalculation();
  59. double Qsca = multi_layer_mie.GetQsca();
  60. printf("Qsca = %g\n", Qsca);
  61. shell_generator::ShellGenerator shell;
  62. shell.Init();
  63. // shell.Refine();
  64. // shell.Refine();
  65. //shell.Refine();
  66. //double scale = 2.0*pi*(core_width + inner_width + outer_width)/WL*8.0001; //Integration sphere radius.
  67. double scale = 2.0*pi*(outer_width)/WL*1.0001; //Integration sphere radius.
  68. //double scale = 1.0001; //Integration sphere radius.
  69. shell.Rescale(scale);
  70. // shell.RotateX(pi/2.0);
  71. // shell.RotateY(pi/2.0);
  72. // shell.RotateZ(pi/2.0);
  73. //shell.PrintVerts();
  74. auto points = shell.GetVerticesT();
  75. multi_layer_mie.SetFieldPointsSP(points);
  76. multi_layer_mie.RunFieldCalculation();
  77. auto E = nmie::ConvertComplexVectorVector<double>(multi_layer_mie.GetFieldE());
  78. auto H = nmie::ConvertComplexVectorVector<double>(multi_layer_mie.GetFieldH());
  79. shell.SetField(E,H);
  80. auto F = shell.Integrate();
  81. std::cout<<"F: " <<F[0]<<", "<< F[1] <<", "<<F[2] << std::endl<< std::endl;
  82. F = shell.IntegrateByComp();
  83. std::cout<<"F: " <<F[0]<<", "<< F[1] <<", "<<F[2] << std::endl;
  84. } catch( const std::invalid_argument& ia ) {
  85. // Will catch if multi_layer_mie fails or other errors.
  86. std::cerr << "Invalid argument: " << ia.what() << std::endl;
  87. return -1;
  88. }
  89. return 0;
  90. }