| 1 |
|
| 2 |
function [mesh] = RectGridQuad(xmin, xmax, ymin, ymax, nx, ny) |
| 3 |
% |
| 4 |
% [mesh] = RectGridQuad(xmin, xmax, ymin, ymax, nx, ny) |
| 5 |
% |
| 6 |
%RECTGRID sets up the grid for piecewise linear elements |
| 7 |
% in a rectangular domain on quadrilateral cells. |
| 8 |
% |
| 9 |
% The grid is constructed by subdividing the x-interval into |
| 10 |
% nx subintervals and the y-interval into ny subintervals. |
| 11 |
% This generates a grid with nx*ny rectangular quadrilaterals. |
| 12 |
% |
| 13 |
% |
| 14 |
% |
| 15 |
% Input |
| 16 |
% xmin, xmax size of the rectangle |
| 17 |
% ymin, ymax |
| 18 |
% nx number of subintervals on x-interval |
| 19 |
% ny number of subintervals on y-interval |
| 20 |
% |
| 21 |
% Output |
| 22 |
% mesh structure array with the following fields |
| 23 |
% |
| 24 |
% mesh.p Real num_nodes x 2 |
| 25 |
% array containing the x- and y- coordinates |
| 26 |
% of the nodes |
| 27 |
% |
| 28 |
% mesh.t Integer num_cells x 4 |
| 29 |
% t(i,1:4) contains the indices of the vertices of |
| 30 |
% quadrilateral i. |
| 31 |
% |
| 32 |
% mesh.e Integer num_edges x 3 |
| 33 |
% e(i,1:2) contains the indices of the vertices of |
| 34 |
% edge i. |
| 35 |
% edge(i,3) contains the boundary marker of edge i. |
| 36 |
% Currently set to one. |
| 37 |
% e(i,3) = 1 Dirichlet bdry conds are imposed on edge i |
| 38 |
% e(i,3) = 2 Neumann bdry conds are imposed on edge i |
| 39 |
% e(i,3) = 3 Robin bdry conds are imposed on edge i |
| 40 |
% |
| 41 |
% mesh.sidesPerCell Integer = 4 (Quadrilateral) |
| 42 |
% |
| 43 |
% mesh.elem_ss{i} = global element IDs on sideset (boundary) i |
| 44 |
% |
| 45 |
% mesh.side_ss{i} = local side (subcell) IDs on sideset (boundary) i |
| 46 |
% |
| 47 |
% mesh.cellType = string for cell type (= 'Quadrilateral') |
| 48 |
% |
| 49 |
% mesh.sideType = string for side subcell type (= 'Line') |
| 50 |
% |
| 51 |
% |
| 52 |
% Vertical ordering: |
| 53 |
% The quadrilaterals are ordered column wise, for instance: |
| 54 |
% |
| 55 |
% 03 -------- 06 -------- 09 -------- 12 |
| 56 |
% | | | | |
| 57 |
% | 2 | 4 | 6 | |
| 58 |
% | | | | |
| 59 |
% 02 -------- 05 -------- 08 -------- 11 |
| 60 |
% | | | | |
| 61 |
% | 1 | 3 | 5 | |
| 62 |
% | | | | |
| 63 |
% 01 -------- 04 -------- 07 -------- 10 |
| 64 |
% |
| 65 |
% The vertices in a quadrilateral are numbered |
| 66 |
% counterclockwise, for example |
| 67 |
% quadrilateral 3: (04, 07, 08, 05) |
| 68 |
% quadrilateral 6: (08, 11, 12, 09) |
| 69 |
% |
| 70 |
% (Usually, the local grid.node numbering should not be important.) |
| 71 |
% |
| 72 |
% number of quadrilaterals: nx*ny, |
| 73 |
% number of vertices: (nx+1)*(ny+1), |
| 74 |
% |
| 75 |
% AUTHOR: |
| 76 |
% Denis Ridzal |
| 77 |
% Sandia National Laboratories |
| 78 |
|
| 79 |
|
| 80 |
nt = nx*ny; |
| 81 |
np = (nx+1)*(ny+1); |
| 82 |
|
| 83 |
% Create arrays |
| 84 |
mesh.t = zeros(nt,4); |
| 85 |
mesh.p = zeros(np,2); |
| 86 |
|
| 87 |
nxp1 = nx + 1; |
| 88 |
nyp1 = ny + 1; |
| 89 |
|
| 90 |
% Create quadrilaterals |
| 91 |
nt = 0; |
| 92 |
for ix = 1:nx |
| 93 |
for iy = 1:ny |
| 94 |
|
| 95 |
iv = (ix-1)*nyp1 + iy; |
| 96 |
iv1 = iv + nyp1; |
| 97 |
|
| 98 |
nt = nt + 1; |
| 99 |
mesh.t(nt,1) = iv; |
| 100 |
mesh.t(nt,2) = iv1; |
| 101 |
mesh.t(nt,3) = iv1+1; |
| 102 |
mesh.t(nt,4) = iv+1; |
| 103 |
|
| 104 |
end |
| 105 |
end |
| 106 |
|
| 107 |
% Create vertex coodinates |
| 108 |
|
| 109 |
hx = (xmax-xmin)/nx; |
| 110 |
hy = (ymax-ymin)/ny; |
| 111 |
x = xmin; |
| 112 |
|
| 113 |
for ix = 1:nx |
| 114 |
|
| 115 |
% set coordinates for vertices with fixed |
| 116 |
% x-coordinate at x |
| 117 |
i1 = (ix-1)*(ny+1)+1; |
| 118 |
i2 = ix*(ny+1); |
| 119 |
mesh.p(i1:i2,1) = x*ones(nyp1,1); |
| 120 |
mesh.p(i1:i2,2) = (ymin:hy:ymax)'; |
| 121 |
|
| 122 |
x = x + hx; |
| 123 |
end |
| 124 |
|
| 125 |
% set coordinates for vertices with fixed |
| 126 |
% x-coordinate at xmax |
| 127 |
i1 = nx*(ny+1)+1; |
| 128 |
i2 = (nx+1)*(ny+1); |
| 129 |
mesh.p(i1:i2,1) = xmax*ones(nyp1,1); |
| 130 |
mesh.p(i1:i2,2) = (ymin:hy:ymax)'; |
| 131 |
|
| 132 |
% Set grid.edge (edges are numbered counter clock wise starting |
| 133 |
% at lower left end). |
| 134 |
|
| 135 |
mesh.e = ones(2*(nx+ny),3); |
| 136 |
|
| 137 |
% edges on left on left boundary |
| 138 |
mesh.e(1:ny,1) = (1:ny)'; |
| 139 |
mesh.e(1:ny,2) = (2:ny+1)'; |
| 140 |
|
| 141 |
% edges on top boundary |
| 142 |
mesh.e(ny+1:nx+ny,1) = (ny+1:ny+1:np-1)'; |
| 143 |
mesh.e(ny+1:nx+ny,2) = (2*(ny+1):ny+1:np)'; |
| 144 |
|
| 145 |
% edges on right boundary |
| 146 |
mesh.e(nx+ny+1:nx+2*ny,1) = (np-ny:np-1)'; |
| 147 |
mesh.e(nx+ny+1:nx+2*ny,2) = (np-ny+1:np)'; |
| 148 |
|
| 149 |
% edges on lower boundary |
| 150 |
mesh.e(nx+2*ny+1:2*(nx+ny),1) = (1:ny+1:np-2*ny-1)'; |
| 151 |
mesh.e(nx+2*ny+1:2*(nx+ny),2) = (ny+2:ny+1:np-ny)'; |
| 152 |
|
| 153 |
% sides per cell |
| 154 |
mesh.sidesPerCell = 4; |
| 155 |
|
| 156 |
% cell type |
| 157 |
mesh.cellType = 'Quadrilateral'; |
| 158 |
|
| 159 |
% side type |
| 160 |
mesh.sideType = 'Line'; |
| 161 |
|
| 162 |
% sidesets |
| 163 |
xvec = [1:nx]'; |
| 164 |
yvec = [1:ny]'; |
| 165 |
mesh.elem_ss{1} = ny*(xvec-1) + 1; % bottom |
| 166 |
mesh.elem_ss{2} = ny*(nx-1) + (yvec-1) + 1; % right |
| 167 |
mesh.elem_ss{3} = ny*xvec; % top |
| 168 |
mesh.elem_ss{4} = yvec; % left |
| 169 |
|
| 170 |
% local side ids for sidesets |
| 171 |
mesh.side_ss{1} = 0*ones(nx,1); % bottom |
| 172 |
mesh.side_ss{2} = 1*ones(ny,1); % right |
| 173 |
mesh.side_ss{3} = 2*ones(nx,1); % top |
| 174 |
mesh.side_ss{4} = 3*ones(ny,1); % left |
| 175 |
|