%---------------------------------------------------------
% E_BEM_MODEL.M
% building the openFEM computer model
% Fiala Peter
% 2008 BME, Laboratory of Acoustics
%---------------------------------------------------------
clear all;
close all;
clc;
%% Loading necessary parameters
load data/boxmesh
%% Transformation to BEM mesh and normal displacements
[bembox, T] = Free2srf(SDT2Free(box), freeDOF);
bembox.bases = [0 0 -0.01];
bembox.normals = [0 0 1];
exportsrf(bembox, 'data/bembox.srf');
%% Acoustic sensitivity matrix
load data/solution omvec
freq = 300;
[res, n] = min(abs(omvec-2*pi*freq));
freq = omvec(n)/2/pi;
system(['AcouBEM -ms ' num2str(round(freq)) ' data/bembox.srf OUT data/surface_' num2str(round(freq)) '.mtx']);
sys = import_acouBEM_system(['data/surface_' num2str(round(freq)) '.mtx']);
%% Boundary condition
load data/solution alpha
load data/boxmodes phi
u = phi * alpha(:,n);
v = i*2*pi*freq*u;
psurf = sys.A\(sys.B*(T*v));
%% Plot the surafce pressure
plot_free_model(SDT2Free(box), freeDOF, v, 1:length(psurf), abs(psurf), 1)
axis equal;
axis tight;
xlabel('x [m]');
ylabel('y [m]');
zlabel('z [m]');
view(15, 25);