example-eval-force.cc 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. auto shift = 0.0;
  49. shell_generator::ShellGenerator shell;
  50. shell.Init();
  51. for (int refines=0; refines<7; ++refines) {
  52. shell.Refine();
  53. for (int i=0; i<5; ++i) {
  54. auto integration_radius = 10+20*i;
  55. outer_width = 10; //+10*i; //nm Si
  56. multi_layer_mie.ClearAllDesign();
  57. multi_layer_mie.AddTargetLayer(outer_width, index_Si);
  58. multi_layer_mie.SetWavelength(WL);
  59. multi_layer_mie.RunMieCalculation();
  60. // double Qsca = multi_layer_mie.GetQsca();
  61. // printf("Qsca = %g\n", Qsca);
  62. double scale = 2.0*pi*(integration_radius)/WL*1.001; //Integration sphere radius.
  63. //double scale = 2.0*pi*(110)/WL*2.001; //Integration sphere radius.
  64. //double scale = 1.0001; //Integration sphere radius.
  65. //shell.PrintVerts();
  66. shell.Rescale(scale);
  67. //shell.PrintVerts();
  68. std::cout << "rescale with scale factor: " << scale << std::endl;
  69. // shell.RotateX(pi/2.0);
  70. // shell.RotateY(pi/2.0);
  71. // shell.RotateZ(pi/2.0);
  72. //shell.PrintVerts();
  73. // auto points = shell.GetVerticesT();
  74. // multi_layer_mie.SetFieldPointsSP(points);
  75. // multi_layer_mie.RunFieldCalculation();
  76. // auto E = nmie::ConvertComplexVectorVector<double>(multi_layer_mie.GetFieldE());
  77. // auto H = nmie::ConvertComplexVectorVector<double>(multi_layer_mie.GetFieldH());
  78. // shell.SetField(E,H);
  79. // auto F = shell.Integrate();
  80. // std::cout<<"F: " <<F[0]<<", "<< F[1] <<", "<<F[2] << std::endl<< std::endl;
  81. // auto F1 = shell.IntegrateByComp();
  82. // std::cout<<"F: " <<F1[0]<<", "<< F1[1] <<", "<<F1[2] << std::endl;
  83. auto charge = 2.54;
  84. {
  85. shift = 0.0 * scale;
  86. auto F1 = shell.IntegrateGaussSimple(charge, shift);
  87. std::cout<<"charge: "<< charge << " integral_R: " << scale << " \tshift_centerX: " << shift << " \tcharge result: " <<F1 << std::endl;
  88. }
  89. {
  90. shift = 0.5 * scale;
  91. auto F1 = shell.IntegrateGaussSimple(charge, shift);
  92. std::cout<<"charge: "<< charge << " integral_R: " << scale << " \tshift_centerX: " << shift << " \tresult: " <<F1 << std::endl;
  93. }
  94. {
  95. shift = 0.9 * scale;
  96. auto F1 = shell.IntegrateGaussSimple(charge, shift);
  97. std::cout<<"charge: "<< charge << " integral_R: " << scale << " \tshift_centerX: " << shift << " \tresult: " <<F1 << std::endl;
  98. }
  99. }
  100. } // end for refines
  101. } catch( const std::invalid_argument& ia ) {
  102. // Will catch if multi_layer_mie fails or other errors.
  103. std::cerr << "Invalid argument: " << ia.what() << std::endl;
  104. return -1;
  105. }
  106. return 0;
  107. }