time | calls | line |
---|
| | 1 | function [dudx, dvdy] = Grad2D_uv(u, v, Nodeu, Nodev, idsP, dx, dy, bcN_ID_u, bcN_ID_v)
|
| | 2 | % function [dudx, dvdy] = Grad2D_uv(u, v, Nodeu, Nodev, idsP, dx, dy, bcN_ID_u, bcN_ID_v)
|
| | 3 | % This function computes du/dx and dv/dy in the centers of active P cells.
|
| | 4 | %
|
| | 5 | % INPUTS:
|
| | 6 | % u: Vector containing values of u
|
| | 7 | % v: Vector containing values of v
|
| | 8 | % Nodeu: Reference node numbering matrix for u-velocity
|
| | 9 | % Nodev: Reference node numbering matrix for v-velocity
|
| | 10 | % idsP: Location of active pressure cells in interior
|
| | 11 | % dx: Mesh spacing in x direction
|
| | 12 | % dy: Mesh spacing in y direction
|
| | 13 | % bcN_ID_u: Array with two entries giving the lowest and highest ID of the
|
| | 14 | % Neumann boundary conditions for the u-velocity
|
| | 15 | % bcN_ID_v: Array with two entries giving the lowest and highest ID of the
|
| | 16 | % Neumann boundary conditions for the u-velocity
|
| | 17 | %
|
| | 18 | % OUTPUTS:
|
| | 19 | % dudx: du/dx returned at the centers of active pressure cells
|
| | 20 | % dvdy: dv/dy returned at the centers of active pressure cells
|
| | 21 | %
|
| | 22 | % Date: Jan. 2014
|
| | 23 | % Authors: Jing Lin
|
| | 24 |
|
| | 25 |
|
| | 26 | %% Preliminary step for du/dx
|
| | 27 |
|
| | 28 | % Find the left and right u cells (including boundaries) for each interior P cell
|
3.98 | 1640 | 29 | uR = u(Nodeu(2:end-1, 2:end ));
|
3.69 | 1640 | 30 | uL = u(Nodeu(2:end-1, 1:end-1));
|
| | 31 |
|
| | 32 | % Take discrete x derivative
|
3.93 | 1640 | 33 | dudx = (uR - uL)/dx;
|
| | 34 |
|
| | 35 |
|
| | 36 | %% Correct the discrete derivatives at Neumann boundaries for du/dx
|
| | 37 |
|
| | 38 | % Find right and left u cells that are actually Neumann boundaries
|
6.99 | 1640 | 39 | bcN_R = logical((Nodeu(2:end-1, 2:end) >= bcN_ID_u(1))...
|
| | 40 | .*(Nodeu(2:end-1, 2:end) <= bcN_ID_u(2)));
|
7.17 | 1640 | 41 | bcN_L = logical((Nodeu(2:end-1, 1:end-1) >= bcN_ID_u(1))...
|
| | 42 | .*(Nodeu(2:end-1, 1:end-1) <= bcN_ID_u(2)));
|
0.15 | 1640 | 43 | Cell_LL = false(size(bcN_R)); Cell_LL(:, 1:end-1) = bcN_R(:, 2:end);
|
0.35 | 1640 | 44 | Cell_RR = false(size(bcN_L)); Cell_RR(:, 2:end) = bcN_L(:, 1:end-1);
|
| | 45 |
|
| | 46 | % Assign the boundary x-derivative
|
1.36 | 1640 | 47 | dudx(bcN_R) = 2/3*uR(bcN_R) + (uL(bcN_R) - uL(Cell_LL))/(3*dx);
|
1.27 | 1640 | 48 | dudx(bcN_L) = -2/3*uL(bcN_L) - (uR(bcN_L) - uR(Cell_RR))/(3*dx);
|
| | 49 |
|
0.74 | 1640 | 50 | dudx = dudx(idsP);
|
| | 51 |
|
| | 52 |
|
| | 53 | %% Preliminary step for dv/dy
|
| | 54 |
|
| | 55 | % Find top (R) and bottom (L) v cells (including boundaries) for each interior P cell
|
4.85 | 1640 | 56 | uR = v(Nodev(1:end-1, 2:end-1));
|
3.55 | 1640 | 57 | uL = v(Nodev(2:end , 2:end-1));
|
| | 58 |
|
| | 59 | % Take discrete y derivative
|
3.57 | 1640 | 60 | dvdy = (uR - uL)/dy;
|
| | 61 |
|
| | 62 |
|
| | 63 | %% Correct the discrete derivatives at Neumann boundaries for dv/dy
|
| | 64 |
|
| | 65 | % Find top (R) and bottom (L) v cells that are actually Neumann boundaries
|
6.83 | 1640 | 66 | bcN_R = logical((Nodev(1:end-1, 2:end-1) >= bcN_ID_v(1))...
|
| | 67 | .*(Nodev(1:end-1, 2:end-1) <= bcN_ID_v(2)));
|
6.45 | 1640 | 68 | bcN_L = logical((Nodev(2:end,2:end-1) >= bcN_ID_v(1))...
|
| | 69 | .*(Nodev(2:end, 2:end-1) <= bcN_ID_v(2)));
|
0.24 | 1640 | 70 | Cell_LL = false(size(bcN_R)); Cell_LL(2:end, :) = bcN_R(1:end-1, :);
|
0.37 | 1640 | 71 | Cell_RR = false(size(bcN_L)); Cell_RR(1:end-1, :) = bcN_L(2:end, :);
|
| | 72 |
|
| | 73 | % Assign the boundary y-derivative
|
0.70 | 1640 | 74 | dvdy(bcN_R) = 2/3*uR(bcN_R) + (uL(bcN_R) - uL(Cell_LL))/(3*dy);
|
0.70 | 1640 | 75 | dvdy(bcN_L) = -2/3*uL(bcN_L) - (uR(bcN_L) - uR(Cell_RR))/(3*dy);
|
| | 76 |
|
0.89 | 1640 | 77 | dvdy = dvdy(idsP);
|