| The control of waves using periodic structures is crucial for modern optical, electromagnetic and acoustic devices such as diffraction gratings, filters, photonic crystals, solar cells, sensors, and absorbers. We present a high-order accurate boundary-based numerical solver for three-dimensional (3D) frequency-domain scattering from a doubly-periodic grating of obstacles. We focus on the case of axisymmetric objects, and handle both acoustic and electromagnetic cases. We combine the method of fundamental solutions (MFS) with a new periodizing scheme, using various fast algorithms such as the fast multiple method and the so-called ``skeletonization". Our scheme has exponential convergence for analytic shapes and avoids singular quadratures, periodic Green's functions, and lattice sums. Furthermore, the convergence rate of our scheme is unaffected by resonances within obstacles. The periodizing scheme is also independent of the complexity of the objects and the frequency can reach 13lambda x 13lambda x 13lambda in each periodic unit, which covers the vast majority of scattering problems in practice; meanwhile, the solver can achieve 10 digits of accuracy, takes less than 1 hour of computational time, and requires less than 6GB of RAM space. We also propose a way to efficiently solve scattering problems on boundaries with corners using the MFS to achieve 10 digits of accuracy for a range of corner angles. Also, we can observe exponential convergence as the number of unknowns increases for corner problems. Lastly, we develop and test the use of a recently-developed fast direct solver for least squares problems to solve high frequency scattering problems on general (non-axisymmetric) smooth objects using the MFS. |