A general method for the computation of electromagnetic scattering problems