nmie-applied.hpp 8.4 KB

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