Adjoint sensitivity analysis for nanophotonic structures