  The optimal control of magnetization dynamics in a ferromagnetic sample at a
microscopic scale is studied. The dynamics of this model is governed by the
Landau-Lifshitz-Gilbert equation on a two-dimensional bounded domain with the
external magnetic field (the control) applied through the effective field. We
prove the global existence and uniqueness of a regular solution in $\mathbb
S^2$ under a smallness condition on control and initial data. We establish the
existence of optimal control and derive a first-order necessary optimality
condition using the Fr\'echet derivative of the control-to-state operator and
adjoint problem approach.
