Fast Large-Scale Electromagnetic Simulation of Doubly Periodic Structures in Layered Media