Modeling the distribution of dark matter and its connection to galaxies