  Large-scale cosmological simulations of galaxy formation currently do not
resolve the densities at which molecular hydrogen forms, implying that the
atomic-to-molecular transition must be modeled either on the fly or in
postprocessing. We present an improved postprocessing framework to estimate the
abundance of atomic and molecular hydrogen and apply it to the IllustrisTNG
simulations. We compare five different models for the atomic-to-molecular
transition, including empirical, simulation-based, and theoretical
prescriptions. Most of these models rely on the surface density of neutral
hydrogen and the ultraviolet (UV) flux in the Lyman-Werner band as input
parameters. Computing these quantities on the kiloparsec scales resolved by the
simulations emerges as the main challenge. We show that the commonly used Jeans
length approximation to the column density of a system can be biased and
exhibits large cell-to-cell scatter. Instead, we propose to compute all surface
quantities in face-on projections and perform the modeling in two dimensions.
In general, the two methods agree on average, but their predictions diverge for
individual galaxies and for models based on the observed midplane pressure of
galaxies. We model the UV radiation from young stars by assuming a constant
escape fraction and optically thin propagation throughout the galaxy. With
these improvements, we find that the five models for the atomic-to-molecular
transition roughly agree on average but that the details of the modeling matter
for individual galaxies and the spatial distribution of molecular hydrogen. We
emphasize that the estimated molecular fractions are approximate due to the
significant systematic uncertainties.
