Construction of a finite element basis of the first de Rham cohomology group and numerical solution of 3D magnetostatic problems