Theory and simulation of the formation and erasure of space-charge gratings in photoconductive polymers