Density dependence of the nuclear symmetry energy constrained by mean-field calculations