% Time-harmonic scattering of plane wave from grating of dielectric obstacles
% Uses MATLAB with MPSpack toolbox, v1.1 beta or above.  Barnett, July 2010

d = 1.0;                                            % problem period
N = 110; s = scale(segment.smoothstar(N, 0.3, 3), 0.35); % smooth closed curve
di = domain(s, 1); di.setrefractiveindex(1.5);      % obstacle, refractive index
de = domain([], [], s, -1);                         % obstacle's exterior
s.addinoutlayerpots('d'); s.addinoutlayerpots('s'); % add Rokhlin LP scheme
s.setmatch('diel', 'TM');                           % TM dielectric continuity
p = qpscatt(de, di, d, struct('nei',2,'buf',1,'M',90)); % numerical parameters
p.setoverallwavenumber(10);                         % incident wavenumber
p.setincidentwave(-pi/5);                           % incident plane wave angle
p.solvecoeffs;                                      % fill matrices and solve
[u d n] = p.braggpowerfracs(struct('table',1));     % Bragg order efficiencies
p.showfullfield(struct('ymax', 1));                 % plot Re part of full field
