Modelling photoluminescence from small particles 1. General formalism and a simple reference implementation