function [res] = InProd_uv(u1,u2,v1,v2, Nodeu, Nodev, dx, dy, idsP)
% function [res] = InProd_uv(u1,u2,v1,v2, Nodeu, Nodev, dx, dy, idsP)
% This function takes the inner product of <u1,u2>+<v1,v2> over the domain  
%
% INPUTS:
%       u:      Vector containing values of u
%       P:      Vector containing values of Pressure
%       NodeU:  Reference node numbering matrix for u-velocity 
%       NodeP:  Reference node numbering matrix for Pressure
%       dx:     delta x, grid spacing in x direction
%       dy:     delta y, grid spacing in y direction
%       idsP:   Location of unmasked Pressure nodes in interior
%       
% OUTPUTS:
%       res:    Returns sum((u1 * u2 + v1 * v2) * dx * dy)
%
% Authors:   Matt Ueckermann, Pierre Lermusiaux, Pat Haley for MIT course 2.29

[Ny,Nx]=size(Nodeu);
Nx=Nx+1;
idsux=2:Nx-1;
idsuy=2:Ny-1;
idsvx=2:Nx-1;
idsvy=2:Ny-1;
resx = (u1(Nodeu(idsuy,idsux-1))+u1(Nodeu(idsuy,idsux)))...
     .*(u2(Nodeu(idsuy,idsux-1))+u2(Nodeu(idsuy,idsux)));
resx = sum(resx(idsP))*0.25*dx*dy;
resy = (v1(Nodev(idsvy-1,idsvx))+v1(Nodev(idsvy,idsvx)))...
     .*(v2(Nodev(idsvy-1,idsvx))+v2(Nodev(idsvy,idsvx)));
resy = sum(resy(idsP))*0.25*dx*dy;
res = (resx+resy);
