In this paper, we address the problem of maximizing the spectral gap of a divergence type diffusion operator. Our main application of interest is characterizing the distribution of a swarm of agents that evolve on a bounded domain in Rn according to a Markov process. A subclass of the divergence type operators that we introduce in this paper can describe the distribution of the swarm across the domain. We construct an operator that stabilizes target distributions that are bounded and strictly positive almost everywhere on the domain. Optimizing the spectral gap of the operator ensures fast convergence to this target distribution. The optimization problem is posed as the minimization of the second largest eigenvalue modulus (SLEM) of the operator (the largest eigenvalue is 0). We use the well-known Courant-Fisher min-max principle to characterize the SLEM. We also present a numerical scheme for solving the optimization problem, and we validate our optimization approach for two example target distributions.