@@ -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
0 commit comments