Skip to content

Commit

Permalink
clean up documentation and add adaptive integration
Browse files Browse the repository at this point in the history
routines. name changes to important routines
  • Loading branch information
askhamwhat committed Apr 24, 2020
1 parent 76fbe4b commit f3bb931
Show file tree
Hide file tree
Showing 93 changed files with 2,560 additions and 523 deletions.
12 changes: 10 additions & 2 deletions +chnk/+lap2d/kern.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

function submat = kern(src,targ,srctau,targtau,type)
function submat = kern(src,targ,srctau,targtau,type,varargin)

[~,ns] = size(src);
[~,nt] = size(targ);
Expand All @@ -21,4 +21,12 @@

if strcmpi(type,'s')
submat = chnk.lap2d.green(src,targ);
end
end

if strcmpi(type,'c')
eta = varargin{1};
[s,grad] = chnk.lap2d.green(src,targ);
nx = repmat(srctau(2,:),nt,1);
ny = repmat(-srctau(1,:),nt,1);
submat = -(grad(:,:,1).*nx + grad(:,:,2).*ny) + eta*s;
end
169 changes: 169 additions & 0 deletions +chnk/+quadadap/buildmat.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
function [sysmat] = buildmat(chnkr,kern,opdims,type,opts)
%CHNK.QUADADAP.BUILDMAT build matrix for given kernel and chnkr
% description of boundary, using special quadrature for self panel
% and adaptive quadrature for neighbor panels. Optionally, adaptive
% quadrature can be applied to nearly singular interactions, i.e.
% targets within a chunk length of each chunk
%
%

if nargin < 5
opts = [];
end

robust = false;
if isfield(opts,'robust')
robust = opts.robust;
end

k = chnkr.k;
nch = chnkr.nch;
r = chnkr.r;
adj = chnkr.adj;
d = chnkr.d;
d2 = chnkr.d2;
h = chnkr.h;

[t,wts,u] = lege.exps(k);
bw = lege.barywts(k);

k2 = max(27,k+1);
[t2,w2] = lege.exps(k2);

if strcmpi(type,'log')

qavail = chnk.quadggq.logavail();
[~,i] = min(abs(qavail-k));
assert(qavail(i) == k,'order %d not found, consider using order %d chunks', ...
k,qavail(i));
[~,~,xs0,wts0] = chnk.quadggq.getlogquad(k);
else
error('type not available')
end

nquad0 = size(xs0,1);

ainterps0 = zeros(opdims(2)*nquad0,opdims(2)*k,k);

temp = eye(opdims(2));

for i = 1:k
xs0j = xs0(:,i);
ainterp0_sm = lege.matrin(k,xs0j);
ainterps0(:,:,i) = kron(ainterp0_sm,temp);
end

% do smooth weight for all
sysmat = chnk.quadnative.buildmat(chnkr,kern,opdims,1:nch,1:nch,wts);

% overwrite nbor and self
for i = 1:nch

jmat = 1 + (i-1)*k*opdims(2);
jmatend = i*k*opdims(2);

ibefore = adj(1,i);
iafter = adj(2,i);

% neighbors
rt = r(:,:,ibefore);
dt = d(:,:,ibefore);
dtlen = sqrt(sum(d.^2,1));
taut = dt./dtlen;
submat = chnk.adapgausswts(r,d,h,t,bw,i,rt,taut, ...
kern,opdims,t2,w2);

imat = 1 + (ibefore-1)*k*opdims(1);
imatend = ibefore*k*opdims(1);

sysmat(imat:imatend,jmat:jmatend) = submat;

rt = r(:,:,iafter);
dt = d(:,:,iafter);
dtlen = sqrt(sum(d.^2,1));
taut = dt./dtlen;
submat = chnk.adapgausswts(r,d,h,t,bw,i,rt,taut, ...
kern,opdims,t2,w2);

imat = 1 + (iafter-1)*k*opdims(1);
imatend = iafter*k*opdims(1);

sysmat(imat:imatend,jmat:jmatend) = submat;

% self

submat = chnk.quadggq.diagbuildmat(r,d,h,i,kern,opdims,...
u,xs0,wts0,ainterps0);

imat = 1 + (i-1)*k*opdims(1);
imatend = i*k*opdims(1);

sysmat(imat:imatend,jmat:jmatend) = submat;

end

if robust

% pair-wise distances of chunk pts

dim = chnkr.dim;
k = chnkr.k;
nch = chnkr.nch;

dists = zeros(k*nch,k*nch);
for i = 1:dim
ri = r(i,:);
dists = dists + (ri - ri.').^2;
end
dists = sqrt(dists);

wtschnk = whts(chnkr);
chnklen = sum(wtschnk,1);

% do adaptive quadrature for points that aren't
% neighbors/self points but are too close

for i = 1:nch
istart = (i-1)*k+1;
iend = i*k;
jmat = 1 + (i-1)*k*opdims(2);
jmatend = i*k*opdims(2);

chnkdisti = dists(:,istart:iend);
chnkdistmini = min(chnkdisti,[],2);
targfix = find(chnkdistmini < chnklen(i));

iright = adj(2,i);
ileft = adj(1,i);
targignore = istart:iend;
if iright > 0
ir1 = (iright-1)*k+1;
ir2 = iright*k;
targignore = [targignore, ir1:ir2];
end
if ileft > 0
il1 = (ileft-1)*k+1;
il2 = ileft*k;
targignore = [targignore, il1:il2];
end

targfix = setdiff(targfix,targignore(:));

rt = r(:,targfix);
dt = d(:,targfix);
dtlen = sqrt(sum(dt.^2,1));
taut = dt./dtlen;

submat = chnk.adapgausswts(r,d,h,t,bw,i,rt,taut, ...
kern,opdims,t2,w2);

imats = bsxfun(@plus,(1:opdims(1)).',opdims(1)*(targfix(:)-1).');
imats = imats(:);
sysmat(imats,jmat:jmatend) = submat;

end


end

end
12 changes: 6 additions & 6 deletions +chnk/+quadggq/buildmat.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
d2 = chnkr.d2;
h = chnkr.h;

[~,whts,u] = lege.exps(k);
[~,wts,u] = lege.exps(k);

if strcmpi(type,'log')

qavail = chnk.quadggq.logavail();
[~,i] = min(abs(qavail-k));
assert(qavail(i) == k,'order %d not found, consider using order %d chunks', ...
k,qavail(i));
[xs1,whts1,xs0,whts0] = chnk.quadggq.getlogquad(k);
[xs1,wts1,xs0,wts0] = chnk.quadggq.getlogquad(k);
else
error('type not available')
end
Expand All @@ -41,7 +41,7 @@
end

% do smooth weight for all
sysmat = chnk.quadnative.buildmat(chnkr,kern,opdims,1:nch,1:nch,whts);
sysmat = chnk.quadnative.buildmat(chnkr,kern,opdims,1:nch,1:nch,wts);

% overwrite nbor and self
for j = 1:nch
Expand All @@ -55,15 +55,15 @@
% neighbors

submat = chnk.quadggq.nearbuildmat(r,d,h,ibefore,j, ...
kern,opdims,u,xs1,whts1,ainterp1);
kern,opdims,u,xs1,wts1,ainterp1);

imat = 1 + (ibefore-1)*k*opdims(1);
imatend = ibefore*k*opdims(1);

sysmat(imat:imatend,jmat:jmatend) = submat;

submat = chnk.quadggq.nearbuildmat(r,d,h,iafter,j, ...
kern,opdims,u,xs1,whts1,ainterp1);
kern,opdims,u,xs1,wts1,ainterp1);

imat = 1 + (iafter-1)*k*opdims(1);
imatend = iafter*k*opdims(1);
Expand All @@ -73,7 +73,7 @@
% self

submat = chnk.quadggq.diagbuildmat(r,d,h,j,kern,opdims,...
u,xs0,whts0,ainterps0);
u,xs0,wts0,ainterps0);

imat = 1 + (j-1)*k*opdims(1);
imatend = j*k*opdims(1);
Expand Down
10 changes: 5 additions & 5 deletions +chnk/+quadggq/buildmattd.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [spmat] = buildmattd(chnkr,kern,quadorder,opdims,type)
function [spmat] = buildmattd(chnkr,kern,opdims,type)
%BUILDMATTD build sparse matrix corresponding to self and neighbor
% interactions for given kernel and chnkr description of boundary
%
Expand All @@ -22,7 +22,7 @@
[~,i] = min(abs(qavail-k));
assert(qavail(i) == k,'order %d not found, consider using order %d chunks', ...
k,qavail(i));
[xs1,whts1,xs0,whts0] = chnk.quadggq.getlogquad(k);
[xs1,wts1,xs0,wts0] = chnk.quadggq.getlogquad(k);
else
error('type not available')
end
Expand Down Expand Up @@ -56,7 +56,7 @@
% neighbors

submat = chnk.quadggq.nearbuildmat(r,d,h,ibefore,j, ...
kern,opdims,u,xs1,whts1,ainterp1);
kern,opdims,u,xs1,wts1,ainterp1);

submat(submat == 0.0) = 1e-300; %hack

Expand All @@ -66,7 +66,7 @@
spmat(imat:imatend,jmat:jmatend) = submat;

submat = chnk.quadggq.nearbuildmat(r,d,h,iafter,j, ...
kern,opdims,u,xs1,whts1,ainterp1);
kern,opdims,u,xs1,wts1,ainterp1);

submat(submat == 0.0) = 1e-300;

Expand All @@ -78,7 +78,7 @@
% self

submat = chnk.quadggq.diagbuildmat(r,d,h,j,kern,opdims,...
u,xs0,whts0,ainterps0);
u,xs0,wts0,ainterps0);

submat(submat == 0.0) = 1e-300;

Expand Down
6 changes: 3 additions & 3 deletions +chnk/+quadnative/buildmat.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function submat = buildmat(chnkr,kern,opdims,i,j,whts)
function submat = buildmat(chnkr,kern,opdims,i,j,wts)
%CHNK.QUADSMOOTH.BUILDMAT build matrix for far interactions with this kernel
% assuming that the smooth rule is sufficient
%
Expand All @@ -12,7 +12,7 @@
j = 1:chnkr.nch;
end
if nargin < 6
[~,whts] = lege.exps(chnkr.k);
[~,wts] = lege.exps(chnkr.k);
end

% grab specific boundary data
Expand All @@ -34,7 +34,7 @@
dtnrms = sqrt(sum(abs(dt).^2,1));
taut = bsxfun(@rdivide,dt,dtnrms);

ws = kron(hs(:),whts(:));
ws = kron(hs(:),wts(:));

dsdt = dsnrms(:).*ws;

Expand Down
Loading

0 comments on commit f3bb931

Please sign in to comment.