mesomie.hpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #ifndef SRC_MESOMIE_HPP_
  2. #define SRC_MESOMIE_HPP_
  3. //******************************************************************************
  4. // Copyright (C) 2009-2022 Ovidio Pena <ovidio@bytesfall.com>
  5. // Copyright (C) 2013-2022 Konstantin Ladutenko <kostyfisik@gmail.com>
  6. //
  7. // This file is part of scattnlay
  8. //
  9. // This program is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU General Public License as published by
  11. // the Free Software Foundation, either version 3 of the License, or
  12. // (at your option) any later version.
  13. //
  14. // This program is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. // GNU General Public License for more details.
  18. //
  19. // The only additional remark is that we expect that all publications
  20. // describing work using this software, or all commercial products
  21. // using it, cite at least one of the following references:
  22. // [1] O. Pena and U. Pal, "Scattering of electromagnetic radiation by
  23. // a multilayered sphere," Computer Physics Communications,
  24. // vol. 180, Nov. 2009, pp. 2348-2354.
  25. // [2] K. Ladutenko, U. Pal, A. Rivera, and O. Pena-Rodriguez, "Mie
  26. // calculation of electromagnetic near-field for a multilayered
  27. // sphere," Computer Physics Communications, vol. 214, May 2017,
  28. // pp. 225-230.
  29. //
  30. // You should have received a copy of the GNU General Public License
  31. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  32. //******************************************************************************
  33. //******************************************************************************
  34. // This class implements the algorithm for a multilayered sphere described by:
  35. // [1] W. Yang, "Improved recursive algorithm for light scattering by a
  36. // multilayered sphere,” Applied Optics, vol. 42, Mar. 2003, pp.
  37. // 1710-1720.
  38. //
  39. // You can find the description of all the used equations in:
  40. // [2] O. Pena and U. Pal, "Scattering of electromagnetic radiation by
  41. // a multilayered sphere," Computer Physics Communications,
  42. // vol. 180, Nov. 2009, pp. 2348-2354.
  43. // [3] K. Ladutenko, U. Pal, A. Rivera, and O. Pena-Rodriguez, "Mie
  44. // calculation of electromagnetic near-field for a multilayered
  45. // sphere," Computer Physics Communications, vol. 214, May 2017,
  46. // pp. 225-230.
  47. //
  48. // Hereinafter all equations numbers refer to [2]
  49. //******************************************************************************
  50. #include <iomanip>
  51. #include <iostream>
  52. #include <stdexcept>
  53. #include <vector>
  54. #include "nmie.hpp"
  55. #include "special-functions-impl.hpp"
  56. namespace nmie {
  57. //******************************************************************************
  58. template <typename FloatType>
  59. void MesoMie<FloatType>::calc_Q() {
  60. auto nmax = an_.size();
  61. Qext_ = 0.0;
  62. Qsca_ = 0.0;
  63. for (int n = nmax - 2; n >= 1; n--) {
  64. // for (int n = 0; n < nmax_; n++) {
  65. const int n1 = n;
  66. // Equation (27)
  67. Qext_ += (n1 + n1 + 1.0) * (an_[n].real() + bn_[n].real());
  68. // std::cout << n1 << ": " << Qext_ << " ";
  69. // Equation (28)
  70. Qsca_ += (n1 + n1 + 1.0) *
  71. (an_[n].real() * an_[n].real() + an_[n].imag() * an_[n].imag() +
  72. bn_[n].real() * bn_[n].real() + bn_[n].imag() * bn_[n].imag());
  73. }
  74. Qext_ *= 2 / pow2(x_);
  75. Qsca_ *= 2 / pow2(x_);
  76. }
  77. //******************************************************************************
  78. template <typename FloatType>
  79. void MesoMie<FloatType>::calc_ab(FloatType R,
  80. FloatType xd,
  81. std::complex<FloatType> xm,
  82. std::complex<FloatType> eps_d,
  83. std::complex<FloatType> eps_m,
  84. std::complex<FloatType> d_parallel,
  85. std::complex<FloatType> d_perp) {
  86. x_ = xd;
  87. // std::cout << "xd: " << xd << " R: " << R << std::endl;
  88. double xx = static_cast<double>(x_);
  89. int nmax = std::round(xx + 11 * std::pow(xx, (1.0 / 3.0)) + 1);
  90. an_.resize(nmax + 1, static_cast<FloatType>(0.0));
  91. bn_.resize(nmax + 1, static_cast<FloatType>(0.0));
  92. std::vector<std::complex<FloatType>> //
  93. D1_xd(nmax + 1), D3_xd(nmax + 1), //
  94. D1_xm(nmax + 1), D3_xm(nmax + 1), //
  95. Psi_xd(nmax + 1), Zeta_xd(nmax + 1), //
  96. Psi_xm(nmax + 1), Zeta_xm(nmax + 1);
  97. evalPsiZetaD1D3(std::complex<FloatType>(xd), Psi_xd, Zeta_xd, D1_xd, D3_xd);
  98. evalPsiZetaD1D3(std::complex<FloatType>(xm), Psi_xm, Zeta_xm, D1_xm, D3_xm);
  99. for (int n = 0; n <= nmax; n++) {
  100. an_[n] = Psi_xd[n] *
  101. ( //
  102. eps_m * xd * D1_xd[n] - eps_d * xm * D1_xm[n] + //
  103. ( //
  104. (eps_m - eps_d) * //
  105. ( //
  106. static_cast<FloatType>(n * (n + 1)) * d_perp + //
  107. xd * D1_xd[n] * xm * D1_xm[n] * d_parallel //
  108. ) / //
  109. R //
  110. ) //
  111. ) / //
  112. ( //
  113. Zeta_xd[n] * //
  114. ( //
  115. eps_m * xd * D3_xd[n] - eps_d * xm * D1_xm[n] + //
  116. ( //
  117. (eps_m - eps_d) * //
  118. ( //
  119. static_cast<FloatType>(n * (n + 1)) * d_perp + //
  120. xd * D3_xd[n] * xm * D1_xm[n] * d_parallel //
  121. ) / //
  122. R //
  123. ) //
  124. ) //
  125. );
  126. bn_[n] = Psi_xd[n] *
  127. ( //
  128. xd * D1_xd[n] - xm * D1_xm[n] + //
  129. ((xm * xm - xd * xd) * d_parallel / R) //
  130. ) / //
  131. ( //
  132. Zeta_xd[n] * ( //
  133. xd * D3_xd[n] - xm * D1_xm[n] + //
  134. ((xm * xm - xd * xd) * d_parallel / R) //
  135. ) //
  136. ); //
  137. }
  138. }
  139. } // namespace nmie
  140. #endif