Variational formulation for a magnetic field on dual meshes