nmie-wrapper.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #ifNdef SRC_NMIE_NMIE_WRAPPER_H_
  2. #define SRC_NMIE_NMIE_WRAPPER_H_
  3. ///
  4. /// @file nmie-wrapper.h
  5. /// @author Ladutenko Konstantin <kostyfisik at gmail (.) com>
  6. /// @date Tue Sep 3 00:40:47 2013
  7. /// @copyright 2013 Ladutenko Konstantin
  8. ///
  9. /// nmie-wrapper 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. /// nmie-wrapper 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. /// You should have received a copy of the GNU General Public License
  20. /// along with nmie-wrapper. If not, see <http://www.gnu.org/licenses/>.
  21. ///
  22. /// nmie-wrapper uses nmie.c from scattnlay by Ovidio Pena
  23. /// <ovidio@bytesfall.com> as a linked library. He has an additional condition to
  24. /// his library:
  25. // The only additional condition is that we expect that all publications //
  26. // describing work using this software , or all commercial products //
  27. // using it, cite the following reference: //
  28. // [1] O. Pena and U. Pal, "Scattering of electromagnetic radiation by //
  29. // a multilayered sphere," Computer Physics Communications, //
  30. // vol. 180, Nov. 2009, pp. 2348-2354. //
  31. ///
  32. /// @brief Wrapper class around nMie function for ease of use
  33. ///
  34. ///
  35. #include <complex>
  36. #include <cstdlib>
  37. #include <iostream>
  38. #include <vector>
  39. #ifndef NDEBUG
  40. # define ASSERT(condition, message) \
  41. do { \
  42. if (! (condition)) { \
  43. std::cerr << "Assertion `" #condition "` failed in " << __FILE__ \
  44. << " line " << __LINE__ << ": " << message << std::endl; \
  45. std::exit(EXIT_FAILURE); \
  46. } \
  47. } while (false)
  48. #else
  49. # define ASSERT(condition, message) do { } while (false)
  50. #endif
  51. namespace nmie {
  52. class MultiLayerMie {
  53. // Will throw for any error!
  54. public:
  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 SetCoatingWidth(std::vector<double> width);
  66. void SetCoatingIndex(std::vector< std::complex<double> > index);
  67. void SetFieldPoints(std::vector< std::vector<double> > coords);
  68. //Set parameters in size parameter units
  69. void SetWidthSP(std::vector<double> width);
  70. void SetIndexSP(std::vector< std::complex<double> > index);
  71. void SetFieldPointsSP(std::vector< std::vector<double> > coords);
  72. // Set common parameters
  73. void SetAnglesForPattern(double from_angle, double to_angle, int samples);
  74. std::vector<double> GetAngles();
  75. void ClearTarget();
  76. void ClearCoating();
  77. void ClearLayers();
  78. // Applied units requests
  79. double GetTotalRadius();
  80. double GetTargetRadius();
  81. double GetCoatingWidth();
  82. std::vector<double> GetTargetLayersWidth();
  83. std::vector< std::complex<double> > GetTargetLayersIndex();
  84. std::vector<double> GetCoatingLayersWidth();
  85. std::vector< std::complex<double> > GetCoatingLayersIndex();
  86. std::vector< std::vector<double> > GetFieldPoints();
  87. std::vector<std::vector<std::complex<double> > > GetFieldE();
  88. std::vector<std::vector<std::complex<double> > > GetFieldH();
  89. std::vector< std::vector<double> > GetSpectra(double from_WL, double to_WL,
  90. int samples);
  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::vector<double> > 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::vector<double> > GetSpectraSP(double from_SP, double to_SP,
  107. int samples);
  108. double GetQext();
  109. double GetQsca();
  110. double GetQabs();
  111. double GetQbk();
  112. double GetQpr();
  113. double GetAsymmetryFactor();
  114. double GetAlbedo();
  115. std::vector<std::complex<double> > GetS1();
  116. std::vector<std::complex<double> > GetS2();
  117. std::vector<double> GetPatternEkSP();
  118. std::vector<double> GetPatternHkSP();
  119. std::vector<double> GetPatternUnpolarizedSP();
  120. void RunMieCalculations();
  121. void RunFieldCalculations();
  122. private:
  123. const double PI=3.14159265358979323846;
  124. void GenerateSizeParameter();
  125. void GenerateIndex();
  126. double wavelength_ = 1.0;
  127. double total_radius_ = 0.0;
  128. /// Width and index for each layer of the structure
  129. std::vector<double> target_width_, coating_width_;
  130. std::vector< std::complex<double> > target_index_, coating_index_;
  131. /// Size parameters for all layers
  132. std::vector<double> size_parameter_;
  133. /// Complex index values for each layers.
  134. std::vector< std::complex<double> > index_;
  135. }; // end of class MultiLayerMie
  136. } // end of namespace nmie
  137. #endif // SRC_NMIE_NMIE_WRAPPER_H_