  This work presents an efficient method for evaluation of wave scattering by
doubly periodic diffraction gratings at or near "Wood anomaly frequencies". At
these frequencies, one or more grazing Rayleigh waves exist, and the lattice
sum for the quasi-periodic Green function ceases to exist. We present a
modification of this sum by adding two types of terms to it. The first type
adds linear combinations of "shifted" Green functions, ensuring that the
spatial singularities introduced by these terms are located below the grating
and therefore outside of the physical domain. With suitable coefficient choices
these terms annihilate the growing contributions in the original lattice sum
and yield algebraic convergence. Convergence of arbitrarily high order can be
obtained by including sufficiently many shifts. The second type of added terms
are quasi-periodic plane wave solutions of the Helmholtz equation which
reinstate certain necessary grazing modes without leading to blow-up at Wood
anomalies. Using the new quasi-periodic Green function, we establish, for the
first time, that the Dirichlet problem of scattering by a smooth doubly
periodic scattering surface at a Wood frequency is uniquely solvable. We also
present an efficient high-order numerical method based on the this new Green
function for the problem of scattering by doubly periodic three-dimensional
surfaces at and around Wood frequencies. We believe this is the first solver in
existence that is applicable to Wood-frequency doubly periodic scattering
problems. We demonstrate the proposed approach by means of applications to
problems of acoustic scattering by doubly periodic gratings at various
frequencies, including frequencies away from, at, and near Wood anomalies.
