NiHu  2.0
helmholtz_ibem_3d_test.m
1 %// sphere radiator with radius R = 1, divided into 6 elements along the radius.
2 radiator = quad2tria(create_sphere_boundary(1, 5));
3 %// field point mesh, a line revolved around the z axis
4 field = revolve_mesh(create_line([1.125, 0, 0; 3.625, 0, 0], 40), pi/100, 50, [0 0 1]);
5 
6 %// extract the mesh description matrices
7 [r_nodes, r_elem] = extract_core_mesh(radiator);
8 [f_nodes, f_elem] = extract_core_mesh(field);
9 
10 %// call C++ code at wave number k = 0
11 k = 4;
12 [Ms, Mf] = helmholtz_bem_indirect_dirichlet(r_nodes, r_elem, f_nodes, f_elem, k);
13 
14 %// define the incident velocity field and analytical solutions
15 x0 = [.4 .3 0];
16 [r_cent, r_norm] = centnorm(radiator);
17 [ps_ana, qs_ana] = incident('point', x0, r_cent, r_norm, k);
18 
19 %// analytical solution on the field
20 f_cent = centnorm(field);
21 pf_ana = incident('point', x0, f_cent, [], k);
22 
23 %// acoustic pressure on the surface and in the field points
24 sigma_inf = Ms \ ps_ana;
25 pf_num = Mf * sigma_inf;
26 
27 % // calculate errors
28 pf_err = abs(pf_num./pf_ana - 1);
29 
30 % // plot results
31 figure;
32 subplot(1,2,1);
33 plot_mesh(field, real(pf_num)); view(2); shading flat;
34 c1 = colorbar('SouthOutside');
35 xlabel(c1, 'Real part of numerical solution');
36 subplot(1,2,2);
37 plot_mesh(field, log10(pf_err)); view(2); shading flat;
38 c1 = colorbar('SouthOutside');
39 xlabel(c1, 'Log10 error');
40 
41 %// display error information
42 fprintf('Field log10 error: %f \n', log10(mean(pf_err)));