clear all
clc
% FE Method in Structural Mechanics Assignment no. 1
% Angel Salesa - Nov 2017
% Introduction of the problem constants
elem =[1 2; 2 3; 1 4;2 4;2 5;4 5;3 5]; % Element
conectivity
real =[1184 1184 1184 1184 1184 1184 1184]; % Cross Section
Area
mat =[210e3 210e3 210e3 210e3 210e3 210e3 210e3]; % Young's modulus
lenght=[3e3 3e3 1.5e3*2^0.5 1.5e3*2^0.5 1.5e3*2^0.5 3e3 1.5e3*2^0.5]; % Element
length
angle=[0 0 45 135 45 0 135]; % Element orientation
%Creation of the global stiffness matrix from the local rigidity matrixes and the
%rotation matrix
K_ = zeros(10); % Inicialitation of global stiffness
for ielem = 1:7 % 7 bars in the truss so 7 elements
A = real(ielem); % Element properties
E = mat(ielem); % Element material
L = lenght(ielem); % Element length
c = cos(pi/180*angle(ielem)); % cos component of the rotation matrix
s = sin(pi/180*angle(ielem)); % sin component of the rotation matrix
T = [c s 0 0 ; -s c 0 0 ;
0 0 c s ; 0 0 -s c ]; % 4x4 Rotation matrix
k_e = [ E*A/L 0 -E*A/L 0 ; 0 0 0 0 ;
-E*A/L 0 E*A/L 0 ; 0 0 0 0 ]; % 4x4 Element matrix in local
coordinates
k_ei = T'*k_e*T; % Element matrix in global coordinates
% The following code is able to make the assembly operation of the global
rigidity matrix
i1=2*(elem(ielem,1)-1)+1; % degree of freedom X node i
i2=i1+1; % degree of freedom Y node i
j1=2*(elem(ielem,2)-1)+1; % degree of freedom X node j
j2=j1+1; % degree of freedom X node j
% Assembly process
K_(i1:i2,i1:i2) = K_(i1:i2,i1:i2) + k_ei(1:2,1:2); % Assembly 1st quadrant
K_(i1:i2,j1:j2) = K_(i1:i2,j1:j2) + k_ei(1:2,3:4); % Assembly 2nd quadrant
K_(j1:j2,i1:i2) = K_(j1:j2,i1:i2) + k_ei(3:4,1:2); % Assembly 3rd quadrant
K_(j1:j2,j1:j2) = K_(j1:j2,j1:j2) + k_ei(3:4,3:4); % Assembly 4th quadrant
end
%Boundary conditions of the nodes: as node 1 is pinned and node 3 rolled
%ux1=0 (position 1); uy1=0 (position 2); uy3=0 (position 6);
%The general rigidity matrix can be reduced
K_red = K_; % Reduced matrix
K_red(:,6)=[];K_red(6,:)=[]; % Eliminates row and column #6 due to uy3=0
K_red(:,2)=[];K_red(2,:)=[]; % Eliminates row and column #2 due to uy1=0
K_red(:,1)=[];K_red(1,:)=[]; % Eliminates row and column #1 due to ux1=0
%Other boundary conditions are the known forces in the nodes:
%fx2=0; fy2=P: fx3=0; fx4=0; fy4=P; fx5=0; fy5=P
f_red = [0 100000 0 0 100000 0 100000]' % The Reduced nodal force vector
% Solve partially the system with the above boundary conditions
u_red=inv(K_red)*f_red
% With the above solutions, the displacement matrix is re-assemble
% The nodal displacement will be
u = [0 0 u_red(1) u_red(2) u_red(3) 0 u_red(4) u_red(5) u_red(6) u_red(7)]'
% And the below are Nodal force vector
f = (K_*u)
%To calculate the stresses in the elements (bars) it is necessary to used
%the rotion matrix (2x2) to get the nodal displacements in the local axis.
for bar=1:7; % Select the 7 no. bars
bar1=elem(bar,1); % Select node num. of the bar
bar2=elem(bar,2); % Select the other node num. of the bar
%First node of the selected bar
positionx1=2*((bar1)-1)+1;
positiony1=positionx1+1;
u1global(1)=u(positionx1); % Select ux displacement of the node
u1global(2)=u(positiony1); % Select uy displacement of the node
a=angle(bar); % Select angle of the bar
R=[cosd(a) -sind(a); sind(a) cosd(a)]; % Rotation matrix 2x2
u1local=u1global*R; % Local displacements for one bar node
resultant1=u1local(1); % Select the axial displacement
%Second node of the selected bar, similar procedure to above
positionx2=2*((bar2)-1)+1;
positiony2=positionx2+1;
u2global(1)=u(positionx2);
u2global(2)=u(positiony2);
u2local=u2global*R;
resultant2=u2local(1);
%The final bar stresses are:
sigma(bar)=(mat(bar)/lenght(bar))*[-1 1]*[resultant1; resultant2];
end
sigma