Derivation of Discrete Adjoint Method for Sensitivity Analysis in Marine Energy Systems