function [dpdx, dpdy] = Grad2D_P(P, NodeP, dx, dy, idsu, idsv)
% function [dpdx, dpdy] = Grad2D_P(P, NodeP, dx, dy, idsu, idsv)
% This function takes the gradient of pressure P, i.e. dP/dx and dP/dy,
% at the INTERIOR cell centers of u and v, respectively. 
%
% INPUTS:
%       P:      Vector containing values of pressure
%       NodeP:  Reference node numbering matrix for pressure
%       dx:     Mesh spacing in x direction
%       dy:     Mesh spacing in y direction
%       idsu:   Location of active u-velocity cells in interior
%       idsv:   Location of active v-velocity cells in interior
%       
% OUTPUTS:
%       dpdx:   x-derivative of pressure at centers of active u-velocity cells
%       dpdy:   y-derivative of pressure at centers of active v-velocity cells
%
% Authors:   Matt Ueckermann, Pierre Lermusiaux, Pat Haley for MIT course 2.29

dpdx = (P(NodeP(2:end-1, 3:end-1)) - P(NodeP(2:end-1, 2:end-2)))/dx;
dpdy = (P(NodeP(2:end-2, 2:end-1)) - P(NodeP(3:end-1, 2:end-1)))/dy;

dpdx = dpdx(idsu);
dpdy = dpdy(idsv);
