What is the connection between the magnetization of a thermodynamic system, the magnetic fields, and the free energy? From multiple textbooks I gather

*

*The first law of thermodynamics: $$dU = \delta Q + \delta W = TdS + \delta W$$

*The definition of the free energy: $$F = U - TS \Rightarrow dF = -SdT + \delta W$$

*The connection between the magnetization and the magnetic fields: $$\vec{B} = \vec{H} + 4\pi\vec{M}$$

*The way authors like to "find" the magnetization of a thermodynamic system: $$\vec{M}(\vec{H}) = -\frac{1}{V}\frac{\partial U}{\partial\vec{H}} = -\frac{1}{V}\frac{\partial F}{\partial\vec{H}}$$
Can (4) be considered as the definition of the magnetization $\vec{M}$, and in turn (3) as the definition of the effective field $\vec{H}$ ? Or is (3) the definition of $\vec{H}$, and (4) can be derived from some electrostatic energy argument? In any case, what is the explicit form of $U(\vec{M})$ ? Is $U$ also a function of $\vec{B}$ or $\vec{H}$ ?
 A: I would start from the Electrodynamic Lagrangian in matter, which can be justified by the fact that one can derive Maxwell's equations from it.
It is fairly easy to see (harder to prove :-)) that the energy due to magnetization field will be (ignoring constants):
$$
U_B=\int_V d^3 r \mathbf{B}.\mathbf{M}=\int_V d^3 r \mathbf{H}.\mathbf{M}+\int_V d^3 r M^2
$$
The change in energy is therefore :
$$
\delta U_B=\int_V d^3 r \delta\mathbf{H}.\mathbf{M}+\int_V d^3 r \mathbf{H}.\delta \mathbf{M}+2\int_V d^3 r \mathbf{M}.\delta\mathbf{M}
$$
Imagine we are changing state of the system along the trajectory that keeps magnetization fixed (so $\delta \mathbf{M}=\mathbf{0}$), and that change $\delta\mathbf{H}$ is constant over volume $V$:
$$
\left(\frac{\partial U_b}{\partial \mathbf{H}}\right)_{\mathbf{M}}=\int_V d^3 r \mathbf{M}
$$
You can get rid of the integral if the magnetization is constant over volume $V$
A: One can typically divide the state functions $\{\mathbf{X}\}$ into a set of generalized displacement $\{\mathbf{x}\}$, and their conjugate generalized forces $\{\mathbf{J}\}$, such that
$$\delta W=\sum_iJ_idx_i$$
In the case of Magnets, Force is a Magnetic field $J_i=B$ and displacement is magnetic dipole moment $m$.
In this respect, the first law of thermodynamics can be written as
$$dU=TdS-mdB$$
$$dF=-SdT-mdB$$
where $B=\mu_0(H+M)$.

There isn't any special definition for magnetization, It's the same all over. We can write magnetization as various partial derivatives using the above.
$$M=\frac{m}{V}=-\frac{1}{V}\left.\frac{\partial F}{\partial B}\right|_T$$

In general, there isn't any explicit expression for $U$. Any state function can be a function of any number of variables depending on system, but mostly two for fixed particles. From the first partial, You can take $U=U(S, B)$.
