0% found this document useful (0 votes)
62 views3 pages

FEM 2d 1 Var

This document contains code for a 2D finite element method (FEM) analysis. It defines variables and functions for rectangular and triangular elements. The code assembles element stiffness matrices and force vectors into global matrices, applies boundary conditions, and solves the system of equations to find the solution vector.

Uploaded by

SeymurH-v
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views3 pages

FEM 2d 1 Var

This document contains code for a 2D finite element method (FEM) analysis. It defines variables and functions for rectangular and triangular elements. The code assembles element stiffness matrices and force vectors into global matrices, applies boundary conditions, and solves the system of equations to find the solution vector.

Uploaded by

SeymurH-v
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

9/18/19 7:02 PM C:\Users\hesey...\FEM_2D_SH.

m 1 of 3

% ===============================================================
% ======2D-FEM-code for rectangular and triangular elements======
% ======SEYMUR HASANOV=====#T00285391============================
%
%
%
clear all;clc;
% Call the input file
%% ===========ALL INPUT FIELS ARE BELOW===========================%%
% =======Uncomment for the input file below======================

% ===============================================================

% Setting condition for defining type of the element, npe & ndfn
if type==1
npe=3;
if ntype==2
ndfn=3;
else
ndfn=1;
if nfunc==2
npe=6;
end
end
else
npe=4;
if ntype==2
npe=8;
ndfn=1;
else
end
end

% End reading data


% Calculate number of total equations to solve

neq = nnod;
g_k = zeros(neq,neq);
g_f = zeros(neq,1);
el_x = zeros(npe,1);
el_y = zeros(npe,1);
9/18/19 7:02 PM C:\Users\hesey...\FEM_2D_SH.m 2 of 3

% Start loop over number of elements to calculate the element matrices


% and assemble them into the global matrices
%
%%
for n=1:nelem %%

for i=1:npe
el_x(i) = x(ncon(n,i));
el_y(i) = y(ncon(n,i));
end
el_x;
el_y;

% Calling element matrices based on RECT & TRI elements

if type==1
[el_k,el_f] = el_kk_tri(npe,fc,el_x,el_y,ey,ex);
else
[el_k,el_f] = el_kk_quad(ntype,npe,ex,ey,fc,el_x,el_y,nfunc);
end

% Assembly

for i = 1:npe
nr = (ncon(n,i)-1)*ndfn;
for ii = 1:ndfn
nr = nr + 1;
l = (i-1)*ndfn+ii;
g_f(nr) = g_f(nr)+el_f(l);
for j = 1:npe
nc = (ncon(n,j)-1)*ndfn;
for jj = 1:ndfn
m = (j-1)*ndfn+jj;
nc = nc+1;
g_k(nr,nc)=g_k(nr,nc)+el_k(l,m);
end
end
end
end
end
9/18/19 7:02 PM C:\Users\hesey...\FEM_2D_SH.m 3 of 3

%%
% Apply known forces

for n = 1:nnbc
nb = inbc(n);
g_f(nb) = g_f(nb)+vnbc(n);
end

% Apply known displacements (1-0) method

for nj = 1:nebc
j = iebc(nj);
for k=1:neq
if k~=j
g_f(k) = g_f(k)-g_k(k,j)*vebc(nj);
g_k(k,j) = 0;
g_k(j,k) = 0;
else
g_k(j,j) = 1;
g_f(j) = vebc(nj);
end
end
end
%%
sol = g_k\g_f;

sol

You might also like