example-eval-force.cc 4.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 outer_width = 67.91; //nm Si
  48. shell_generator::ShellGenerator shell;
  49. shell.Init();
  50. shell.Refine();
  51. shell.Refine();
  52. shell.Refine();
  53. for (int i=0; i<10; ++i) {
  54. outer_width = 10+10*i; //nm Si
  55. multi_layer_mie.AddTargetLayer(outer_width, index_Si);
  56. multi_layer_mie.SetWavelength(WL);
  57. multi_layer_mie.RunMieCalculation();
  58. double Qsca = multi_layer_mie.GetQsca();
  59. printf("Qsca = %g\n", Qsca);
  60. //double scale = 2.0*pi*(outer_width)/WL*1.001; //Integration sphere radius.
  61. double scale = 2.0*pi*(110)/WL*2.001; //Integration sphere radius.
  62. //double scale = 1.0001; //Integration sphere radius.
  63. shell.Rescale(scale);
  64. // shell.RotateX(pi/2.0);
  65. // shell.RotateY(pi/2.0);
  66. // shell.RotateZ(pi/2.0);
  67. //shell.PrintVerts();
  68. auto points = shell.GetVerticesT();
  69. multi_layer_mie.SetFieldPointsSP(points);
  70. multi_layer_mie.RunFieldCalculation();
  71. auto E = nmie::ConvertComplexVectorVector<double>(multi_layer_mie.GetFieldE());
  72. auto H = nmie::ConvertComplexVectorVector<double>(multi_layer_mie.GetFieldH());
  73. shell.SetField(E,H);
  74. // auto F = shell.Integrate();
  75. // std::cout<<"F: " <<F[0]<<", "<< F[1] <<", "<<F[2] << std::endl<< std::endl;
  76. auto F1 = shell.IntegrateByComp();
  77. std::cout<<"F: " <<F1[0]<<", "<< F1[1] <<", "<<F1[2] << std::endl;
  78. }
  79. } catch( const std::invalid_argument& ia ) {
  80. // Will catch if multi_layer_mie fails or other errors.
  81. std::cerr << "Invalid argument: " << ia.what() << std::endl;
  82. return -1;
  83. }
  84. return 0;
  85. }