  We present a computational framework for efficient optimization-based
"inverse design" of large-area "metasurfaces" (subwavelength-patterned
surfaces) for applications such as multi-wavelength and multi-angle
optimizations, and demultiplexers. To optimize surfaces that can be thousands
of wavelengths in diameter, with thousands (or millions) of parameters, the key
is a fast approximate solver for the scattered field. We employ a "locally
periodic" approximation in which the scattering problem is approximated by a
composition of periodic scattering problems from each unit cell of the surface,
and validate it against brute-force Maxwell solutions. This is an extension of
ideas in previous metasurface designs, but with greatly increased flexibility,
e.g. to automatically balance tradeoffs between multiple frequencies, or to
optimize a photonic device given only partial information about the desired
field. Our approach even extends beyond the metasurface regime to
non-subwavelength structures where additional diffracted orders must be
included (but the period is not large enough to apply scalar diffraction
theory).
