Must magnetic field lines close upon themselves or go to infinity? Conventional wisdom tells us that magnetic field lines must either form closed loops, or shoot off to infinity. However, this leaves out the possibility that a magnetic field line, even if it stays confined inside a compact region of space, can in principle come back to close to its starting point but miss it, forming a quasi-loop that never quite closes.
In particular, I suspect it's possible to set this up using a twisted-torus magnetic field like the ones in a tokamak, where by controlling the relative strengths of the toroidal and poloidal components one can engineer situations where magnetic field lines close upon themselves after $N_\mathrm{t}$ toroidal loops around the torus and $N_\mathrm{p}$ poloidal loops about it, but one can also engineer things such that this never quite happens and the magnetic field line occupies a dense subset of a surface (or even a dense subset of space?).

 Image source
Alas, in looking for an explicit expression for such a field I got drowned in technical results for tokamaks and magnetic fields in neutron stars, so I'll just leave this here in case someone wants to have a crack at it.
Is this possible? I'm for now mostly interested in results for this specific configuration, but if this configuration won't work (i.e. if some result guarantees that field lines in this setting do close upon themselves) then I'm also interested in examples from further afield.
 A: I had the same question a few years ago, both for magnetic field lines and for current lines in the quasi-static approximation. The following papers from the American Journal of Physics convinced me that, indeed, magnetic field lines are not always closed or extending to infinity.


*

*"Lines of force in electric and magnetic fields": J. Slepian, Am. J. Phys. 19 no. 2, 87 (1951)

*"Topology of steady current magnetic fields", K.L. McDonald, Am. J. Phys. 22 no. 9, 586 (1954)

*"The magnetic fields lines of a helical coil are not simple loops", M. Lieberherr, Am. J. Phys. 78 no. 11, 1117 (2010)
A: Nope. Conventional wisdom is wrong about this one. Magnetic field lines can have much more interesting configurations.
Magnetic field lines are trajectories of Hamiltonian systems and, as such, are typically chaotic, which means they never close on themselves (if they did, they'd be periodic, not chaotic). This case is made very clear in this paper by Phil Morrison: Magnetic field lines, Hamiltonian dynamics, and nontwist systems (e-print, without figures).
The dense covering of a toroidal surface you mention is also typical: in fact, these so-called quasiperiodic lines are infinitely more common than their periodic counterparts - essentially because irrational numbers are infinitely more common than rational numbers.
Again, in the same way that a real-life mechanical system is typically chaotic rather than periodic, real life magnetic fields will most often also be chaotic, even for simple configurations and that's actually probably good.
In the image bellow, electric current flows through the black lines (belonging to two perpendicular wire loops), generating the field line showed in red. From a paper that makes a good case that

chaotic magnetic-field lines are ubiquitous in the modern technological world.


