Cooling of magnetars with internal layer heating