  We introduce a versatile numerical method for modeling light diffraction in
periodically patterned photonic structures containing quadratically nonlinear
non-centrosymmetric optical materials. Our approach extends the generalized
source method to nonlinear optical interactions by incorporating the
contribution of nonlinear polarization sources to the diffracted field in the
algorithm. We derive the mathematical formalism underlying the numerical method
and introduce the Fourier-factorization suitable for nonlinear calculations.
The numerical efficiency and runtime characteristics of the method are
investigated in a set of benchmark calculations: the results corresponding to
the fundamental frequency are compared to those obtained from a reference
method and the beneficial effects of the modified Fourier-factorization rule on
the accuracy of the nonlinear computations is demonstrated. In order to
illustrate the capabilities of our method, we employ it to demonstrate strong
enhancement of second-harmonic generated in one- and two-dimensional optical
gratings resonantly coupled to a slab waveguide. Our method can be easily
extended to other types of nonlinear optical interactions by simply
incorporating the corresponding nonlinear polarization sources in the
algorithm.
