1D Problem Solve Using FEM
1D Problem Solve Using FEM
Objective
Finite Element Formulation and analysis of one dimensional problem by developing computer program.
Software used
Matlab 2018
Step 1- Discretization
The domain is subdivided into three elements and four nodes as shown in the figure.
The two element stiffness matrices k1, k2 and k3 are obtained by making calls to the MATLAB function
. linear triangle element stiffness. Each matrix has size 2×2.
1 −1 1 −1
k1 = 5.175×1010 × [ ] k2 = 2.07×1010 × [ ]
−1 1 −1 1
1 −1
k3 = 5.175×109 × [ ]
−1 1
Since the structure has four nodes, the size of the global matrix is 4×4. So by assembling k1, k2 and k3
. we get K.
5.175 − 5.175 0 0
−5.175 7.245 −2.07 0
K = 1010 ×[ ]
0 −2.07 2.5875 −0.5175
0 0 −0.5175 0.5175
5.175 − 5.175 0 0 𝑢1 F1
−5.175 7.245 −2.07 0 𝑢2 F2
1010 ×[ ] ×[𝑢 ] = [ ]
0 −2.07 2.5875 −0.5175 3 2000
0 0 −0.5175 0.5175 𝑢4 F4
In this step, we obtain stresses and strains in both element using MATLAB.
oneD_ElementStiffness(k)
where k is this function calculates the element stiffness matrix for each linear line element where k is element
stiffness which is calculated by EA/L where E is modulus of elasticity, A is the area of cross section, and L is
the length of element. It returns the 2×2 element stiffness matrix k.
oneD_Assemble (K,k,i,j)
this function assembles the element stiffness matrix k of the linear line element joining nodes i and j into the
global stiffness matrix K. it returns the n×n global stiffness matrix K every time an element is assembled.
oneD_ElementStiffness(k)
function y = oneD_ElementStiffness(k)
%element_stiffness i.s this function call the stiffness matrix of 2*2 size
y=[k -k;-k k];
end
oneD_Assemble (K,k,i,j)
function y = oneD_Assemble(K,k,i,j )
% Assemble-this function assemble the element stiffness matrix k
% of element with nodes i and j into the global stiffness
% matrix K
%This function call K after matrix k is assembled
K(i,i)=K(i,i) +k(1,1);
K(i,j)=K(i,j) +k(1,2);
K(j,i)=K(j,i) +k(2,1);
K(j,j)=K(j,j) +k(2,2);
y=K;
end
%% Boundary condition
% using dialoge box , creative way
% I have created a function of dialoge box to access all boundary condition
[dof1,U,dof2,F]=Boundary_condn_dlg(U,F);
% dof1=fixed node or degree of restriction due to given displacement (that nodes where
displacement are given)
% dof2= that node where force value are given
% dof3= free node or that nodes where displacement value are not given
dof3=setxor(1:n,dof1);
for a=dof1
fprintf('\nDisplacement at node-%i (U%i)= %g',a,a,U(a))
end
for a=dof2
fprintf('\nExternal force at node-%i (F%i)= %g',a,a,F(a))
end
%% Solution on the basis of given Input
fprintf('\n');
%% *STEP-1: DISCRETIZATION*
disp('~~~~~~~~~~~~~~~~~~~~~~~~~')
fprintf('\nTotal no of node = %i',n);
fprintf('\nTotal no of element = %i\n',m );
elements=1:m;
nodes=[i;j];
T1=table(elements',nodes',L',E',A',Ke','VariableNames',
{'Element','nodes','Length','Young_modulus','Area','Stiffness'});
disp(' ');
disp(T1)
for dof3=dof3
fprintf('\nU%i= %1.3g ',dof3,U(dof3))
end
if dof1~=0
for a=dof1
fprintf('\nR%i= %1.3g ',a,F(a))
end
end
%% *STEP-6: POST PROCESING*
end
%% * CONCLUSION :--*
Boundary condition
------------------------
Displacement at node-1 (U1)= 0
Displacement at node-4 (U4)= 0
External force at node-3 (F3)= 2000
STEP-1: DISCRETIZATION
~~~~~~~~~~~~~~~~~~~~~~~~~
Total no of node = 4
Total no of element = 3
1 1 2 20 2.07e+11 5 5.175e+10
2 2 3 30 2.07e+11 3 2.07e+10
3 3 4 40 2.07e+11 1 5.175e+09
FOR ELEMENT1:
K1=
5.175e+10 -5.175e+10
-5.175e+10 5.175e+10
FOR ELEMENT2:
K2=
2.07e+10 -2.07e+10
-2.07e+10 2.07e+10
FOR ELEMENT3:
K3=
5.175e+09 -5.175e+09
-5.175e+09 5.175e+09
MATLAB Command Window Page 2
Given :
U1 = 0
U4 = 0
F3 = 2000
STEP-5: SOLUTION
~~~~~~~~~~~~~~~~~~~~~~~
Now solve the Equation K*U=F
U2= 2.86e-08
U3= 1e-07
R1= -1.48e+03
R4= -519
----------------------
Node Displacement Force
____ ____________ __________
1 0 -1481.5
2 2.8628e-08 1.0346e-13
3 1.002e-07 2000
4 0 -518.52
Q.1 Five springs, having stiffnesses k1 = 105 N/m, k2 = 2 × 105 N/m, k3 = 3 × 105 N/m, k4 = 4 × 105 N/m,
and k5 = 5 × 105 N/m are connected as a parallel-series system and is subjected to a load P = 1000 N at
node 4 as shown in Figure 1. Determine the displacements of nodes 2, 3, and 4 using the finite
element method. State the assumptions made in your solution. (Example 1.6, Chapter 1)
Figure 1
6/23/21 6:28 PM E:\M.TECH\SEM 2\...\Spring_LinearElement.m 1 of 4
for dof3=dof3
fprintf('\nU%i= %1.3g ',dof3,U(dof3))
end
if dof1~=0
for a=dof1
fprintf('\nR%i= %1.3g ',a,F(a))
end
end
%% *STEP-6: POST PROCESING*
end
6/23/21 6:28 PM E:\M.TECH\SEM 2\...\Spring_LinearElement.m 4 of 4
%% * CONCLUSION :--*
fprintf('\n\nSTEP-7: CONCLUSION :-- \n');
disp('--------------------------~~')
T2=table([1:n]',U,F,'VariableNames',{'Node','Displacement','Force'});
T3=table(elements', nodes', element_load' ,'VariableNames',
{'Element','nodes','element_load'});
disp('(1) Nodes wise Result:')
disp('----------------------')
disp(T2)
disp('(2) Elements wise Result:')
disp('-------------------------')
disp(T3)
fprintf('\nNOTE: (+ve)element load means tensile in nature')
fprintf('\n and (-ve)element load means compressive in nature\n')
disp('===================================================================')
MATLAB Command Window Page 1
===================================================================
Question.No:- Example 1.6 [SPRING ELEMENT PROBLEM]
===================================================================
GIVEN PARAMETERS ARE:
===================================================================
Total no of nodes (n) = 4
Total no of elements (m) = 5
FOR ELEMENT-(1) => i,j,Ke1 = [1,2,10^5]
FOR ELEMENT-(2) => i,j,Ke2 = [1,2,2*10^5]
FOR ELEMENT-(3) => i,j,Ke3 = [2,3,3*10^5]
FOR ELEMENT-(4) => i,j,Ke4 = [3,4,4*10^5]
FOR ELEMENT-(5) => i,j,Ke5 = [3,4,5*10^5]
Boundary condition
------------------------
Displacement at node-1 (U1)= 0
Displacement at node-4 (U4)= 0
External force at node-4 (F4)= 1000
===================================================================
SOLUTION OF THE PROBLEM STEP WISE STEP:
===================================================================
STEP-1: DISCRITIZATION
-----------------------
Total no of node = 4
Total no of element = 5
1 1 2 1e+05
2 1 2 2e+05
3 2 3 3e+05
4 3 4 4e+05
5 3 4 5e+05
FOR ELEMENT1:
K1=
100000 -100000
-100000 100000
FOR ELEMENT2:
K2=
200000 -200000
-200000 200000
MATLAB Command Window Page 2
FOR ELEMENT3:
K3=
300000 -300000
-300000 300000
FOR ELEMENT4:
K4=
400000 -400000
-400000 400000
FOR ELEMENT5:
K5=
500000 -500000
-500000 500000
Given :
U1 = 0
U4 = 0
F4 = 1000
STEP-5: SOLUTION
~~~~~~~~~~~~~~~~~~~~~~~
Now solve the Equation K*U=F
U2= 0
U3= 0
R1= 0
R4= 0
1 0 0
2 0 0
3 0 0
4 0 0
1 1 2 0
2 1 2 0
3 2 3 0
4 3 4 0
5 3 4 0
[dof1,T,dof2,Q]=Boundary_condn_dlg(T,Q);
dof3=setxor(1:n,dof1);
for a=dof1
fprintf('\nTemperature at node-%i (T%i)= %g',a,a,T(a));
end
for a=dof2
fprintf('\nHeat_flow at node-%i (F%i)= %g',a,a,Q(a))
end
fprintf('\n');
%% DISCRETIZATION
%% ELEMENTS MATRIX
6/23/21 6:05 PM E:\M.TECH...\Heat_Transfer_LinearElement.m 2 of 4
end
end
if size(Q,1)~=n && size(T,1)~=n
Q=Q';
end
T=K\Q;
Q=S*T;
for dof3=dof3
fprintf('\nT%i= %1.3g ',dof3,T(dof3))
end
if dof1~=0
for a=dof1
fprintf('\nR%i= %1.3g ',a,Q(a))
end
end
%% POST PROCESING
end
%% CONCLUSION :
{'Element','nodes','strain','Heat_flow','stress'});
disp('1) Nodes wise Result:')
disp('----------------------')
disp(T2)
disp('2) Elements wise Result:')
disp('------------------------')
disp(T3)
disp(' ')
MATLAB Command Window Page 1
Boundary condition
------------------------
Temperature at node-3 (T3)= 30
Heat_flow at node-1 (F1)= -0.24
STEP-1: DISCRITIZATION
~~~~~~~~~~~~~~~~~~~~~~~~~
Total no of node = 3
Total no of element = 2
1 1 2 3 0.25 1 0.083333
2 2 3 6 0.08 1 0.013333
FOR ELEMENT1:
K1=
0.083333 -0.083333
-0.083333 0.083333
FOR ELEMENT2:
K2=
0.013333 -0.013333
-0.013333 0.013333
Given :
T3 = 30
Q1 = -0.24
After putting the boundary values
K T Q
___________________________________ __ _____
K T Q
______________________ __ _____
STEP-5: SOLUTION
~~~~~~~~~~~~~~~~~~~~~~~
Now solve the Equation K*T=Q
T1= 9.12
T2= 12
R3= 0.24
1 9.12 -0.24
2 12 1.0755e-16
3 30 0.24
>>
Generalized MATLAB program for a one dimensional Fluid flow problem:
6/23/21 5:37 PM E:\M.TECH\SEM 2\F...\Fluid_LinearElement.m 1 of 4
%% Given Parameters
C=(1/u)*((D.^4)./L);
Ke=C.*(pi/128);
disp(' ')
disp('(viii)Element Stiffness')
for m=1:m
[dof1,P,dof2,Q]=Boundary_condn_dlg(P,Q);
6/23/21 5:37 PM E:\M.TECH\SEM 2\F...\Fluid_LinearElement.m 2 of 4
dof3=setxor(1:n,dof1);
for a=dof1
fprintf('\nPressure at node-%i (P%i)= %g',a,a,P(a))
end
for a=dof2
fprintf('\nDischarge at node-%i (Q%i)= %g',a,a,Q(a))
end
%% Solution
fprintf('\n');
p=sym('P',[n,1]);
q=sym(Q);
fprintf('\nSTEP-4: APPLYING BOUNDARY CONDITIONS\n');
disp('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
fprintf('\nGiven :')
if dof1~=0
for a=dof1
fprintf('\nP%i = %g ',a,P(a));
p(a)=P(a);
q(a)=sym(sprintf('R%i',a));
end
6/23/21 5:37 PM E:\M.TECH\SEM 2\F...\Fluid_LinearElement.m 3 of 4
end
for a=dof2
fprintf('\nQ%i = %g',dof2,Q(dof2));
end
fprintf('\n\nAfter putting the boundary values\n\n')
p=string(p);p=char(p);
q=string(q);q=char(q);
ST1=table(K,p,q,'VariableNames',{'K','P','Q'});
disp(ST1);
fprintf('\n\nNow delete the row and column crossponding to fixed node\n\n')
ST2=table(K(dof3,dof3),p(dof3,:),q(dof3,:),'VariableNames',{'K','P','Q'});
disp(ST2);
%% SOLUTION ( FIND OUT P=? FROM K*P=Q )
for dof3=dof3
fprintf('\nP%i= %1.3g ',dof3,P(dof3))
end
if dof1~=0
for a=dof1
fprintf('\nR%i= %1.3g ',a,Q(a))
end
end
%% POST PROCESING
if Discharge(m)>0
X=' (positive flow)';
elseif Discharge(m)<0
X=' (negative flow)';
else
X=' (no discharge)';
end
fprintf('\n (1) pressure: P%i=%1.3g and P%i=%1.3g',i(m),P(i(m)),j(m),P(j(m)))
fprintf('\n (2) discharge:(q%i)={K%i*(P%i-P%i)}= %1.3g ',m,m,j(m),i(m),Discharge(m)),
disp(X);
end
MATLAB Command Window Page 1
(viii)Element Stiffness
Ke1 = 19.88
Ke2 = 7.9895
Ke3 = 2.805
Ke4 = 1.5532
Boundary condition
------------------------
Pressure at node-1 (P1)= 30
Pressure at node-3 (P3)= 22
Pressure at node-4 (P4)= 20
Pressure at node-5 (P5)= 25
Discharge at node-2 (Q2)= 0
STEP-1: DISCRETIZATION
-----------------------
Total no of node = 5
Total no of element = 4
1 1 2 19.88
2 2 3 7.9895
3 2 4 2.805
4 2 5 1.5532
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FOR ELEMENT1:
K1=
19.88 -19.88
-19.88 19.88
FOR ELEMENT2:
K2=
7.9895 -7.9895
-7.9895 7.9895
FOR ELEMENT3:
K3=
2.805 -2.805
-2.805 2.805
FOR ELEMENT4:
K4=
1.5532 -1.5532
-1.5532 1.5532
Given :
P1 = 30
P3 = 22
P4 = 20
P5 = 25
Q2 = 0
K P Q
__________________________________________________ __ __
MATLAB Command Window Page 3
19.88 -19.88 0 0 0 30 R1
-19.88 32.228 -7.9895 -2.805 -1.5532 P2 0
0 -7.9895 7.9895 0 0 22 R3
0 -2.805 0 2.805 0 20 R4
0 -1.5532 0 0 1.5532 25 R5
K P Q
______ __ __
32.228 P2 0
STEP-5: SOLUTION
~~~~~~~~~~~~~~~~~~~~~~~
Now solve the Equation K*P=Q
P2= 26.9
R1= 61.5
R3= -39.2
R4= -19.4
R5= -2.96