Accurate and easy method for work function calculations