Energy calculation of a permanent magnet system by surface and flux integrals (the flux-mmf method)