nmie-applied.h 8.4 KB

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