Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

10/02/17 06:51 ‫ م‬C:\Users\NyZak\Desk...\fempro4.

m 1 of 6

% CE 603 FINITE ELEMENT METHOD %


% NAME : BADREDIN M. S. AMMAR , NUMBER : 2216103 %
% PLANE STRESS ANALYSIS OF A CANTILEVER BEAM USING
ISOPARAMETRIC %
% FOUR-NODE ELEMENTS
% Variable descriptions
% k = element matrix
% f = element vector
% kk = system matrix
% ff = system vector,(N)
% disp = system nodal displecment vector,(cm)
% eldisp = element nodal displecement vector,(cm)
% stress = matrix containing stresses,(N/cm^2)
% strain = matrix containing strains
% gcoord = coordinate values of each node
% nodes = nodal connectivity of each element
% index = a vector containing system dofs associated with each element
% point2 = matrix containing sampling points
% weight2 = matrix containing weighting coefficients
% bcdof = a vector containing dofs associated with boundary conditions
% bcval = a vector containing boundary condition values associated with
% the dofs in bcdof
% ------------------------------------------------------------------------
%
% ---------------------------------
% input data for control parameters
% ---------------------------------
clear all
clc
nel = 4; % number of elements
nnel = 4; % number of nodes per element
ndof = 2; % number of dofs per node
nnode = 9; % total number of nodes in system
sdof = nnode*ndof; % total system dofs
edof = nnel*ndof; % degrees of freedom per element
emodule = 7500000; % elastic modules,(N/cm^2)
10/02/17 06:51 ‫ م‬C:\Users\NyZak\Desk...\fempro4.m 2 of 6

poisson = 0.3; % Poisson's ratio


thick = 0.2; % thickness of plate,(cm)
nglx = 2; ngly = 2; % 2x2 Gauss-Legendre quadrature
nglxy = nglx*ngly; % number of sampling points per element
%
% ---------------------------------------------
% input data for nodal coordinate values
% gcoord(i,j) where i-> node no. and j-> x or y
% ---------------------------------------------
gcoord = [0 0; 6 0; 20 0; 0 10; 10 10; 20 10; 0.0 20; 14 20; 20 20];
%
% --------------------------------------------------------
% input data for nodal connectivity for each element
% nodes(i,j) where i-> element no. and j-> connected nodes
% --------------------------------------------------------
nodes = [1 2 5 4; 2 3 6 5; 4 5 8 7; 5 6 9 8];
%
% ----------------------------------
% input data for boundary conditions
% ----------------------------------
bcdof = [1 2 3 4 5 6]; % first four dofs are constrained
bcval = [0 0 0 0 0 0]; % whose described values are 0
%
% ----------------------------------------
% initialization of matrices and vectors
% ----------------------------------------
ff = zeros(sdof,1); % system force vector
kk = zeros(sdof,sdof); % system matrix
disp = zeros(sdof,1); % sysrem displacement vector
eldisp = zeros(edof,1); % element displacement vector
stress = zeros(nglxy,3); % matrix containing stress components
strain = zeros(nglxy,3); % matrix containing stress components
index = zeros(edof,1); % index vector
kinmtx = zeros(3,edof); % kinmatic matrix
matmtx = zeros(3,3); % constitutive matrix
%
10/02/17 06:51 ‫ م‬C:\Users\NyZak\Desk...\fempro4.m 3 of 6

% ---------------
% force vector
% ---------------
ff(13) = 400; % force applied at node 13 in x-axis,(N)
ff(17) = 200; % force applied at node 17 in x-axis,(N)
%
% -------------------------------------------------
% compute element matrices and vector, and assemble
% -------------------------------------------------
[point2,weight2]=feglqd2(nglx,ngly); % sampling points & weights
matmtx = fematiso(1,emodule,poisson); % constitutive matrix
%
for iel = 1:nel % loop for the total number of elements
for i = 1:nnel
nd(i) = nodes(iel,i); % extract nodes for (iel)-th element
xcoord(i) = gcoord(nd(i),1); % extract x value of the node
ycoord(i) = gcoord(nd(i),2); % extract y value of the node
end
%
k = zeros(edof,edof); % initialization of element matrix
%
% ----------------------
% numerical integration
% ----------------------
for intx = 1:nglx
x = point2(intx,1); % sampling point in x-sxis
wtx = weight2(intx,1); % weight in x-axis
for inty = 1:ngly
y = point2(inty,2); % sampling point in y-sxis
wty = weight2(inty,2); % weight in y-axis
[shape,dhdr,dhds]=feisoq4(x,y);
jacob2 = fejacob2(nnel,dhdr,dhds,xcoord,ycoord);
detjacob = det(jacob2); % determinant of jacobian
invjacob = inv(jacob2); % inverse of jacobian matrix
[dhdx,dhdy] = federiv2(nnel,dhdr,dhds,invjacob);
kinmtx2 = fekine2(nnel,dhdx,dhdy); % compute kinmatic matrix
10/02/17 06:51 ‫ م‬C:\Users\NyZak\Desk...\fempro4.m 4 of 6

%
% ------------------------
% compute element matrix
% ------------------------
k = k+kinmtx2'*matmtx*kinmtx2*thick*wtx*wty*detjacob;
end
end % end of numerical integration loop
%
index = feeldof(nd,nnel,ndof); % extract system dofs for the element
%
kk = feasmbl1(kk,k,index); % assemble element matrices
%
end % end of loop for the total number of elements
%
% -------------------------
% apply boundary condition
% -------------------------
[kk,ff]=feaplyc2(kk,ff,bcdof,bcval);
%
% -------------------------
% solve the matrix equation
% -------------------------
disp = kk\ff;
%
num = 1:1:sdof;
displace = [num' disp] % print nodal displacements
%
% ----------------------------
% element stress computation
% ----------------------------
for ielp = 1:nel % loop for the total number of elements
%
for i = 1:nnel
nd(i) =nodes(ielp,i); % extrat nodes for (iel)-th elements
xcoord(i) = gcoord(nd(i),1); % extract x value of the node
ycoord(i) = gcoord(nd(i),2); % extract y value of the node
10/02/17 06:51 ‫ م‬C:\Users\NyZak\Desk...\fempro4.m 5 of 6

end
%
% -----------------------
% numerical integration
% -----------------------
intp =0;
for intx = 1:nglx
x = point2(intx,1); % sampling point in x-axis
wtx = weight2(intx,1); % weight in x-axis
for inty = 1:ngly
y = point2(inty,2); % sampling point in y-sxis
wty = weight2(inty,2); % weight in y-axis
intp = intp+1;
%
[shape,dhdr,dhds]=feisoq4(x,y);
%
jacob2=fejacob2(nnel,dhdr,dhds,xcoord,ycoord);
%
detjacob = det(jacob2); % determinant of jacobian
invjacob = inv(jacob2); % inverse of jacobian matrix
%
[dhdx,dhdy]=federiv2(nnel,dhdr,dhds,invjacob);
%
kinmtx2=fekine2(nnel,dhdx,dhdy);
%
index = feeldof(nd,nnel,ndof);
%
% ------------------------------------
% extract element displacement vector
% ------------------------------------
for i = 1:edof
eldisp(i)=disp(index(i));
end
%
kinmtx2=fekine2(nnel,dhdx,dhdy); % compute kinmatic matrix
%
10/02/17 06:51 ‫ م‬C:\Users\NyZak\Desk...\fempro4.m 6 of 6

estrain = kinmtx2*eldisp; % compute strains


estress = matmtx*estrain; % compute stresses
%
for i = 1:3
strain(intp,i) = estrain(i); % store for each sampling point
stress(intp,i) = estress(i); % store for each sampling point
end
%
location = [ielp,intx,inty] % print location for stress
stress = stress(intp,:) % print stress values
%
end
end % end of integration loop
%
end % end of loop for total number of element
%
%

You might also like