example-eval-force.cc 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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-basic.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(1.1,0.0);
  45. // const std::complex<double> index_Ag = std::sqrt(epsilon_Ag);
  46. double WL=545; //nm
  47. //double WL=400; //nm
  48. //double outer_width = 67.91; //nm Si
  49. double outer_width = 4*2*2; //nm Si
  50. auto shift = 0.0;
  51. shell_generator::ShellGenerator shell;
  52. shell.Init();
  53. shell.Refine();
  54. shell.Refine();
  55. for (int refines=0; refines<1; ++refines) {
  56. shell.Refine();
  57. std::cout<<"Refined"<<std::endl;
  58. for (int i=0; i<7; ++i) {
  59. //outer_width = 40 + 5*i;
  60. auto integration_radius = outer_width + 5*i ;
  61. //outer_width = 10; //+10*i; //nm Si
  62. multi_layer_mie.ClearAllDesign();
  63. multi_layer_mie.AddTargetLayer(outer_width, index_Si);
  64. multi_layer_mie.SetWavelength(WL);
  65. multi_layer_mie.RunMieCalculation();
  66. double Qsca = multi_layer_mie.GetQsca();
  67. //printf("Qsca = %g\t", Qsca);
  68. double scale = 2.0*pi*(integration_radius)/WL*1.00001; //Integration sphere radius.
  69. shell.Rescale(scale);
  70. // auto points = shell.GetVerticesT();
  71. auto points = shell.GetFaceCentersT();
  72. multi_layer_mie.SetFieldPointsSP(points);
  73. multi_layer_mie.RunFieldCalculation();
  74. auto E = nmie::ConvertComplexVectorVector<double>(multi_layer_mie.GetFieldE());
  75. auto H = nmie::ConvertComplexVectorVector<double>(multi_layer_mie.GetFieldH());
  76. // auto Es = nmie::ConvertComplexVectorVector<double>(multi_layer_mie.GetFieldEs());
  77. // auto Hs = nmie::ConvertComplexVectorVector<double>(multi_layer_mie.GetFieldHs());
  78. shell.SetField(E,H);
  79. //shell.SetFieldSph(Es,Hs);
  80. // auto F = shell.Integrate();
  81. //auto F = shell.IntegrateByFaces();
  82. //auto F = shell.IntegrateByComp();
  83. // auto F = shell.IntegrateByCompReal();
  84. //std::cout << "integrate_R:\t" << scale*WL/(2.0*pi);
  85. //std::cout<<"\tforce:\t" <<F[0]<<"\t"<< F[1] <<"\t"<<F[2] << std::endl;
  86. auto F = shell.IntegrateGauss(2.54,12.03);
  87. //std::cout<<"\tcharge:\t" <<F<< std::endl;
  88. // auto F1 = shell.IntegrateByComp();
  89. // std::cout<<"F: " <<F1[0]<<", "<< F1[1] <<", "<<F1[2] << std::endl;
  90. }
  91. } // end for refines
  92. } catch( const std::invalid_argument &ia ) {
  93. // Will catch if multi_layer_mie fails or other errors.
  94. std::cerr << "Invalid argument: " << ia.what() << std::endl;
  95. return -1;
  96. }
  97. return 0;
  98. }