Calculation of light distribution in optical devices by a global solution of an inhomogeneous scalar wave equation