Professional Documents
Culture Documents
x = linspace(-1,1,n_panels);
y = x;
z = x;
face = [x(1) x(end)];
n = 1;
area_b = (x(2) - x(1)) ^ 2;
%% Body - cube
% Top and bottom face
for k = 1:length(face)
for i = 1:length(x)
for j = 1:length(y)
pos_b(n,:) = [x(i) y(j) face(k)];
nor_b(n,:) = [0 0 k];
u(n,:) = 0;
n = n+1;
end
end
end
for i = 1:length(face)
for k = 1:length(z)
for j = 1:length(y)
pos_b(n,:) = [face(i) y(j) z(k)];
nor_b(n,:) = [i 0 0];
u(n,:) = i;
n = n+1;
end
end
end
nor_b(nor_b == 1) = 1;
nor_b(nor_b == 2) = -1;
u(u == 1) = -0.015;
u(u == 2) = 0.01;
%% Free surface
x = linspace(-10,10,n_panels);
y = x;
z = x;
face = [x(1) x(end)];
n = 1;
area_sig = (x(2) - x(1)) ^ 2;
for k = 1:length(face)
for i = 1:length(x)
for j = 1:length(y)
pos_sig(n,:) = [x(i) y(j) face(k)];
nor_sig(n,:) = [0 0 k];
% u(n,:) = 0;
n = n+1;
end
end
end
for i = 1:length(face)
for k = 1:length(z)
for j = 1:length(y)
pos_sig(n,:) = [face(i) y(j) z(k)];
nor_sig(n,:) = [i 0 0];
% u(n,:) = i;
n = n+1;
end
end
end
nor_sig(nor_sig == 1) = -1;
nor_sig(nor_sig == 2) = 1;
%% Compute the r and exponent vectors for ALL surface points (b and sig)
s_idx = 1:n_points;
r_idx = s_idx;
r_mat = nan(s_idx(end));
for i = 1:size(s_idx,2)
for j = 1:size(r_idx,2)
r_mat(i,j) = sqrt((pos(i,1)-pos(j,1))^2+(pos(i,2)-pos(j,2))^2 ...
+ (pos(i,3)-pos(j,3))^2);
end
end
k = 2000*pi/1500; % k = sigma/speed_sound
exp_mat = (1j*k*r_mat);
G_mat = exp_mat .* r_mat;
%% LHS - Term 1
source_mat = 2*pi*diag(ones(1,n_points));
term1 = source_mat;
%% LHS - Term 2
count = 0;
for j = n_points_b
for i = 1:n_points
count = count + 1;
if j==i
continue;
end
end
end
sum_dG1 = sum(dG1,2,'omitnan')*area_b;
sum_dG2 = sum(dG2,2,'omitnan')*area_b;
sum_dG3 = sum(dG3,2,'omitnan')*area_b;
dG_b = [sum_dG1 sum_dG2 sum_dG3];
%% LHS - Term 3
%
% dG1 = nan(n_points);
% dG2 = nan(n_points);
% dG3 = nan(n_points);
% dG_sig = nan(n_points,3);
count = 0;
for j = n_points_sig
for i = 1:n_points
count = count + 1;
if j==i
continue;
end
end
end
sum_dG1 = sum(dG1,2,'omitnan')*area_sig;
sum_dG2 = sum(dG2,2,'omitnan')*area_sig;
sum_dG3 = sum(dG3,2,'omitnan')*area_sig;
dG_sig = [sum_dG1 sum_dG2 sum_dG3];
%% LHS - Term 4
for j = 1:size(n_points_sig,2)
for i = n_points
if j == i
continue;
end
ikG(i,j) = 1j * k * G_mat(i,j);
end
end
term4 = ikG;
%% RHS
rho = 1000;
sigma = 2000*pi;
dp_rhs = 1j*rho*sigma*u; %or ones(1,n_points) * uo
G_rhs = G_mat(:,n_points_sig);
term_rhs = G_rhs * dp_rhs * area_b;
p_i = p(b);
disp(n_points) % Display the total number of surface panels in the whole
system
end