nmie-applied.hpp 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. #ifndef SRC_NMIE_APPLIED_HPP_
  2. #define SRC_NMIE_APPLIED_HPP_
  3. //**********************************************************************************//
  4. // Copyright (C) 2009-2018 Ovidio Pena <ovidio@bytesfall.com> //
  5. // Copyright (C) 2013-2018 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. #include <array>
  34. #include <complex>
  35. #include <cstdlib>
  36. #include <iostream>
  37. #include <vector>
  38. #include "nmie.hpp"
  39. #include "nmie-impl.cc"
  40. namespace nmie {
  41. 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);
  42. 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);
  43. 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);
  44. 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);
  45. template <typename FloatType = double>
  46. class MultiLayerMieApplied : public MultiLayerMie<FloatType> {
  47. // Will throw for any error!
  48. public:
  49. void RunMieCalculation();
  50. void GetFailed();
  51. long iformat = 0;
  52. bool output = true;
  53. void prn(FloatType var) {
  54. do {
  55. if (!output) break;
  56. ++iformat;
  57. printf("%23.13e",var);
  58. if (iformat%4 == 0) printf("\n");
  59. } while (false);
  60. }
  61. // Set parameters in applied units
  62. void SetWavelength(FloatType wavelength) {
  63. this->MultiLayerMie<FloatType>::MarkUncalculated();
  64. wavelength_ = wavelength;};
  65. // It is possible to set only a multilayer target to run calculaitons.
  66. // For many runs it can be convenient to separate target and coating layers.
  67. // Per layer
  68. void AddTargetLayer(FloatType layer_width, std::complex<FloatType> layer_index);
  69. void AddTargetLayerReIm(FloatType layer_width,
  70. FloatType re_layer_index, FloatType im_layer_index);
  71. void AddCoatingLayer(FloatType layer_width, std::complex<FloatType> layer_index);
  72. // For all layers
  73. void SetTargetWidth(std::vector<FloatType> width);
  74. void SetTargetIndex(std::vector< std::complex<FloatType> > index);
  75. void SetTargetPEC(FloatType radius);
  76. void SetCoatingWidth(std::vector<FloatType> width);
  77. void SetCoatingIndex(std::vector< std::complex<FloatType> > index);
  78. void SetFieldPoints(std::vector< std::array<FloatType,3> > coords);
  79. //Set parameters in size parameter units
  80. void SetWidthSP(const std::vector<FloatType>& width);
  81. void SetIndexSP(const std::vector< std::complex<FloatType> >& index);
  82. void SetFieldPointsSP(const std::vector< std::vector<FloatType> >& coords_sp);
  83. // Set common parameters
  84. void SetModeNmaxAndType(int mode_n, int mode_type) {
  85. this->MultiLayerMie<FloatType>::SetModeNmaxAndType(mode_n, mode_type);};
  86. void SetAnglesForPattern(FloatType from_angle, FloatType to_angle, int samples);
  87. std::vector<FloatType> GetAngles();
  88. void ClearTarget();
  89. void ClearCoating();
  90. void ClearLayers();
  91. void ClearAllDesign(); //Layers + SP + index_
  92. // Applied units requests
  93. FloatType GetTotalRadius();
  94. FloatType GetTargetRadius();
  95. FloatType GetCoatingWidth();
  96. std::vector<FloatType> GetTargetLayersWidth();
  97. std::vector< std::complex<FloatType> > GetTargetLayersIndex();
  98. std::vector<FloatType> GetCoatingLayersWidth();
  99. std::vector< std::complex<FloatType> > GetCoatingLayersIndex();
  100. std::vector< std::vector<FloatType> > GetFieldPoints();
  101. std::vector< std::vector<FloatType> > GetSpectra(FloatType from_WL, FloatType to_WL, int samples); // ext, sca, abs, bk
  102. FloatType GetRCSext();
  103. FloatType GetRCSsca();
  104. FloatType GetRCSabs();
  105. FloatType GetRCSbk();
  106. std::vector<FloatType> GetPatternEk();
  107. std::vector<FloatType> GetPatternHk();
  108. std::vector<FloatType> GetPatternUnpolarized();
  109. // Dimensionless
  110. FloatType GetQsca(){ return this->MultiLayerMie<FloatType>::GetQsca();};
  111. FloatType GetQabs(){ return this->MultiLayerMie<FloatType>::GetQabs();};
  112. FloatType GetQext(){ return this->MultiLayerMie<FloatType>::GetQext();};
  113. // Size parameter units
  114. std::vector<FloatType> GetLayerWidthSP();
  115. // Same as to get target and coating index
  116. std::vector< std::complex<FloatType> > GetLayerIndex();
  117. std::vector< std::array<FloatType,3> > GetFieldPointsSP();
  118. // Do we need normalize field to size parameter?
  119. /* std::vector<std::vector<std::complex<FloatType> > > GetFieldESP(); */
  120. /* std::vector<std::vector<std::complex<FloatType> > > GetFieldHSP(); */
  121. std::vector< std::array<FloatType,5> > GetSpectraSP(FloatType from_SP, FloatType to_SP, int samples); // WL,ext, sca, abs, bk
  122. std::vector<FloatType> GetPatternEkSP();
  123. std::vector<FloatType> GetPatternHkSP();
  124. std::vector<FloatType> GetPatternUnpolarizedSP();
  125. void GetExpanCoeffs
  126. (std::vector< std::vector<std::complex<FloatType> > >& aln,
  127. std::vector< std::vector<std::complex<FloatType> > >& bln,
  128. std::vector< std::vector<std::complex<FloatType> > >& cln,
  129. std::vector< std::vector<std::complex<FloatType> > >& dln);
  130. // Output results (data file + python script to plot it with matplotlib)
  131. void PlotSpectra();
  132. void PlotSpectraSP();
  133. void PlotField();
  134. void PlotFieldSP();
  135. void PlotPattern();
  136. void PlotPatternSP();
  137. private:
  138. void ConvertToSP();
  139. void GenerateSizeParameter();
  140. void GenerateIndex();
  141. void InitMieCalculations();
  142. void sbesjh(std::complex<FloatType> z, std::vector<std::complex<FloatType> >& jn,
  143. std::vector<std::complex<FloatType> >& jnp, std::vector<std::complex<FloatType> >& h1n,
  144. std::vector<std::complex<FloatType> >& h1np);
  145. void sphericalBessel(std::complex<FloatType> z, std::vector<std::complex<FloatType> >& bj,
  146. std::vector<std::complex<FloatType> >& by, std::vector<std::complex<FloatType> >& bd);
  147. std::complex<FloatType> calcD1confra(int N, const std::complex<FloatType> z);
  148. FloatType wavelength_ = 1.0;
  149. FloatType total_radius_ = 0.0;
  150. /// Width and index for each layer of the structure
  151. std::vector<FloatType> target_width_, coating_width_;
  152. std::vector< std::complex<FloatType> > target_index_, coating_index_;
  153. std::vector< std::vector<FloatType> > coords_sp_;
  154. }; // end of class MultiLayerMie
  155. } // end of namespace nmie
  156. #endif // SRC_NMIE_APPLIED_HPP