nmie-js-wrapper.cc 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //**********************************************************************************//
  2. // Copyright (C) 2009-2019 Ovidio Pena <ovidio@bytesfall.com> //
  3. // Copyright (C) 2013-2019 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 at least one of the following references: //
  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. // [2] K. Ladutenko, U. Pal, A. Rivera, and O. Pena-Rodriguez, "Mie //
  24. // calculation of electromagnetic near-field for a multilayered //
  25. // sphere," Computer Physics Communications, vol. 214, May 2017, //
  26. // pp. 225-230. //
  27. // //
  28. // You should have received a copy of the GNU General Public License //
  29. // along with this program. If not, see <http://www.gnu.org/licenses/>. //
  30. // //
  31. // @brief Wrapper to JS
  32. // //
  33. //**********************************************************************************//
  34. #include "nmie-applied.hpp"
  35. #include "nmie-applied-impl.hpp"
  36. #include "nmie-precision.hpp"
  37. using namespace emscripten;
  38. nmie::MultiLayerMieApplied<double> ml_mie;
  39. EMSCRIPTEN_BINDINGS (c) {
  40. class_<nmie::MultiLayerMieApplied<double>>("nmie")
  41. .constructor<>()
  42. .function("SetWavelength", &nmie::MultiLayerMieApplied<double>::SetWavelength)
  43. .function("AddTargetLayerReIm",&nmie::MultiLayerMieApplied<double>::AddTargetLayerReIm)
  44. .function("SetModeNmaxAndType",&nmie::MultiLayerMieApplied<double>::SetModeNmaxAndType)
  45. .function("ClearTarget",&nmie::MultiLayerMieApplied<double>::ClearTarget)
  46. .function("RunMieCalculation",&nmie::MultiLayerMieApplied<double>::RunMieCalculation)
  47. .function("RunFieldCalculationPolar",&nmie::MultiLayerMieApplied<double>::RunFieldCalculationPolar)
  48. .function("GetFieldEabs",&nmie::MultiLayerMieApplied<double>::GetFieldEabs)
  49. .function("GetQsca",&nmie::MultiLayerMieApplied<double>::GetQsca)
  50. .function("GetQext",&nmie::MultiLayerMieApplied<double>::GetQext)
  51. .function("GetQabs",&nmie::MultiLayerMieApplied<double>::GetQabs)
  52. // .function("bf",&nmie::MultiLayerMieApplied<double>::bf)
  53. ;
  54. }
  55. //namespace nmie {
  56. //**********************************************************************************//
  57. // This function emulates a C call to calculate the actual scattering parameters //
  58. // and amplitudes. //
  59. // //
  60. // Input parameters: //
  61. // L: Number of layers //
  62. // pl: Index of PEC layer. If there is none just send -1 //
  63. // x: Array containing the size parameters of the layers [0..L-1] //
  64. // m: Array containing the relative refractive indexes of the layers [0..L-1] //
  65. // nTheta: Number of scattering angles //
  66. // Theta: Array containing all the scattering angles where the scattering //
  67. // amplitudes will be calculated //
  68. // nmax: Maximum number of multipolar expansion terms to be used for the //
  69. // calculations. Only use it if you know what you are doing, otherwise //
  70. // set this parameter to -1 and the function will calculate it //
  71. // //
  72. // Output parameters: //
  73. // Qext: Efficiency factor for extinction //
  74. // Qsca: Efficiency factor for scattering //
  75. // Qabs: Efficiency factor for absorption (Qabs = Qext - Qsca) //
  76. // Qbk: Efficiency factor for backscattering //
  77. // Qpr: Efficiency factor for the radiation pressure //
  78. // g: Asymmetry factor (g = (Qext-Qpr)/Qsca) //
  79. // Albedo: Single scattering albedo (Albedo = Qsca/Qext) //
  80. // S1, S2: Complex scattering amplitudes //
  81. // //
  82. // Return value: //
  83. // Number of multipolar expansion terms used for the calculations //
  84. //**********************************************************************************//
  85. // int nMieApplied(const unsigned int L, const int pl, std::vector<double> &x, std::vector<std::complex<double> > &m, const unsigned int nTheta, std::vector<double> &Theta, const int nmax, double *Qext, double *Qsca, double *Qabs, double *Qbk, double *Qpr, double *g, double *Albedo, std::vector<std::complex<double> >& S1, std::vector<std::complex<double> >& S2) {
  86. //
  87. // if (x.size() != L || m.size() != L)
  88. // throw std::invalid_argument("Declared number of layers do not fit x and m!");
  89. // if (Theta.size() != nTheta)
  90. // throw std::invalid_argument("Declared number of sample for Theta is not correct!");
  91. // try {
  92. // MultiLayerMieApplied<FloatType> ml_mie;
  93. // ml_mie.SetLayersSize(ConvertVector<FloatType>(x));
  94. // ml_mie.SetLayersIndex(ConvertComplexVector<FloatType>(m));
  95. // ml_mie.SetAngles(ConvertVector<FloatType>(Theta));
  96. // ml_mie.SetPECLayer(pl);
  97. // ml_mie.SetMaxTerms(nmax);
  98. //
  99. // ml_mie.RunMieCalculation();
  100. //
  101. // *Qext = static_cast<double>(ml_mie.GetQext());
  102. // *Qsca = static_cast<double>(ml_mie.GetQsca());
  103. // *Qabs = static_cast<double>(ml_mie.GetQabs());
  104. // *Qbk = static_cast<double>(ml_mie.GetQbk());
  105. // *Qpr = static_cast<double>(ml_mie.GetQpr());
  106. // *g = static_cast<double>(ml_mie.GetAsymmetryFactor());
  107. // *Albedo = static_cast<double>(ml_mie.GetAlbedo());
  108. // S1 = ConvertComplexVector<double>(ml_mie.GetS1());
  109. // S2 = ConvertComplexVector<double>(ml_mie.GetS2());
  110. //
  111. // return ml_mie.GetMaxTerms();
  112. // } catch(const std::invalid_argument& ia) {
  113. // // Will catch if ml_mie fails or other errors.
  114. // std::cerr << "Invalid argument: " << ia.what() << std::endl;
  115. // throw std::invalid_argument(ia);
  116. // return -1;
  117. // }
  118. // return 0;
  119. // }
  120. // int nMieApplied(const unsigned int L, std::vector<double>& x, std::vector<std::complex<double> >& m, const unsigned int nTheta, std::vector<double>& Theta, double *Qext, double *Qsca, double *Qabs, double *Qbk, double *Qpr, double *g, double *Albedo, std::vector<std::complex<double> >& S1, std::vector<std::complex<double> >& S2) {
  121. // return nmie::nMieApplied(L, -1, x, m, nTheta, Theta, -1, Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo, S1, S2);
  122. // }
  123. // int nMieApplied(const unsigned int L, const int pl, std::vector<double>& x, std::vector<std::complex<double> >& m, const unsigned int nTheta, std::vector<double>& Theta, double *Qext, double *Qsca, double *Qabs, double *Qbk, double *Qpr, double *g, double *Albedo, std::vector<std::complex<double> >& S1, std::vector<std::complex<double> >& S2) {
  124. // return nmie::nMieApplied(L, pl, x, m, nTheta, Theta, -1, Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo, S1, S2);
  125. // }
  126. // int nMieApplied(const unsigned int L, std::vector<double>& x, std::vector<std::complex<double> >& m, const unsigned int nTheta, std::vector<double>& Theta, const int nmax, double *Qext, double *Qsca, double *Qabs, double *Qbk, double *Qpr, double *g, double *Albedo, std::vector<std::complex<double> >& S1, std::vector<std::complex<double> >& S2) {
  127. // return nmie::nMieApplied(L, -1, x, m, nTheta, Theta, nmax, Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo, S1, S2);
  128. // }
  129. // ********************************************************************** //
  130. // ********************************************************************** //
  131. // ********************************************************************** //
  132. //} // end of namespace nmie