Efficient generation of divergence-free fields for the finite element analysis of 3D cavity resonances