A modal approach for analysing optical systems with applications to solar light trapping and digital removal of GRIN lens aberrations