(* AdjointFinder: If you use this in your research or teaching, please cite the webpage: 
https://gokulhari.github.io/webpage/AdjointFinder.html
and the paper:
G.Hariharan, S.Kumar, and M.R.Jovanovic, Well-conditioned ultraspherical and spectral integration methods for resolvent analysis of channel flows of Newtonian and viscoelastic fluids, Phys.Rev.Fluids, 2020, note:Submitted}
Written by Gokul Hariharan (harih020@umn.edu)
*)

Once[Get["~/Desktop/AdjointFinder.wl"]] (* Call this once, adjust this based on where you store the pack *)
(* Call Clear[AdjointFinder`] to clear all functions in this context *)

(*Define the equations for linearized Navier-Stokes equations in the evolution form, see Chapter 3 of Stability and transitions in shear flow by Schmid and Henningson *)
(* Note: here k2 = (kx^2) + (kz^2) and k4 = (k2^2) *)
veq = omega*(v''[y] - k2 v[y]) +I kx U[y](v''[y]-k2 v[y]) -I kx U''[y]v[y]-(1/R)(v''''[y]-k2 v''[y] +k4 v[y]);
etaeq = omega*eta[y] + I kx U'[y]v[y] + I kx U  eta[y] - (1/R)(eta''[y]-k2 eta[y]);

{eqAd,eqBc} = Adjoint[{veq,etaeq},{v[-1],eta[-1],v'[-1]},{v[1],eta[1],v'[1]},{y,-1,1},{v,eta,4}];
Print["Adjoint Equations: "]
Print[eqAd]
Print["Adjoint Boudary conditions: "]
Print[eqBc]