Calculation of electromagnetic forces in superconducting magnets