-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_sound_soft_spheroid.m
225 lines (167 loc) · 5.96 KB
/
example_sound_soft_spheroid.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
% TMATROM3 example
%
% This example:
%
% 1) Computes the T-matrix of a sound-soft spheroid
% 2) Visualises the spheroid
% 3) Computes the T-matrix of the spheroid*
% 4) Uses the T-matrix to compute the scattered field for an incident plane wave
% 5) Plots the differential scattering cross section
% 6) Plots the total scattered field
%
% * the T-matrix is saved to disk and if the example is rerun then the
% saved T-matrix is used.
%
% Stuart C. Hawkins - 2 September 2021
% Copyright 2019-2022 Stuart C. Hawkins
%
% This file is part of TMATROM3
%
% TMATROM3 is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% TMATROM3 is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with TMATROM3. If not, see <http://www.gnu.org/licenses/>.
%------------------------------------------------
% print info
%------------------------------------------------
help example_sound_soft_spheroid
%------------------------------------------------
% set main parameters
%------------------------------------------------
% set wavenumber
kwave = 5.0;
% set aspect ratio of prolate spheroid
ar = 1.5;
% set spheroid centre
x0 = [0;0;0];
% set plane wave direction
d = [0;0;1];
% set solver parameter
m = 25;
%------------------------------------------------
% try to load the T-matrix
%------------------------------------------------
% initialise flag to say we didn't load the T-matrix
loaded_tmatrix = 0;
% check if a T-matrix file exists
if exist('tmatrix_sound_soft_spheroid_example.mat','file')
% load the T-matrix
T = tmatrix('tmatrix_sound_soft_spheroid_example.mat');
% check the wavenumber matches...
if abs(T.kwave - kwave)<1e-15
% ...if it matched then we accept the saved T-matrix but beware...
% the aspect ratio or centre could have been changed so it still
% might not be the correct T-matrix
% update the flag to show we loaded the T-matrix
loaded_tmatrix = 1;
end
end
% display a warning message
if loaded_tmatrix
fprintf('Warning:\n\n');
fprintf('Loaded T-matrix from tmatrix_sound_soft_spheroid_example.mat.\n');
fprintf('This may not be the correct T-matrix if you changed any of the\n');
fprintf('experiment parameters.\n\n')
fprintf('In this case please delete tmatrix_sound_soft_spheroid_example.mat\n');
fprintf('and rerun this example.\n');
end
%------------------------------------------------
% compute the T-matrix
%------------------------------------------------
% setup solver for sound soft scattering by a spheroid
slvr = solverEllipsoidSoft(kwave,[],x0,[1 1 ar],m,2*m);
% work out the suggested wavefunction expansion order
% Note: the diameter of the prolate spheroid is 2*ar so the
% "radius" is ar
n = suggestedorder(kwave,ar);
% compute the T-matrix if we didn't already load it
if ~loaded_tmatrix
% setup the solver... this assembles the linear system
slvr.setup
% compute the T-matrix with expansion origin [0;0;0]
T = ghtmatrix(n,kwave,slvr,[0;0;0]);
% save the T-matrix
T.save('tmatrix_sound_soft_spheroid_example.mat')
end
%------------------------------------------------
% visualise the scatterer
%------------------------------------------------
% create a new figure
figure(1)
% visualise the scatterer
slvr.visualise()
% make the figure look nice
axis equal
light
title('Visualisation of the scatterer')
%------------------------------------------------
% use the T-matrix to solve the scattering problem
%------------------------------------------------
% setup incident wave
inc = plane_wave(d,kwave);
% get the regular wavefunction expansion of the incident wave with
% expansion origin [0;0;0]
a = regularwavefunctionexpansion(n,[0;0;0],inc);
% compute the radiating wavefunction expansion of the scattered wave
% with expansion origin [0;0;0] using the T-matrix
b = T * a;
%------------------------------------------------
% visualise the differential scattering cross section
%------------------------------------------------
% create a new figure
figure
% generate a vector of scattering angles
theta = linspace(0,pi,1000);
% compute corresponding points on the unit sphere at which we
% compute the differential scattering cross section
p = [sin(theta);zeros(size(theta));cos(theta)];
% get the far field at the points in p
psi = b.evaluateFarField(p);
% plot the differential scattering cross section
plot(theta,abs(psi).^2,'b-')
% make the figure look nice
xlabel('scattering angle')
ylabel('differential scattering cross section')
title('Differential scattering cross section')
%------------------------------------------------
% visualise the total field
%------------------------------------------------
% create a new figure
figure
% create a mesh of points at which to compute the field
u = linspace(-3,3,100);
v = linspace(-3,3,100);
[x,z] = meshgrid(u,v);
y = zeros(size(x));
% stack the mesh points into a 3 x m array
p = [x(:).';y(:).';z(:).'];
% the wavefunction expansion is only valid outside a sphere of radius
% ar... we need to apply a mask
r = sqrt(sum(p.^2,1));
mask = (r>1.05*ar);
% initialise an array to hold the field
psi = zeros(size(x));
% get the field at the masked mesh points
tmp = b.evaluate(p(:,mask)) + inc.evaluate(p(:,mask));
% slot the field values into their array
psi(mask) = tmp;
% make the masked points NaN so that they don't get plotted
psi(~mask) = NaN;
% plot the real part of the field
surf(x,y,z,real(psi))
% make the figure look nice
axis equal
shading interp
title('Total field (real part)')
% add the scatterer
hold on
slvr.visualise();
hold off