The unsteady partial differential equations (UPDE) with convection term gives a clear descriptions for the solidification process of a slab in dynamic production of continuous casting. To give a suitable setting value of secondary cooling water flow rate for the dynamic control system, this study investigates an optimal control problem (OCP) of UPDE with convection term. Firstly, control vector discretization of OCP and the solution of UPDE are given. Secondly, due to the rapidity for gradient, this paper analyzes the expression of the gradient calculation method based on Hamiltonian function costate system by approximate treatment, matrix calculation and composite trapezoidal integral method. Thirdly, an improved three-term spectrum conjugate gradient algorithm (ITSCGA) is proposed to solve the OCP of UPDE, and the global convergence of the ITSCGA is demonstrated. Lastly, the performance of ITSCGA is demonstrated by experimental simulations. The results demonstrate that the ITSCGA provides a smaller temperature fluctuations, and improves the quality of a slab.