Gratings: Theory and Numeric Applications