Skip to content

Commit

Permalink
fix typos in chunkerinterior/kerneval. fix bug in kernbyindexr
Browse files Browse the repository at this point in the history
adds things to trigger FLAM, FMM, direct in greenlaptest
  • Loading branch information
askhamwhat committed Feb 29, 2024
1 parent 69e5922 commit 0aeb6ad
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 21 deletions.
16 changes: 11 additions & 5 deletions chunkie/+chnk/+flam/kernbyindexr.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,22 @@
srcinfo.n = nj;
% Assign appropriate object to targinfo
targinfo = [];
if isa(targobj, "chunker")
if isa(targobj, "chunker") || isa(targobj, "chunkgraph")
targinfo.r = targobj.r(:,iuni);
targinfo.d = targobj.d(:,iuni);
targinfo.d2 = targobj.d2(:,iuni);
targinfo.n = targobj.n(:,iuni);
elseif isa(targobj, "chunkgraph")
elseif isstruct(targobj)
if isfield(targobj,'d')
targinfo.d = targobj.d(:,iuni);
end
if isfield(targobj,'d2')
targinfo.d = targobj.d(:,iuni);
end
if isfield(targobj,'n')
targinfo.n = targobj.n(:,iuni);
end
targinfo.r = targobj.r(:,iuni);
targinfo.d = targobj.d(:,iuni);
targinfo.d2 = targobj.d2(:,iuni);
targinfo.n = targobj.n(:,iuni);
else
targinfo.r = targobj(:,iuni);
end
Expand Down
2 changes: 1 addition & 1 deletion chunkie/chunkerinterior.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
elseif class(chnkobj) == "chunkgraph"
chnkr = merge(chnkobj.echnks);
else
msg = "Unsupported object in chunkerinteriort";
msg = "Unsupported object in chunkerinterior";
error(msg)
end

Expand Down
5 changes: 1 addition & 4 deletions chunkie/chunkerkerneval.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,10 @@
elseif class(chnkobj) == "chunkgraph"
chnkr = merge(chnkobj.echnks);
else
msg = "Unsupported object in chunkerinteriort";
msg = "Unsupported object in chunkerkerneval";
error(msg)
end




srcinfo = []; targinfo = [];
srcinfo.r = chnkr.r(:,1); srcinfo.d = chnkr.d(:,1);
srcinfo.n = chnkr.n(:,1); srcinfo.d2 = chnkr.d2(:,1);
Expand Down
57 changes: 46 additions & 11 deletions devtools/test/chunkerkerneval_greenlapTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@

% sources

ns = 10;
ns = 100;
ts = 0.0+2*pi*rand(ns,1);
sources = starfish(ts,narms,amp);
sources = 3.0*sources;
strengths = randn(ns,1);

% targets

nt = 100;
nt = 300;
ts = 0.0+2*pi*rand(nt,1);
targets = starfish(ts,narms,amp);
targets = targets.*repmat(rand(1,nt),2,1);
Expand All @@ -52,9 +52,9 @@

% kernel defs

kernd = @(s,t) chnk.lap2d.kern(s,t,'d');
kerns = @(s,t) chnk.lap2d.kern(s,t,'s');
kernsprime = @(s,t) chnk.lap2d.kern(s,t,'sprime');
kernd = kernel('lap','d');
kerns = kernel('lap','s');
kernsprime = kernel('lap','sprime');

opdims = [1 1];

Expand All @@ -63,21 +63,22 @@
srcinfo = []; srcinfo.r = sources;
targinfo = []; targinfo.r = chnkr.r(:,:);
targinfo.d = chnkr.d(:,:);
kernmats = kerns(srcinfo,targinfo);
kernmatsprime = kernsprime(srcinfo,targinfo);
kernmats = kerns.eval(srcinfo,targinfo);
kernmatsprime = kernsprime.eval(srcinfo,targinfo);
densu = kernmats*strengths;
densun = kernmatsprime*strengths;

% eval u at targets

targinfo = []; targinfo.r = targets;
kernmatstarg = kerns(srcinfo,targinfo);
kernmatstarg = kerns.eval(srcinfo,targinfo);
utarg = kernmatstarg*strengths;


% test green's id
% test green's id. we use FLAM, direct and FMM for smooth work

opts.quadkgparams = {'RelTol',1.0e-13,'AbsTol',1.0e-13};
opts = [];
opts.flam = true;
start=tic; Du = chunkerkerneval(chnkr,kernd,densu,targets,opts);
toc(start)
start=tic; Sun = chunkerkerneval(chnkr,kerns,densun,targets,opts);
Expand All @@ -89,7 +90,41 @@

relerr = norm(utarg-utarg2,'fro')/norm(utarg,'fro');

fprintf('relative frobenius error %5.2e\n',relerr);
fprintf('relative frobenius error, forcing flam %5.2e\n',relerr);

assert(relerr < 1e-11);

opts = [];
opts.accel = false;
start=tic; Du = chunkerkerneval(chnkr,kernd,densu,targets,opts);
toc(start)
start=tic; Sun = chunkerkerneval(chnkr,kerns,densun,targets,opts);
toc(start)

utarg2 = Sun-Du;

%

relerr = norm(utarg-utarg2,'fro')/norm(utarg,'fro');

fprintf('relative frobenius error, forcing direct %5.2e\n',relerr);

assert(relerr < 1e-11);

opts = [];
opts.forcefmm = true;
start=tic; Du = chunkerkerneval(chnkr,kernd,densu,targets,opts);
toc(start)
start=tic; Sun = chunkerkerneval(chnkr,kerns,densun,targets,opts);
toc(start)

utarg2 = Sun-Du;

%

relerr = norm(utarg-utarg2,'fro')/norm(utarg,'fro');

fprintf('relative frobenius error, forcing fmm %5.2e\n',relerr);

assert(relerr < 1e-11);

0 comments on commit 0aeb6ad

Please sign in to comment.