Thursday, November 10, 2011

4 node quadrilateral element

Below you may find a Matlab function written by me to generate 4 node quadrilateral elements. It is very easy and straight forward.


function [Edof,Ex,Ey]=quadmesh(xcorner,ycorner,nx,ny)


% function [Edof,Ex,Ey]=quadmesh(xcorner,ycorner,nx,ny)
%----------- Description ---------
% Generates quadrilateral 4 node elements
% ------------ INPUT -------------
% xcorner=[lower left, lower right, upper right, upper left] 
% ycorner=[lower left, lower right, upper right, upper left]
% nx= No. elements in x direction
% ny= No. elements in y direction
%    4         3
%    o---------o
%    |         |
%    |         | 
%    |         |
%    o---------o
%    1         2
% ----------- OUTPUT -------------
% Ex= element x coordinates matrix [nrelem X 4]
% Ey= element y coordinates matrix [nrelem X 4]
% Edof= element DOF [nrelem X 9]
% Written by 
% Shah, 10 November 2011


l=xcorner(2)-xcorner(1);
h=ycorner(3)-ycorner(2);
for i=1:ny
        for j=1:nx
            dl=(i-1)*(nx+1)+j;
            ul=dl+(nx+1); 
            dr=dl+1;
            ur=ul+1;
            xy_dl=[(j-1)*(l/nx)+xcorner(1) (i-1)*(h/ny)+ycorner(1)];
            xy_dr=[j*(l/nx)+xcorner(1) (i-1)*(h/ny)+ycorner(1)];
            xy_ul=[(j-1)*(l/nx)+xcorner(1) i*(h/ny)+ycorner(1)];
            xy_ur=[j*(l/nx)+xcorner(1) i*(h/ny)+ycorner(1)];
            el=(i-1)*nx+j;
            Edof(el,:)=[el,2*dl-1,2*dl,2*dr-1,2*dr,2*ur-1,2*ur,2*ul-1,2*ul];
            Ex(el,:)=[xy_dl(1) xy_dr(1) xy_ur(1) xy_ul(1)];
            Ey(el,:)=[xy_dl(2) xy_dr(2) xy_ur(2) xy_ul(2)];
        end
end


figure(1);
hold on;
for i=1:length(Edof(:,1));
    plot(Ex(i,[1:end 1]),Ey(i,[1:end 1]));
end
axis equal

No comments:

Post a Comment