1 #include <boost/math/constants/constants.hpp>
4 #include "library/laplace_2d.hpp"
5 #include "../library/lib_element.hpp"
9 typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>
dMatrix;
10 typedef Eigen::Matrix<unsigned, Eigen::Dynamic, Eigen::Dynamic> uMatrix;
15 using namespace boost::math::double_constants;
18 uMatrix elements(N, 3);
19 for (
int i = 0; i < N; ++i)
21 double phi = i*two_pi/N;
22 nodes(i,0) = r * cos(phi);
23 nodes(i,1) = r * sin(phi);
24 elements(i,0) = NiHu::line_1_elem::id;
25 elements(i,1) = i % N;
26 elements(i,2) = (i+1) % N;
31 template <
class TestSpace,
class TrialSpace>
32 static void tester(TestSpace
const &test_space, TrialSpace
const &trial_space)
34 using namespace boost::math::double_constants;
43 size_t N = test_space.get_num_dofs();
57 auto const &mesh = trial_space.get_mesh();
58 for (
unsigned k = 0; k < N; ++k)
60 auto const &elem = mesh.template get_elem<NiHu::line_1_elem>(k);
61 auto y = elem.get_center();
62 auto ny = elem.get_normal().normalized();
63 for (
int s = 0; s < x0.cols(); ++s)
65 auto rvec = y - x0.col(s);
66 double r = rvec.norm();
67 double rdn = rvec.dot(ny) / r;
68 p0(k) += A(s) * -std::log(r) / two_pi;
69 q0(k) += A(s) * -(1.0/r) * rdn / two_pi;
73 std::cout <<
"Matrix generation" << std::endl;
75 dMatrix G(N, N),
H(N, N), Ht(N, N), D(N, N), I(N,N);
82 I << test_space * I_op[trial_space];
83 G << test_space * G_op[trial_space];
84 H << test_space * H_op[trial_space];
85 Ht << test_space * Ht_op[trial_space];
86 D << test_space * D_op[trial_space];
89 std::cout <<
" Solution with direct Neumann:" << std::endl;
90 dMatrix p_direct_neumann = (
H - .5 * I).colPivHouseholderQr().solve(G * q0);
91 double error_direct_neumann = (p_direct_neumann-p0).norm() / p0.norm();
92 std::cout <<
"Direct Neumann Error: " << error_direct_neumann << std::endl;
95 std::cout <<
" Solution with direct Dirichlet:" << std::endl;
96 dMatrix q_direct_dirichlet = G.colPivHouseholderQr().solve((
H - .5 * I) * p0);
97 double error_direct_dirichlet = (q_direct_dirichlet-q0).norm() / q0.norm();
98 std::cout <<
"Direct Dirichlet Error: " << error_direct_dirichlet << std::endl;
108 std::cout <<
"Collocation" << std::endl;
109 tester(NiHu::dirac(trial_space), trial_space);
111 std::cout <<
"Galerkin" << std::endl;
112 tester(trial_space, trial_space);