-
Notifications
You must be signed in to change notification settings - Fork 0
/
TProd_Mesh.m
39 lines (34 loc) · 1017 Bytes
/
TProd_Mesh.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
function Mesh = TProd_Mesh(x,y)
%TPROD_MESH Create Tensor-Product mesh
%
% MESH = TPROD_MESH(X,Y) initializes a tensor-product mesh with vertices
% at (X(i),Y(j)). The vectors X and Y must be sorted in ascending order.
%
% MESH = TPROD_MESH(X) is short for MESH = TPROD_MESH(X,X);
%
% Example :
%
% Mesh = TProd_Mesh(0:1/n:1);
% Copyright 2007-2007 Claude Gittelson
% SAM - Seminar for Applied Mathematics
% ETH-Zentrum
% CH-8092 Zurich, Switzerland
% Handle input arguments
if(nargin < 2)
y = x;
end
% Create coordinates
[X,Y] = meshgrid(x,y);
Mesh.Coordinates = [X(:),Y(:)];
% Create elements
nX = length(x);
nY = length(y);
nElem = (nX-1)*(nY-1);
Mesh.Elements = zeros(nElem,4);
for i=1:nX-1
Mesh.Elements((i-1)*(nY-1)+(1:nY-1),1) = (i-1)*nY + (1:nY-1);
Mesh.Elements((i-1)*(nY-1)+(1:nY-1),4) = (i-1)*nY + (2:nY);
Mesh.Elements((i-1)*(nY-1)+(1:nY-1),2) = i*nY + (1:nY-1);
Mesh.Elements((i-1)*(nY-1)+(1:nY-1),3) = i*nY + (2:nY);
end
return