NiHu  2.0
unit_sphere.cpp
Go to the documentation of this file.
1 
7 #include "unit_sphere.h"
8 
9 #include <boost/math/constants/constants.hpp>
10 #include <boost/math/special_functions/spherical_harmonic.hpp>
11 
13 
14 namespace NiHu
15 {
16 namespace fmm
17 {
18 
19 unit_sphere::unit_sphere(size_t P)
20  : m_P(P)
21 {
22  using namespace boost::math::double_constants;
23  auto res = NiHu::gauss_impl<double>(unsigned(m_P));
24  auto const &xi = res.col(0);
25  this->wtheta = res.col(1);
26 
27  // number of quadrature points
28  size_t N = 2 * m_P*m_P;
29  s.resize(3, N);
30  w.resize(N, 1);
31 
32  theta = acos(xi.array());
33  phi.resize(2 * m_P);
34 
35  for (size_t i = 0; i < 2 * m_P; ++i)
36  {
37  phi(i) = i * pi / m_P;
38  s.block(0, i*m_P, 1, m_P) = std::cos(phi(i)) * sin(theta.array().transpose());
39  s.block(1, i*m_P, 1, m_P) = std::sin(phi(i)) * sin(theta.array().transpose());
40  s.block(2, i*m_P, 1, m_P) = xi.transpose();
41  w.segment(i*m_P, m_P) = this->wtheta * pi / m_P;
42  }
43 }
44 
45 unit_sphere::cmatrix_t unit_sphere::spht(cvector_t const &f, int L) const
46 {
47  using boost::math::spherical_harmonic;
48  Eigen::Matrix<std::complex<double>, Eigen::Dynamic, Eigen::Dynamic> Flm(L + 1, 2 * L + 1);
49  Flm.setZero();
50  for (int l = 0; l <= L; ++l)
51  for (int m = -l; m <= l; ++m)
52  for (int k = 0; k < s.cols(); ++k) // integration loop
53  Flm(l, m + L) +=
54  conj(spherical_harmonic(l, m, theta(k%m_P), phi(k / m_P)))
55  * f(k) * w(k);
56  return Flm;
57 }
58 
59 unit_sphere::cvector_t unit_sphere::ispht(cmatrix_t const &Flm) const
60 {
61  using boost::math::spherical_harmonic;
62  Eigen::Matrix<std::complex<double>, Eigen::Dynamic, 1> f(s.cols(), 1);
63  f.setZero();
64  int L = int(Flm.rows() - 1);
65  for (int l = 0; l <= L; ++l)
66  for (int m = -l; m <= l; ++m)
67  for (int k = 0; k < s.cols(); ++k) // integration loop
68  f(k) += Flm(l, m + L)
69  * spherical_harmonic(l, m, theta(k%m_P), phi(k / m_P));
70  return f;
71 }
72 
73 } // namespace fmm
74 } // namespace NiHu
gaussian_quadrature.hpp
implementation of Gaussian quadratures
unit_sphere.h
Interface of class NiHu::fmm::unit_sphere.
NiHu::fmm::unit_sphere::spht
cmatrix_t spht(cvector_t const &f, int L) const
perform spherical transform
Definition: unit_sphere.cpp:45
NiHu::fmm::unit_sphere::ispht
cvector_t ispht(cmatrix_t const &Flm) const
perform inverse spherical transform
Definition: unit_sphere.cpp:59