1 #include <boost/math/constants/constants.hpp>
4 #include "library/laplace_3d.hpp"
5 #include "../library/lib_element.hpp"
6 #include "../interface/read_off_mesh.hpp"
10 typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>
dMatrix;
11 typedef Eigen::Matrix<unsigned, Eigen::Dynamic, Eigen::Dynamic> uMatrix;
13 template <
class TestSpace,
class TrialSpace>
14 static double tester(TestSpace
const &test_space, TrialSpace
const &trial_space)
16 using namespace boost::math::double_constants;
23 size_t N = test_space.get_num_dofs();
38 auto const &mesh = trial_space.get_mesh();
39 for (
unsigned k = 0; k < N; ++k)
41 auto const &elem = mesh.template get_elem<NiHu::tria_1_elem>(k);
42 auto y = elem.get_center();
43 auto ny = elem.get_normal().normalized();
44 for (
int s = 0; s < x0.cols(); ++s)
46 auto rvec = y - x0.col(s);
47 double r = rvec.norm();
48 double rdn = rvec.dot(ny) / r;
49 p0(k) += A(s) * 1./r/(4.0 * pi);
50 q0(k) += A(s) * -(1./r/r) * rdn /(4.0 * pi);
55 dMatrix L(N, N), M(N, N), I(N,N);
56 L.setZero(); M.setZero(); I.setZero();
58 I << test_space * I_op[trial_space];
59 L << test_space * L_op[trial_space];
60 M << test_space * M_op[trial_space];
62 std::cout << I.block(0, 0, 5, 5) << std::endl << std::endl;
63 std::cout << L.block(0, 0, 5, 5) << std::endl << std::endl;
64 std::cout << M.block(0, 0, 5, 5) << std::endl << std::endl;
66 dMatrix p = (M - .5 * I).colPivHouseholderQr().solve(L * q0);
68 return (p-p0).norm() / p0.norm();
71 int main(
int argc,
char *argv[])
75 std::cerr <<
"Usage: " << argv[0] <<
" OFFname" << std::endl;
83 std::cout <<
"Collocation" << std::endl;
84 double coll_error = tester(NiHu::dirac(trial_space), trial_space);
85 std::cout << coll_error << std::endl;
87 std::cout <<
"Galerkin" << std::endl;
88 double gal_error = tester(trial_space, trial_space);
89 std::cout << gal_error << std::endl;