NiHu  2.0
laplace_2d_fmm.cpp
Go to the documentation of this file.
1 
7 #include "laplace_2d_fmm.hpp"
8 
9 #include <boost/math/special_functions/binomial.hpp>
10 
11 namespace NiHu
12 {
13 namespace fmm
14 {
15 
16 std::complex<double> laplace_2d_fmm::center2complex(cluster_t const& c)
17 {
18  auto const& x = c.get_bounding_box().get_center();
19  return std::complex<double>(x(0), x(1));
20 }
21 
22 laplace_2d_fmm::m2m
24 {
25  return m2m();
26 }
27 
30 {
31  return l2l();
32 }
33 
36 {
37  return m2l();
38 }
39 
41 {
42  m_expansion_length = L;
43 }
44 
46 {
47  return m_expansion_length;
48 }
49 
51 {
52  return multipole_t::Zero(m_expansion_length + 1, 1);
53 }
54 
56 {
57  return local_t::Zero(m_expansion_length + 1, 1);
58 }
59 
60 laplace_2d_fmm::m2l::result_t
61 laplace_2d_fmm::m2l::operator()(cluster_t to, cluster_t from) const
62 {
63  std::complex<double> z0 = center2complex(from) - center2complex(to);
64  result_t res(to.get_expansion_length() + 1, from.get_expansion_length() + 1);
65  res(0, 0) = std::log(-z0);
66  for (size_t k = 1; k <= from.get_expansion_length(); ++k)
67  res(0, k) = 1. / std::pow(-z0, k);
68  for (size_t l = 1; l <= to.get_expansion_length(); ++l)
69  {
70  res(l, 0) = -1. / l / std::pow(z0, l);
71  for (size_t k = 1; k <= from.get_expansion_length(); ++k)
72  res(l, k) = 1. / std::pow(z0, l + k) * std::pow(-1, k)
73  * boost::math::binomial_coefficient<double>(unsigned(k + l - 1), unsigned(k - 1));
74  }
75  return res;
76 }
77 
78 laplace_2d_fmm::m2m::result_t
79 laplace_2d_fmm::m2m::operator()(cluster_t to, cluster_t from) const
80 {
81  std::complex<double> z0 = center2complex(from) - center2complex(to);
82 
83  result_t res = result_t::Zero(to.get_expansion_length() + 1, from.get_expansion_length() + 1);
84  res(0, 0) = 1;
85  for (size_t l = 1; l <= to.get_expansion_length(); ++l)
86  {
87  res(l, 0) = -std::pow(z0, l) / double(l);
88  for (size_t k = 1; k <= l; ++k)
89  res(l, k) = std::pow(z0, l - k)
90  * boost::math::binomial_coefficient<double>(unsigned(l - 1), unsigned(k - 1));
91  }
92  return res;
93 }
94 
95 laplace_2d_fmm::l2l::result_t
96 laplace_2d_fmm::l2l::operator()(cluster_t to, cluster_t from) const
97 {
98  std::complex<double> z0 = center2complex(from) - center2complex(to);
99  result_t res = result_t::Zero(to.get_expansion_length() + 1, from.get_expansion_length() + 1);
100  for (size_t l = 0; l <= to.get_expansion_length(); ++l)
101  {
102  for (size_t k = l; k <= from.get_expansion_length(); ++k)
103  res(l, k) = boost::math::binomial_coefficient<double>(unsigned(k), unsigned(l))
104  * std::pow(-z0, k - l);
105  }
106  return res;
107 }
108 
109 } // end of namespace fmm
110 } // namespace NiHu
NiHu::fmm::laplace_2d_fmm::create_m2l
m2l create_m2l() const
return an instance of the M2L operator
Definition: laplace_2d_fmm.cpp:35
NiHu::fmm::chebyshev_cluster
Cluster class of the Black Box FMM.
Definition: chebyshev_cluster.hpp:28
NiHu::fmm::laplace_2d_fmm::m2l
M2L operator of the Laplace 2D FMM.
Definition: laplace_2d_fmm.hpp:360
NiHu::fmm::laplace_2d_cluster::set_expansion_length
void set_expansion_length(size_t L)
set the expansion length
Definition: laplace_2d_fmm.cpp:40
NiHu::fmm::laplace_2d_fmm::create_l2l
l2l create_l2l() const
return an instance of the L2L operator
Definition: laplace_2d_fmm.cpp:29
NiHu::fmm::laplace_2d_fmm::create_m2m
m2m create_m2m() const
return an instance of the M2M operator
Definition: laplace_2d_fmm.cpp:23
NiHu::fmm::laplace_2d_cluster::zero_local
local_t zero_local() const
return a cleared local contribution
Definition: laplace_2d_fmm.cpp:55
NiHu::fmm::laplace_2d_cluster::zero_multipole
multipole_t zero_multipole() const
return a cleared multipole contribution
Definition: laplace_2d_fmm.cpp:50
NiHu::fmm::laplace_2d_cluster::multipole_t
base_t::multipole_t multipole_t
the multipole type
Definition: laplace_2d_fmm.hpp:49
NiHu::fmm::laplace_2d_cluster::get_expansion_length
size_t get_expansion_length() const
get the expansion length
Definition: laplace_2d_fmm.cpp:45
NiHu::fmm::laplace_2d_cluster::local_t
base_t::local_t local_t
the local type
Definition: laplace_2d_fmm.hpp:51
NiHu::fmm::laplace_2d_fmm::l2l
L2L operator of the Laplace 2D FMM.
Definition: laplace_2d_fmm.hpp:347
NiHu::fmm::laplace_2d_fmm::m2m
M2M operator of the Laplace 2D FMM.
Definition: laplace_2d_fmm.hpp:334
laplace_2d_fmm.hpp
FMM method for the 2D Laplace equation.