  Within the framework of the quantum molecular dynamics transport model, the
pion production and constraint of the high-density symmetry energy in heavy-ion
collisions near threshold energy have been thoroughly investigated. The energy
conservation in the decay of resonances and reabsorption of pions as well as in
the inelastic nucleon-nucleon and nucleon-resonance collisions are taken into
account. The isospin diffusion in the low-density region (0.2$\rho_{0}$ -
0.8$\rho_{0}$) and high-density region (1.2$\rho_{0}$ - 1.8$\rho_{0}$) is
investigated by analyzing the spectra of neutron/proton and $\pi^{-}/\pi^{+}$
ratios in the isotopic reactions of $^{132}$Sn + $^{124}$Sn and $^{108}$Sn +
$^{112}$Sn at the incident energy of 270 MeV/nucleon, in which the symmetry
energy manifests the opposite effect in the different density domain. The
controversial conclusion of the $\pi^{-}/\pi^{+}$ ratio for constraining the
high-density symmetry energy by different transport models with the FOPI data
has been clarified. A soft symmetry energy with the slope parameter of
$L(\rho_{0}) = 42\pm 25$ MeV by using the standard error analysis within the
range of $1\sigma$ is obtained by analyzing the experimental data from the
S$\pi$RIT collaboration. The neutron stars with the maximal mass of 2
$M_{\odot}$ and radius of 11-13 km are obtained with the constrained symmetry
energy.
