1. A method for calculating and using adjoint gradients in a reservoir simulator, comprising: (a) calculating adjoint gradients of an objective function with respect to changes in valve settings while taking into account a modeling of pressure drop and fluid flow along a wellbore; (b) in response to the calculated adjoint gradients, calculating sensitivities of a reservoir responsive to changes in parameterization of downhole devices; and (c) in response to the calculated sensitivities, using said sensitivities to optimize control of wells in a reservoir by optimizing an objective function.