A systematic methodology for formulating,implementing,solving and verifying discrete adjoint of the compressible Reynolds-averaged Navier-Stokes(RANS) equations for aerodynamic design optimization on unstructured meshes is proposed.First,a general adjoint formulation is constructed for the entire optimization problem,including parameterization,mesh deformation,flow solution and computation of the objective function,which is followed by detailed formulations of matrix-vector products arising in the adjoint model.According to this formulation,procedural components of implementing the required matrix-vector products are generated by means of automatic differentiation(AD) in a structured and modular manner.Furthermore,a duality-preserving iterative algorithm is employed to solve flow adjoint equations arising in the adjoint model,ensuring identical convergence rates for the tangent and the adjoint models.A three-step strategy is adopted to verify the adjoint computation.The proposed method has several remarkable features:the use of AD techniques avoids tedious and error-prone manual derivation and programming;duality is strictly preserved so that consistent and highly accurate discrete sensitivities can be obtained;and comparable efficiency to hand-coded implementation can be achieved.Upon the current discrete adjoint method,a gradient-based optimization framework has been developed and applied to a drag reduction problem.