1 #include <boost/math/constants/constants.hpp>
5 #include "library/helmholtz_3d.hpp"
10 typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>
dMatrix;
11 typedef Eigen::Matrix<unsigned, Eigen::Dynamic, Eigen::Dynamic> uMatrix;
12 typedef Eigen::Matrix<std::complex<double>, Eigen::Dynamic, Eigen::Dynamic> cMatrix;
14 template <
class TestSpace,
class TrialSpace>
15 static double tester(TestSpace
const &test_space, TrialSpace
const &trial_space)
17 using namespace boost::math::double_constants;
26 size_t N = test_space.get_num_dofs();
29 cMatrix q0(N, 1), p0(N,1);
41 auto const &mesh = trial_space.get_mesh();
42 for (
size_t k = 0; k < N; ++k)
44 auto const &elem = mesh.template get_elem<NiHu::tria_1_elem>(k);
45 auto y = elem.get_center();
46 auto ny = elem.get_normal().normalized();
47 for (
int s = 0; s < x0.cols(); ++s)
49 auto rvec = y - x0.col(s);
50 double r = rvec.norm();
51 std::complex<double> ikr(0., wn*r);
52 double rdn = rvec.dot(ny) / r;
53 p0(k) += A(s) * std::exp(-ikr)/r/(4. * pi);
54 q0(k) += A(s) * -(std::exp(-ikr)/r/r) * rdn /(4. * pi) * (1. + ikr);
59 cMatrix L(N, N), M(N, N), I(N,N);
60 L.setZero(); M.setZero(); I.setZero();
62 I << test_space * I_op[trial_space];
63 L << test_space * L_op[trial_space];
64 M << test_space * M_op[trial_space];
66 std::cout << I.block(0, 0, 5, 5) << std::endl << std::endl;
67 std::cout << L.block(0, 0, 5, 5) << std::endl << std::endl;
68 std::cout << M.block(0, 0, 5, 5) << std::endl << std::endl;
70 cMatrix p = (M - .5 * I).colPivHouseholderQr().solve(L * q0);
72 return (p-p0).norm() / p0.norm();
75 int main(
int argc,
char *argv[])
79 std::cerr <<
"Usage: " << argv[0] <<
" OFFname" << std::endl;
87 std::cout <<
"Collocation" << std::endl;
88 double coll_error = tester(NiHu::dirac(trial_space), trial_space);
89 std::cout << coll_error << std::endl;
91 std::cout <<
"Galerkin" << std::endl;
92 double gal_error = tester(trial_space, trial_space);
93 std::cout << gal_error << std::endl;