To solve the problem of broken lines we can use hand made code. First, we define interpolation functions for $B_x,B_z$ to exclude singularities as follows
Bx = Interpolation[
Flatten[Table[{x,
z, \[ScriptCapitalB]BarMagnet[{x, 0., z}, {1.5, .5,
5.5}] [[1]]}, {x, 0, 10, .1}, {z, 0, 10, .1}], 1]];
Bz = Interpolation[
Flatten[Table[{x,
z, \[ScriptCapitalB]BarMagnet[{x, 0., z}, {1.5, .5,
5.5}] [[3]]}, {x, 0, 10, .1}, {z, 0, 10, .1}], 1]];
Second, we compute field lines with
X1 = ParametricNDSolveValue[{z'[t] == Bz[x[t], z[t]],
x'[t] == Bx[x[t], z[t]], x[0] == x0, z[0] == z0},
x, {t, 0, 1000}, {x0, z0}];
Z1 =
ParametricNDSolveValue[{x'[t] == Bx[x[t], z[t]],
z'[t] == Bz[x[t], z[t]], x[0] == x0, z[0] == z0},
z, {t, 0, 1000}, {x0, z0}];
Finally we plot stream lines with StreamPlot[]
and ParametricPlot[]
, and show in one plot
sp = StreamPlot[{Bx[x, z], Bz[x, z]} , {x, 0, 10}, {z, 0, 10},
PlotRange -> All,
StreamPoints -> Fine,
AspectRatio -> Automatic, Frame -> None,
StreamColorFunction -> "Rainbow", StreamScale -> None,
VectorPoints -> Fine, PerformanceGoal -> "Quality",
MaxRecursion -> 2];
ppxz = ParametricPlot[
Table[{X1[x0, 0.01][t], Z1[x0, 0.01][t]}, {x0, .1, .5, .1}], {t, 0,
1000}, PlotStyle -> Red];
Show[sp, ppxz]