Self-consistent determination of the electrostatic potential barrier due to the photoelectron sheath near a spacecraft