# Magnetic field in infinite cylinder with current density

Consider an infinite cylinder (in $z$) and with external radius also infinite. In the cylinder flows a current defined by a superficial current density given by:

$$J(r, \theta) = \frac{J_{0} R^2}{r^2}\cos(\theta) \qquad \left[\text{with unit }\frac{\rm A}{\rm m^2}\right]$$

Evaluate the $x$ and $y$ components of the magnetic field in point $P$.

The schematic is, Here are my attempts:

If I get the idea correctly, there is no current flowing in the inside wire, i.e., $r \leq R$, only for $r > R$.

I have drawn an amperian loop $\mathscr{C}$ with radius $r$, such that $r > R$ and applied Ampere's Law to it.

$$\nabla \times \vec{H} = \vec{J}$$ $$\oint_\mathscr{C} \vec{H} \cdot d\vec{l} = \int_S \vec{J} \cdot d\vec{S}$$

$$I_\text{enclosed} \equiv \int_S \vec{J} \cdot d\vec{S}$$.

Ok, so changing to polar coordinates, we will have $dS = r\ dr\ d\theta$. If I define $d\vec{S}$ outwards the cross section as is $\vec{J}$, we get

$$I_\text{enclosed} \equiv \int_S J dS = \int \int \frac{J_{0} R^2}{r^2}\cos(\theta)\cdot r\ dr\ d\theta$$

Here's the issue: should I integrate $r$ for $R < r < +\infty$? If so, then the integral diverges. Should I integrate $\theta$ for $0 < \theta < 2 \pi$? Then the magnetic field is null, which is inconsistent, since in that region there is a current enclosed by the Amperian loop.

Note that your current distribution has a "supply" current where $0<|\theta|<\frac{2\pi}4$ and an opposing "return" current on the other side of the cylinder. That current distribution has a different set of symmetries than your Amperian loop that's a circle at constant $r$, so unlike in the straight-wire case, you can't assume that $\oint \vec H \cdot d\vec\ell = 0$ corresponds to $\vec H = 0$. Your circle has rotational symmetry, but your current distribution has reflection (anti-)symmetry about the $x$- and $y$-axes. That suggests that sections of the curves $x=0$ and $y=0$ would be interesting to include as segments in your Amperian loop.