py_nmie.cc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //**********************************************************************************//
  2. // Copyright (C) 2009-2015 Ovidio Pena <ovidio@bytesfall.com> //
  3. // //
  4. // This file is part of scattnlay //
  5. // //
  6. // This program is free software: you can redistribute it and/or modify //
  7. // it under the terms of the GNU General Public License as published by //
  8. // the Free Software Foundation, either version 3 of the License, or //
  9. // (at your option) any later version. //
  10. // //
  11. // This program is distributed in the hope that it will be useful, //
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of //
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
  14. // GNU General Public License for more details. //
  15. // //
  16. // The only additional remark is that we expect that all publications //
  17. // describing work using this software, or all commercial products //
  18. // using it, cite the following reference: //
  19. // [1] O. Pena and U. Pal, "Scattering of electromagnetic radiation by //
  20. // a multilayered sphere," Computer Physics Communications, //
  21. // vol. 180, Nov. 2009, pp. 2348-2354. //
  22. // //
  23. // You should have received a copy of the GNU General Public License //
  24. // along with this program. If not, see <http://www.gnu.org/licenses/>. //
  25. //**********************************************************************************//
  26. #include <math.h>
  27. #include <stdlib.h>
  28. #include <stdio.h>
  29. #include "nmie.h"
  30. #include "py_nmie.h"
  31. // Same as nMie in 'nmie.h' but uses double arrays to return the results (useful for python).
  32. // This is a workaround because I have not been able to return the results using
  33. // std::vector<std::complex<double> >
  34. int nMie(int L, int pl, std::vector<double> x, std::vector<std::complex<double> > m,
  35. int nTheta, std::vector<double> Theta, int nmax,
  36. double *Qext, double *Qsca, double *Qabs, double *Qbk, double *Qpr, double *g, double *Albedo,
  37. double S1r[], double S1i[], double S2r[], double S2i[]) {
  38. int i, result;
  39. std::vector<std::complex<double> > S1, S2;
  40. S1.resize(nTheta);
  41. S2.resize(nTheta);
  42. result = nMie(L, pl, x, m, nTheta, Theta, nmax, Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo, S1, S2);
  43. for (i = 0; i < nTheta; i++) {
  44. S1r[i] = S1[i].real();
  45. S1i[i] = S1[i].imag();
  46. S2r[i] = S2[i].real();
  47. S2i[i] = S2[i].imag();
  48. }
  49. return result;
  50. }
  51. // Same as nField in 'nmie.h' but uses double arrays to return the results (useful for python).
  52. // This is a workaround because I have not been able to return the results using
  53. // std::vector<std::complex<double> >
  54. int nField(int L, int pl, std::vector<double> x, std::vector<std::complex<double> > m, int nmax,
  55. int nCoords, std::vector<double> Xp, std::vector<double> Yp, std::vector<double> Zp,
  56. double Er[], double Ei[], double Hr[], double Hi[]) {
  57. int i, result;
  58. std::vector<std::complex<double> > E, H;
  59. E.resize(nCoords);
  60. H.resize(nCoords);
  61. result = nField(L, pl, x, m, nmax, nCoords, Xp, Yp, Zp, E, H);
  62. for (i = 0; i < nCoords; i++) {
  63. Er[i] = E[i].real();
  64. Ei[i] = E[i].imag();
  65. Hr[i] = H[i].real();
  66. Hi[i] = H[i].imag();
  67. }
  68. return result;
  69. }