Theory of multilayer solar cells