NiHu  2.0
helmholtz_bem_3d_matrices_gauss_test.m
1 clear;
2 
3 %% Create surface mesh
4 
5 R = 1;
6 % M = 5;
7 % L = [2 2 2];
8 % M = [6 6 6];
9 Le = 1e-1;
10 mesh = create_radiatterer(Le);
11 % mesh = create_brick_boundary(L, M);
12 nElem = size(mesh.Elements,1);
13 
14 %% Create field point mesh
15 [xc, nc] = geo2gauss(mesh, 2);
16 
17 eps = 1e-3;
18 
19 field = create_empty_mesh();
20 Nf = size(xc,1);
21 field.Nodes = [(1 : Nf)' xc + eps * nc];
22 field.Elements(1:Nf,1) = 1:Nf;
23 field.Elements(:,2) = ShapeSet.LinearQuad.Id;
24 field.Elements(:,3) = 1;
25 field.Elements(:,4) = 1;
26 field.Elements(:,5:8) = repmat(field.Nodes(:,1), 1, 4);
27 
28 f = 20;
29 c = 340;
30 k = 2*pi*f/c;
31 
32 kmax = min(mesh_kmax(mesh));
33 % k = .6 * kmax;
34 
35 %% Compute BEM matrices
36 [surf_nodes, surf_elements] = extract_core_mesh(mesh);
37 [field_nodes, field_elements] = extract_core_mesh(field);
38 
39 [G, H, Ht, D, Gf, Hf] = helmholtz_bem_3d_matrices_gauss(...
40  surf_nodes, surf_elements, field_nodes, field_elements, k);
41 
42 %% Compute pressure
43 % x0 = [1 1 1];
44 % [p0, q0] = incident('point', x0, xc, nc, k);
45 q0 = ones(4*nElem,1);
46 
47 I = eye(size(H));
48 
49 %% Solve regular
50 rhs = G * q0;
51 A = H - .5 * I;
52 ps = gmres(A, rhs, 100, 1e-4, 100);
53 
54 figure;
55 plot_mesh(mesh, abs(mean(reshape(ps, 4, []), 1)'));
56 shading flat;
57 colorbar;
58 axis equal;
59 title('Regular');
60 
61 %% Solve BM
62 alpha = 1i/k;
63 rhs = ((G + alpha * (Ht + .5 * I)) * q0);
64 A = ((H - .5 * I) + alpha * D);
65 ps_bm = gmres(A, rhs, 100, 1e-4, 100);
66 
67 figure;
68 plot_mesh(mesh, abs(mean(reshape(ps_bm, 4, []), 1)'));
69 shading flat;
70 colorbar;
71 axis equal;
72 title('Burton-Miller');
73 
74 %% Solve approx BM
75 Ht_appr = (Gf - G) / eps;
76 D_appr = (Hf - H) / eps;
77 for e = 1 : nElem
78  idx = (e-1)*4+(1:4);
79  Ht_appr(idx,idx) = Ht(idx,idx);
80  D_appr(idx,idx) = D(idx,idx);
81 end
82 
83 rhs = ((G + alpha * (Ht_appr + .5 * I)) * q0);
84 A = ((H - .5 * I) + alpha * D_appr);
85 ps_bm_appr = gmres(A, rhs, 100, 1e-4, 100);
86 
87 figure;
88 plot_mesh(mesh, abs(mean(reshape(ps_bm_appr, 4, []), 1)'));
89 shading flat;
90 colorbar;
91 axis equal;
92 title('Burton-Miller approx');
93 
94 %% Solve derivative
95 rhs = (Ht + .5 * I) * q0;
96 A = D;
97 ps_2 = gmres(A, rhs, 100, 1e-4, 100);
98 
99 figure;
100 plot_mesh(mesh, abs(mean(reshape(ps_2, 4, []), 1)'));
101 shading flat;
102 colorbar;
103 axis equal;
104 title('Derivative');
105 
106 
NiHu::bessel::H
make_complex< T >::type H(T const &z)
H^(K)_nu(z) Bessel function.
Definition: math_functions.hpp:365