  Defect physics of europium (Eu) doped GaN is investigated using
first-principles hybrid density-functional defect calculations. This includes
the interaction between the rare-earth dopant and native point defects (Ga and
N vacancies) and other impurities (O, Si, C, H, and Mg) unintentionally present
or intentionally incorporated into the host material. While the trivalent
Eu$^{3+}$ ion is often found to be predominant when Eu is incorporated at the
Ga site in wurtzite GaN, the divalent Eu$^{2+}$ is also stable and found to be
predominant in a small range of Fermi-level values in the band-gap region. The
Eu$^{2+}$/Eu$^{3+}$ ratio can be tuned by tuning the position of Fermi level
and through defect association. We find co-doping with oxygen can facilitate
the incorporation of Eu into the lattice. The unassociated Eu$_{\rm Ga}$ is an
electrically and optically active defect center and its behavior is profoundly
impacted by local defect--defect interaction. Defect complexes such as Eu$_{\rm
Ga}$-O$_{\rm N}$, Eu$_{\rm Ga}$-Si$_{\rm Ga}$, Eu$_{\rm Ga}$-H$_i$, Eu$_{\rm
Ga}$-Mg$_{\rm Ga}$, and Eu$_{\rm Ga}$-O$_{\rm N}$-Mg$_{\rm Ga}$ can efficiently
act as deep carrier traps and mediate energy transfer from the host into the
Eu$^{3+}$ $4f$-electron core which then leads to sharp red intra-$f$
luminescence. Eu-related defects can also give rise to defect-to-band
luminescence. The unassociated Eu$_{\rm Ga}$, for example, is identified as a
possible source of the broad blue emission observed in n-type,
Eu$^{2+}$-containing GaN. This work calls for a re-assessment of certain
assumptions regarding specific defect configurations previously made for
Eu-doped GaN and further investigation into the origin of the photoluminescence
hysteresis observed in (Eu,Mg)-doped samples.
