NiHu  2.0
helmholtz_bem_2d_cyl_test.m
1 %// create meshes
2 R0 = 1; %// radius of the cylinder
3 R1 = 2; %// radius of the field point mesh
4 N = 200; %// number of boundary elements on the cylinder
5 dir = [1 0 0]; %// direction of the incident plane wave
6 
7 radiator = create_circle_boundary(R0, N);
8 field_mesh = create_circle_boundary(R1, N);
9 
10 kmax = min(mesh_kmax(radiator));
11 k = .5 * kmax;
12 
13 %// system matrices
14 [r_nodes, r_elements] = extract_core_mesh(radiator);
15 [f_nodes, f_elements] = extract_core_mesh(field_mesh);
16 [Ls, Ms, Lf, Mf] = helmholtz_bem_2d_cyl(...
17  r_nodes, r_elements, f_nodes, f_elements, k);
18 
19 %// Numerical solution
20 [xs, ns] = centnorm(radiator); %// center and normal of the cylinder elements
21 [pinc_s, qinc_s] = incident('plane', dir, xs, ns, k); %// incident wave field
22 
23 qref_s = -qinc_s; %// reflected velocity field
24 pref_s = Ms \ (Ls * qref_s); %// solution of the BEM problem
25 ptot_s = pinc_s + pref_s; %// total pressure field
26 
27 [xf, nf] = centnorm(field_mesh);%// center and normal of the field elements
28 pinc_f = incident('plane', dir, xf, [], k); %// incident wave field
29 
30 pref_f = Mf * pref_s - Lf * qref_s; %// radiated pressure to field points
31 ptot_f = pinc_f + pref_f; %// total pressure in field points
32 
33 %// Analytical solution
34 pref_f_anal = planewave_cyl2d(xf, R0, k, 100);
35 ptot_f_anal = pinc_f + pref_f_anal;
36 
37 plot(atan2(xf(:,2), xf(:,1)), abs(ptot_f), '.-', ...
38  atan2(xf(:,2), xf(:,1)), abs(ptot_f_anal), '.-');
39 xlabel('angle [rad]');
40 ylabel('scattered field');
41 legend('NiHu', 'Analytic');
42 
43 error = log10(mean(abs(ptot_f./ptot_f_anal-1)));
44 fprintf(1, 'Log10 mean error: %f\n', error);