Skip to content

Commit 6d435c7

Browse files
committed
fixing getnear to return struct and adding documentation
1 parent e2f6aea commit 6d435c7

File tree

2 files changed

+118
-16
lines changed

2 files changed

+118
-16
lines changed

matlab/fmm3dbie_routs.mw

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5329,17 +5329,58 @@ end
53295329
%
53305330
%
53315331
@ src/getnear.m
5332-
function [row_ptr, col_ind, iquad] = getnear(S, targinfo, rfac)
5332+
function [rsc] = getnear(S, targinfo, rfac)
53335333
%
5334-
% getnear
5335-
% This subroutine returns the indices of the near quadrature corrections
5334+
% getnear(S, varargin)
5335+
%
5336+
% Syntax:
5337+
% [rsc] = getnear(S)
5338+
% [rsc] = getnear(S, targinfo)
5339+
% [rsc] = getnear(S, targinfo, rfac)
5340+
%
5341+
% This subroutine returns the row sparse compressed struct
5342+
% for near interactions between the surface S, and targets.
5343+
%
5344+
% The row sparse compressed representation is a sparse format
5345+
% between target indices and patch indices of the surface.
5346+
% It additionally includes an indexing array which points to where
5347+
% quadrature corrections for interaction between target and patch
5348+
% are stored.
5349+
%
5350+
% Input arguments:
5351+
% * S: surfer object, see README.md in matlab for details
5352+
% * targinfo: target info (optional)
5353+
% targinfo.r = (3,nt) target locations
5354+
% targinfo = S if unspecified
5355+
% * rfac: radius defining near neighborhood (optional)
5356+
% target t_{i} is close to patch \Gamma_{j} if
5357+
% d(t_{i}, c_{j}) <= rfac*R_{j}
5358+
% where c_{j} is the centroid of \Gamma_{j}, and
5359+
% R_{j} is the radius of the bounding sphere
5360+
% centered at c_{j}
5361+
%
5362+
% Output arguments:
5363+
% * rsc: row sparse compressed struct
5364+
% rsc.row_ptr: (nt+1,1)
5365+
% pointer to col_ind array where list of relevant source
5366+
% patches for target i starts
5367+
% rsc.col_ind: (nnz,1)
5368+
% list of source patches relevant for all targets,
5369+
% sorted by target number
5370+
% rsc.iquad: (nnz+1,1)
5371+
% iquad(i) is the location in quadrature correction array
5372+
% where quadrature for interaction corresponding to
5373+
% col_ind(i) starts
5374+
%
5375+
%
5376+
53365377
[~,~,norders,ixyzs,iptype,~] = extract_arrays(S);
53375378
npatches = S.npatches;
53385379
npts = S.npts;
53395380

53405381
if nargin < 2
53415382
targs = S.r;
5342-
else
5383+
else
53435384
if isa(S, 'struct') || isa(S,'surfer')
53445385
targs = targinfo.r;
53455386
else
@@ -5350,9 +5391,14 @@ function [row_ptr, col_ind, iquad] = getnear(S, targinfo, rfac)
53505391
ntarg = size(targs,2);
53515392

53525393
if nargin < 3
5353-
iptype_avg = floor(sum(iptype)/(npatches+0.0d0));
5354-
norder_avg = floor(sum(norders)/(npatches+0.0d0));
5355-
5394+
[iptype_c, iptype_n] = groupcounts(iptype);
5395+
[~, ind] = max(iptype_c);
5396+
iptype_avg = iptype_n(ind);
5397+
5398+
[norder_c, norder_n] = groupcounts(norders);
5399+
[~, ind] = max(norder_c);
5400+
norder_avg = norder_n(ind);
5401+
53565402
% get nearfield definition
53575403
rfac = 0;
53585404
rfac0 = 0;
@@ -5380,5 +5426,10 @@ function [row_ptr, col_ind, iquad] = getnear(S, targinfo, rfac)
53805426
iquad = zeros(nnz+1,1);
53815427
npp1 = npatches+1;
53825428
# FORTRAN get_iquad_rsc(int[1] npatches,int[npp1] ixyzs,int[1] npts,int[1] nnz,int[ntp1] row_ptr,int[nnz] col_ind,inout int[nnzp1] iquad);
5429+
5430+
rsc = [];
5431+
rsc.row_ptr = row_ptr;
5432+
rsc.col_ind = col_ind;
5433+
rsc.iquad = iquad;
53835434

5384-
end
5435+
end

matlab/src/getnear.m

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,55 @@
1-
function [row_ptr, col_ind, iquad] = getnear(S, targinfo, rfac)
1+
function [rsc] = getnear(S, targinfo, rfac)
22
%
3-
% getnear
4-
% This subroutine returns the indices of the near quadrature corrections
3+
% getnear(S, varargin)
4+
%
5+
% Syntax:
6+
% [rsc] = getnear(S)
7+
% [rsc] = getnear(S, targinfo)
8+
% [rsc] = getnear(S, targinfo, rfac)
9+
%
10+
% This subroutine returns the row sparse compressed struct
11+
% for near interactions between the surface S, and targets.
12+
%
13+
% The row sparse compressed representation is a sparse format
14+
% between target indices and patch indices of the surface.
15+
% It additionally includes an indexing array which points to where
16+
% quadrature corrections for interaction between target and patch
17+
% are stored.
18+
%
19+
% Input arguments:
20+
% * S: surfer object, see README.md in matlab for details
21+
% * targinfo: target info (optional)
22+
% targinfo.r = (3,nt) target locations
23+
% targinfo = S if unspecified
24+
% * rfac: radius defining near neighborhood (optional)
25+
% target t_{i} is close to patch \Gamma_{j} if
26+
% d(t_{i}, c_{j}) <= rfac*R_{j}
27+
% where c_{j} is the centroid of \Gamma_{j}, and
28+
% R_{j} is the radius of the bounding sphere
29+
% centered at c_{j}
30+
%
31+
% Output arguments:
32+
% * rsc: row sparse compressed struct
33+
% rsc.row_ptr: (nt+1,1)
34+
% pointer to col_ind array where list of relevant source
35+
% patches for target i starts
36+
% rsc.col_ind: (nnz,1)
37+
% list of source patches relevant for all targets,
38+
% sorted by target number
39+
% rsc.iquad: (nnz+1,1)
40+
% iquad(i) is the location in quadrature correction array
41+
% where quadrature for interaction corresponding to
42+
% col_ind(i) starts
43+
%
44+
%
45+
546
[~,~,norders,ixyzs,iptype,~] = extract_arrays(S);
647
npatches = S.npatches;
748
npts = S.npts;
849

950
if nargin < 2
1051
targs = S.r;
11-
else
52+
else
1253
if isa(S, 'struct') || isa(S,'surfer')
1354
targs = targinfo.r;
1455
else
@@ -19,9 +60,14 @@
1960
ntarg = size(targs,2);
2061

2162
if nargin < 3
22-
iptype_avg = floor(sum(iptype)/(npatches+0.0d0));
23-
norder_avg = floor(sum(norders)/(npatches+0.0d0));
24-
63+
[iptype_c, iptype_n] = groupcounts(iptype);
64+
[~, ind] = max(iptype_c);
65+
iptype_avg = iptype_n(ind);
66+
67+
[norder_c, norder_n] = groupcounts(norders);
68+
[~, ind] = max(norder_c);
69+
norder_avg = norder_n(ind);
70+
2571
% get nearfield definition
2672
rfac = 0;
2773
rfac0 = 0;
@@ -53,5 +99,10 @@
5399
npp1 = npatches+1;
54100
mex_id_ = 'get_iquad_rsc(i int[x], i int[x], i int[x], i int[x], i int[x], i int[x], io int[x])';
55101
[iquad] = fmm3dbie_routs(mex_id_, npatches, ixyzs, npts, nnz, row_ptr, col_ind, iquad, 1, npp1, 1, 1, ntp1, nnz, nnzp1);
102+
103+
rsc = [];
104+
rsc.row_ptr = row_ptr;
105+
rsc.col_ind = col_ind;
106+
rsc.iquad = iquad;
56107

57-
end
108+
end

0 commit comments

Comments
 (0)