Direction of the force on a current-carrying wire, related to the energy of the magnetic field Suppose I have a current-carrying wire with current $I$ coming out of the page, along the z axis. Its field is superposed on a uniform magnetic field $B$ in the x direction (to the right), which exists for $a\le y\le b$ ($a\le0$, $b\ge0$). Below is my attempt to represent what I think the field lines look like, using a combination of software and hand drawing:

Now suppose we keep $b-a$ constant but move the wire up and down relative to the slab of uniform field. The condition where the wire is at the top of the slab ($b=0$) clearly has more energy in the magnetic field (for a given length $\ell$) than the condition where the wire is at the bottom. This means that the wire should experience a downward force, i.e., magnetic field energy could be released by moving the wire down, and this energy could be used to do work.
But this is the opposite of the correct direction for the Lorentz force, so now I'm baffled. What is wrong with this argument?
To see if I could tease out the mistake, I went ahead and did the integral. The superposition of the field has an energy proportional to $\int \textbf{B}_1\cdot\textbf{B}_2 dv$ plus terms independent of the position of the wire, where $\textbf{B}_1$ is the uniform field and $\textbf{B}_2$ is the field of the wire. If I do the integral for a slab of volume of length $\ell$ in the z direction, I get $IB\ell h+\text{const}$, where $h=|a|$ and const. means a term that doesn't vary if $b-a$ is held fixed. The force on the wire per unit length is then $IB\ell$, which is the expected result, but the force still seems to be in the wrong direction. 
To create the uniform part of the magnetic field, we need to have a sheet of current coming out of the page at $y=b$, and a sheet going into the page at $y=a$. These should cause an upward force on the wire, agreeing with the Lorentz force law and disagreeing with the energy analysis.
It seems like I can also make a version that is geometrically simpler. If I get rid of the wire, then I just have two oppositely directed sheets of current. The Lorentz force law says that these sheets repel each other, and this also makes sense because the magnetic field contributes a $y$ pressure to the stress-energy. But the energy of the field (per unit of xz area) is clearly going to increase if the sheets get farther apart.
What is wrong with my reasoning here?
 A: Here's a more familiar situation that illustrates the same kind of paradox: Two parallel wires carrying equal currents (same magnitude, same sign) attract each other. But given two parallel wires each carrying a fixed current $I$, the total energy in their combined magnetic field is greater when the wires are closer together. Does this mean that energy is not conserved in this situation?
Answer: Yes, that's exactly what it means! Conservation of energy only holds in a model with no time-dependent external influences. But we need a time-dependent external influence in order to keep the currents constant as the wires start to move. If we extend the model to include other dynamic entities that are somehow arranged to keep the currents constant, then we will find that the total energy of that whole system is conserved. 
Suppose instead that we consider a model that does not have any such influences. In this case, the currents in the wires will decrease when the wires start to appraoch each other. To see why, think of the individual charges moving along one of the wires. The force on a charge in wire $1$ due to the magnetic field of wire $2$ is proportional to $\nabla\times\mathbf{B}_2$. The charge wants to move in a circular arc that bends toward the other wire. But as the charge follows that circular arc, it's not just moving toward the other wire; it's speed remains constant, which means that the component of its velocity parallel to the wire must be decreasing. In other words, the current in the wire is decreasing. 
The same reasoning applies in the situation you described.
I haven't done this calculation explicitly, but I'll bet that if you do this calculation, accounting for the decreasing current in this way, you'll find that the total energy does not change.
