Dual harmonic systems have been widely used in high intensity proton synchrotrons to suppress the space charge effect, as well as reduce the beam loss. To investigate the longitudinal beam dynamics in a dual rf system, the potential well, the sub-buckets in the bunch and the multi-solutions of the phase equation are studied theoretically in this paper. Based on these theoretical studies, optimization of bunching factor and rf voltage waveform are made for the dual harmonic rf system in the upgrade phase of the China Spallation Neutron Source Rapid Cycling Synchrotron （CSNS/RCS）. In the optimization process, the simulation with space charge effect is done using a newly developed code. C-SCSIM.