How do we apply Ampère's law for non-planar loops?

How do we apply Ampère's (magnetism) law for non-planar loops?

Its most general form(or you can say the only one I know) is $$\oint_C \mathbf B\cdot\mathrm d\mathbf l = \mu_0 \iint_S\mathbf J\cdot \mathrm d\mathbf S$$ But what would current enclosed mean in case of non planar loops. I mean infinite amount of curves can contain such loop. As a result while the right-hand side (line integral of B field) would same in each but the integral of current density would be different for each curve (surface or manifold).

• Could you please state, which form of Ampère's law you are referring to? In the form I know the current is arbitrary, so it doesn't have to be restricted to a loop. – Photon Mar 30 '17 at 8:54
• Is one of the sides of the equation an integral of the current density or is it just the total current? – Photon Mar 30 '17 at 8:58
• Ok, you need the form, where the integral of the current density is not yet done, like the first and second part of this equation: wikimedia.org/api/rest_v1/media/math/render/svg/… – Photon Mar 30 '17 at 9:00
• What would current enclosed mean in case of non planar loops? Infinte amount of curves can pass through such loop – Prayas Agrawal Mar 30 '17 at 9:02
• An infinite amount of curves can pass through a planar loop as well. Just choose any, which is easy to integrate. – Photon Mar 30 '17 at 9:17

The problem with Ampère's law, for any kind of loop (including planar loops!) is that there are plenty of surfaces $S$ that share the same boundary $C=\partial S$, which makes the statement $$\oint_C \mathbf B\cdot\mathrm d\mathbf l = \mu_0 \iint_S\mathbf J\cdot \mathrm d\mathbf S$$ a bit suspect, unless we can (a) choose a canonical surface $S$ for each curve $C$, or (b) show that the surface integral on the right-hand side is actually independent of what surface we choose.
The resolution to this is, in fact, (b): the current flow really is independent of the surface you choose. To prove this, consider two surfaces $S_1$ and $S_2$ which share the same boundary $C$, so that we want to prove that $$\iint_{S_1}\mathbf J\cdot \mathrm d\mathbf S = \iint_{S_2}\mathbf J\cdot \mathrm d\mathbf S,$$ or, equivalently, that $${\large\bigcirc}\kern-1.55em\iint_{S}\mathbf J\cdot \mathrm d\mathbf S = \iint_{S_1}\mathbf J\cdot \mathrm d\mathbf S - \iint_{S_2}\mathbf J\cdot \mathrm d\mathbf S =0,$$ where $S$ is the closed surface that surrounds the space between $S_1$ and $S_2$.
Now, there's a bunch of ways to prove that that integral is indeed zero, but they all boil down to this: the closed surface integral $\mathop{\vcenter{ \unicode{x222F}}}_{S}\mathbf J\cdot \mathrm d\mathbf S$ represents the net amount of charge that enters the volume between $S_1$ and $S_2$ per unit time, and for a static situation, that net amount needs to be exactly zero, or you would have a linear growth of the enclosed charge in that volume, quickly taking you out of the static situation you thought you were in.
Of course, this does mean that Ampère's law as formulated here can no longer hold without modifications in dynamic situations - and, indeed, in that case you need to extend it to the Ampère-Maxwell law, which includes an additional term in the surface integral, and which again has the property that it holds regardless of what surface $S$ you choose to integrate over.