-
Notifications
You must be signed in to change notification settings - Fork 0
/
point_source.m
207 lines (160 loc) · 6.28 KB
/
point_source.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
% Point source incident field.
%
% u = point_source(x0,k) returns a point source object u with
% wavenumber k and source location x0 (a vector with length 3).
%
% Also:
%
% f = u.evaluate(p) returns the values f of the point source at points p.
% Here p must be a 3 x n matrix.
%
% f = u.evaluate(z,mask) returns the values f of the point source at
% points z for which mask==1 and NaN elsewhere.
%
% [dx,dy,dz] = u.evaluateGradient(p) returns dx, dy and dz the partial
% derivatives of the point source in the x, y and z directions respectively
% at the points p. Here p must be a 3 x n matrix.
%
% [dx,dy,dz] = u.evaluateGradient(z,mask) returns dx, dy and dz the partial
% derivatives of the point source in the x, y and z directions respectively
% at the points p for which mask==1 and NaN elsewhere.
%
% cof = u.get_coefficients(x0,n) returns the vector cof of regular
% wavefunction expansion coefficients of the point source field with
% wavefunction origin x0 and order n.
%
% See also: plane_wave, incident.
%
% Stuart C. Hawkins - 20 April 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/>.
classdef point_source < incident
properties
location
kwave
end
methods
%-----------------------------------------
% constructor
%-----------------------------------------
function self = point_source(location,kwave)
% set wavenumber
self.kwave = kwave;
% set location (as column vector)
self.location = location(:);
end
%-----------------------------------------
% evaluate
%-----------------------------------------
function val = evaluate(self,points,mask)
% get size of points
n = size(points);
% reshape points
points = reshape(points,3,[]);
% reshape mask if given
if nargin>2
mask = reshape(mask,1,[]);
end
% initialise return array
val = zeros(1,size(points,2));
% apply mask if necessary
if nargin > 2
points = points(:,mask);
end
% get distance of points from source
r = sqrt(sum((points - repmat(self.location,1,size(points,2))).^2,1));
% evaluate incident field
v = (0.25/pi)*exp(1i*self.kwave*r)./r;
% insert values into the return array
if nargin>2
val(:,mask) = v;
else
val = v;
end
% reshape the return array to match points
if length(n)==2
val = reshape(val,1,n(end));
else
val = reshape(val,n(2:end));
end
end
%-----------------------------------------
% evaluate gradient
%-----------------------------------------
function [dx,dy,dz] = evaluateGradient(self,points,mask)
% get size of points
n = size(points);
% reshape points
points = reshape(points,3,[]);
% reshape mask if given
if nargin>2
mask = reshape(mask,1,[]);
end
% initialise return array
dx = zeros(1,size(points,2));
dy = zeros(1,size(points,2));
dz = zeros(1,size(points,2));
% apply mask if necessary
if nargin > 2
points = points(:,mask);
end
% get direction of points from source
d = points - repmat(self.location,1,size(points,2));
% get distance of points from source
r = sqrt(sum(d.^2,1));
% evaluate incident field
v = (0.25/pi)*exp(1i*self.kwave*r)...
.*((1i*self.kwave)*r-1)./r.^3;
% insert values into the return array
if nargin>2
dx(:,mask) = v.*d(1,:);
dy(:,mask) = v.*d(2,:);
dz(:,mask) = v.*d(3,:);
else
dx = v.*d(1,:);
dy = v.*d(2,:);
dz = v.*d(3,:);
end
% reshape the return array to match points
if length(n)==2
dx = reshape(dx,1,n(end));
dy = reshape(dy,1,n(end));
dz = reshape(dz,1,n(end));
else
dx = reshape(dx,n(2:end));
dy = reshape(dy,n(2:end));
dz = reshape(dz,n(2:end));
end
end
%-----------------------------------------
% evaluate far field
%-----------------------------------------
function val = evaluateFarField(self,points)
% compute the far field using (2.15) in Colton and Kress,
% Inverse Acoustic and Electromagnetic Scattering Theory, 4th
% edition.
dp = sum(repmat(self.location,1,size(points,2)) .* points,1);
val = (0.25/pi)*exp(-1i*self.kwave*dp);
end
%-----------------------------------------
% get coefficients
%-----------------------------------------
function cof = get_coefficients(self,centre,nmax)
error('not implemented yet')
end
end
end