diff --git a/chunkie/+chnk/+flam/kernbyindexr.m b/chunkie/+chnk/+flam/kernbyindexr.m index a03fa2a..b280657 100644 --- a/chunkie/+chnk/+flam/kernbyindexr.m +++ b/chunkie/+chnk/+flam/kernbyindexr.m @@ -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 diff --git a/chunkie/chunkerinterior.m b/chunkie/chunkerinterior.m index 49ece7e..cde9605 100644 --- a/chunkie/chunkerinterior.m +++ b/chunkie/chunkerinterior.m @@ -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 diff --git a/chunkie/chunkerkerneval.m b/chunkie/chunkerkerneval.m index 573bf92..8530f53 100644 --- a/chunkie/chunkerkerneval.m +++ b/chunkie/chunkerkerneval.m @@ -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); diff --git a/devtools/test/chunkerkerneval_greenlapTest.m b/devtools/test/chunkerkerneval_greenlapTest.m index 9cccf63..ecf5c92 100644 --- a/devtools/test/chunkerkerneval_greenlapTest.m +++ b/devtools/test/chunkerkerneval_greenlapTest.m @@ -23,7 +23,7 @@ % sources -ns = 10; +ns = 100; ts = 0.0+2*pi*rand(ns,1); sources = starfish(ts,narms,amp); sources = 3.0*sources; @@ -31,7 +31,7 @@ % 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); @@ -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]; @@ -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); @@ -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);