pb11_wrapper.cc 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include <string>
  2. #include "nmie-pybind11.hpp"
  3. #include "nmie.hpp"
  4. #include "nmie-basic.hpp"
  5. //py::class_<Pet>(m, "Pet")
  6. //.def(py::init<const std::string &, int>())
  7. //.def("set", static_cast<void (Pet::*)(int)>(&Pet::set), "Set the pet's age")
  8. //.def("set", static_cast<void (Pet::*)(const std::string &)>(&Pet::set), "Set the pet's name");
  9. //
  10. template<typename T>
  11. void declare_nmie(py::module &m, std::string &typestr) {
  12. using mie_typed = nmie::MultiLayerMie<nmie::FloatType>;
  13. std::string pyclass_name = std::string("mie") + typestr;
  14. py::class_<mie_typed>(m, pyclass_name.c_str(), py::buffer_protocol(), py::dynamic_attr())
  15. .def(py::init<>())
  16. .def("GetPECLayer", &mie_typed::GetPECLayer)
  17. .def("SetPECLayer", &mie_typed::SetPECLayer)
  18. .def("SetMaxTerms", &mie_typed::SetMaxTerms)
  19. .def("GetMaxTerms", &mie_typed::GetMaxTerms)
  20. .def("SetModeNmaxAndType", &mie_typed::SetModeNmaxAndType)
  21. .def("RunMieCalculation", &mie_typed::RunMieCalculation)
  22. .def("SetLayersSize", static_cast<
  23. void (mie_typed::*)
  24. (const py::array_t<double, py::array::c_style | py::array::forcecast>&)>
  25. (&mie_typed::SetLayersSize)
  26. )
  27. .def("SetLayersIndex", static_cast<
  28. void (mie_typed::*)
  29. (const py::array_t<std::complex<double>, py::array::c_style | py::array::forcecast> &)>
  30. (&mie_typed::SetLayersIndex)
  31. )
  32. .def("SetAngles", static_cast<
  33. void (mie_typed::*)
  34. (const py::array_t<double, py::array::c_style | py::array::forcecast>&)>
  35. (&mie_typed::SetAngles)
  36. )
  37. .def("GetQext", &mie_typed::GetQext<double>)
  38. .def("GetQsca", &mie_typed::GetQsca<double>)
  39. .def("GetQabs", &mie_typed::GetQabs<double>)
  40. .def("GetQpr", &mie_typed::GetQpr<double>)
  41. .def("GetQbk", &mie_typed::GetQbk<double>)
  42. .def("GetAsymmetryFactor", &mie_typed::GetAsymmetryFactor<double>)
  43. .def("GetAlbedo", &mie_typed::GetAlbedo<double>)
  44. .def("GetS1", &mie_typed::GetS1<double>)
  45. .def("GetS2", &mie_typed::GetS2<double>)
  46. ;
  47. }
  48. // wrap as Python module
  49. #ifdef MULTI_PRECISION
  50. std::string precision_name = "_mp";
  51. PYBIND11_MODULE(scattnlay_mp, m)
  52. #else
  53. std::string precision_name = "_dp";
  54. PYBIND11_MODULE(scattnlay_dp, m)
  55. #endif // MULTI_PRECISION
  56. {
  57. m.doc() = "The Python version of scattnlay";
  58. declare_nmie<nmie::FloatType>(m, precision_name);
  59. m.def("scattcoeffs", &py_ScattCoeffs,
  60. "Calculate the scattering coefficients, required to calculate both the near- and far-field parameters.",
  61. py::arg("x"), py::arg("m"), py::arg("nmax") = -1, py::arg("pl") = -1);
  62. m.def("expancoeffs", &py_ExpanCoeffs,
  63. "Calculate the expansion coefficients, required to calculate the near-field parameters.",
  64. py::arg("x"), py::arg("m"), py::arg("nmax") = -1, py::arg("pl") = -1);
  65. m.def("fieldnlay", &py_fieldnlay,
  66. "Calculate the complex electric and magnetic field in the surroundings and inside the particle.",
  67. py::arg("x"), py::arg("m"), py::arg("xp"), py::arg("yp"), py::arg("zp"), py::arg("nmax") = -1, py::arg("pl") = -1);
  68. }