1function out = solver(prob, n)
2% chunkie double-layer BIE for the interior Dirichlet Laplace problem.
3%
4% The same second-kind double-layer formulation as nystrom-dlp,
5% (D - I/2) sigma = g, but discretized and solved by
6% chunkie (https://github.com/fastalgorithms/chunkie), a production
7% MATLAB toolbox for boundary integral equations in 2D: the curve is
8% panelized into n uniform 16th-order Gauss-Legendre chunks, chunkermat
9% assembles the system with high-order singular quadrature, the dense
10% system is solved directly, and chunkerkerneval evaluates the potential
11% with corrected quadrature for targets near the boundary.
12%
13% This solver runs in real MATLAB only: the command-line harness invokes
14% it through `matlab -batch`, having put chunkie on the path with
15% `mip load --install chunkie`. It is not runnable in the browser.
16%
17% n : number of chunks (16 points each).
19chnkr = chunkerfuncuni(@(t) fcurve(t, prob), n);
21% Dirichlet data at the nodes: for this problem family the curve
22% parameter is the polar angle, so it is recovered from the node
23% coordinates.
24xy = chnkr.r(:, :);
25tt = mod(atan2(xy(2, :), xy(1, :)), 2*pi);
26rhs = prob.g(tt(:));
28fkern = kernel('lap', 'd');
29sysmat = chunkermat(chnkr, fkern);
30sysmat = sysmat - 0.5*eye(chnkr.npt);
31sigma = sysmat \ rhs;
33out = struct();
34out.uEval = eval_targets(chnkr, fkern, sigma, prob.evalXY);
35if size(prob.vizXY, 1) > 0
36 out.uGrid = eval_targets(chnkr, fkern, sigma, prob.vizXY);
37else
38 out.uGrid = zeros(0, 1);
39end
41end
43function u = eval_targets(chnkr, fkern, sigma, XY)
44% Evaluation with chunkie's own defaults, which means its FMM
45% acceleration of the smooth part (opts.accel, true unless overridden)
46% wherever the point counts make that worth doing. The mip fmm2d package
47% supplies the compiled binary this needs.
48u = chunkerkerneval(chnkr, fkern, sigma, XY.');
49u = u(:);
50end
52function [r, d, d2] = fcurve(t, prob)
53tt = t(:);
54r = prob.curve(tt).';
55d = prob.curveD(tt).';
56d2 = prob.curveDD(tt).';
57end