I need help understanding Ampere's circuital law. Consider a square shaped iron core with an N turn coil on one side. Let each side of the core has the length a an has equal cross-section. The textbook approach is to take a closed contour passing through the middle of the core. All magnetic flux is inside the core, so we have (given the coil current I)
NI = aH + aH + aH + aH
But what if I take a contour that pass inside the coil and then goes outside? Outside the core there is no (or very little) magnetic field, so
NI = aH + 0
The two equations do not match. What is wrong?
After reading comments and thinking on the problem I have advice for future readers.
Magnetic flux concentrates inside the core. This is true enough to assume that flux is constant along the core, but not enough to assume that field in the air is zero.
From Ampere's circuital law we may conclude that H field must be stronger in the surrounding air that in the core to satisfy the law for different contours. B field on the other hand is much stronger inside the core than outside because it is proportional to the flux.
I have modeled the problem in the FEMM and attach supporting figures below. If someone wants to model it himself, be careful not to saturate the core; otherwise you'll get disturbed field distribution.