Twisted boundary conditions in lattice simulations