-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathQ4meshGenerator.m
54 lines (49 loc) · 1.62 KB
/
Q4meshGenerator.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
function [VX,VY,EtoV,nV,nE]=Q4meshGenerator(Lx,Ly,xE,yE)
%% Quadrilateral uniform mesh on a rectangular domain, using Q4 elements
% structure for finite element analysis
% by Manuel Diaz, NTU, 2013.11.28
%
% INPUTS
% Lx:[a,b]= width range of the rectangular structure
% Ly:[c,d]= Height range of the rectangular structure
% xE = Number of elements on x- axis
% yE = Number of elements on y- axis
%
% OUTPUTS
% VX = x coordinate each element vertex
% VY = y coordinate each element vertex
% EtoV = vertices connectivity
% nV = Number of Vertices
% nE = Number of elements
% Define mesh status function
fstats=@(p,t) fprintf('%d nodes, %d elements %.2f\n\n', ...
size(p,1),size(t,1));
%% ELEMENT TO VERTICES CONNECTIVITY
% Build EtoV matrix
nE = xE*yE; % total number of elements
nV = (xE+1)*(yE+1); % total number of nodes
eNodes = 4;
EtoV = zeros(nE,eNodes); e=1;
for i = 1:xE;
for j = 1:yE;
k = j+(yE+1)*(i-1);
EtoV(e,:) = [k, (yE+1)+k, (yE+1)+k+1, k+1];
e = e+1;
end
end
%% COORDINATES GENERATION
% build VX and VY arrays
nx = linspace(Lx(1),Lx(2),xE+1);
ny = linspace(Ly(1),Ly(2),yE+1);
[x,y] = meshgrid(nx,ny);
VX=zeros(nV,1); VY=zeros(nV,1); e=1;
for i = 1:xE+1
for j = 1:yE+1
VX(e) = x(j,i);
VY(e) = y(j,i);
e = e+1; % element counter
end
end
%% MESH STATUS
fstats([VX,VY],EtoV);
end