2D Frame with internal-hinge

clc;
clear all ;
close all ;

A = input( ‘Do you Want To Use Last Document inputs? , If Your answer is Yes Enter ((1)) if No Enter((0)) !!!’);
if A==0
nHinged = input ( ‘Please Enter The number of Internal Hinged nodes’);
nSimple = input ( ‘Please Enter The number of Simple nodes’);
nPoint = input( ‘ Please Enter The number of External point Force’);
nUnif=input(‘Please Enter The number of Elements which are under uniform load’);
W0 = zeros ( nUnif , 1);
P0 = zeros ( nPoint , 1);
for i=1:nPoint
P0(i,1) = input(‘Please Enter The Magnitude of point Load(s)’);
end
save(‘PointLoads.txt ‘ , ‘ P0 ‘ , ‘-ASCII’ ) ;

for  i=1:nUnif 
    W0(i,1) = input('Please Enter The Magnitude of Uniform Line Load');
end
save('UniformLoads.txt' , 'W0' , '-ASCII');
elseif A==1
    nHinged  = 2 ;
    nSimple  = 7 ;
    nPoint   = 2 ;
     W0 = LoadFromFile('UniformLoads.txt' , '%f' , [1 Inf]);
     P0 = LoadFromFile('PointLoads.txt' , '%f' , [1 Inf]);

end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Processing %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

[ KElements , KTotal , KReduced , Frame2D , nNodes , nElements ] = …
Makeallinone( ‘Coordinates.txt’, ‘Supports.txt’ , ‘Connectivity.txt’ );
nUnif = 2 ;
Frame2D.Lunif = zeros ( nUnif,1 );
Frame2D.Lunif(1) = Frame2D.L(4);
Frame2D.Lunif(2) = Frame2D.L(6);

DofperNode = 3 ;
UnifLoad = zeros ( 2*DofperNode , nUnif ) ;
for i = 1:nUnif
UnifLoad(: , i ) = Frame2DMakeUniformLoad( W0(i) , Frame2D.Lunif(i));
end
Fex = [ 0.0 ; 0.0 ; 0.0 ;(UnifLoad ( 1:3 , 1 )) ; 0.0 ; P0(1) ; 0.0 …
; (UnifLoad ( 4:6 , 1 ) + UnifLoad ( 1:3 , 2)) ;…
0.0 ;P0(2) ; 0.0 ; (UnifLoad ( 4:6 , 1 )) ; 0.0 ; 0.0 ; 0.0 ] ;
u = KReduced\Fex ;
U =[0.0 ; 0.0 ;0.0; u(1:21) ; 0.0 ; 0.0 ; 0.0 ];
FTotal = (KTotal * U ) ;
FTotal(4:13) = FTotal(4:13) -Fex(1:10) ;
FTotal(15:18) = FTotal(15:18) – Fex(12:15) ;
FTotal(20:24) = FTotal (20:24) – Fex(17:21) ;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Check Point %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SigmaFx = sum(FTotal(1:3:3nNodes)); SigmaFy = sum(FTotal(2:3:3nNodes));
SigmaM = sum(FTotal(3:3:3nNodes)); display(SigmaFx); display(SigmaFy); display(SigmaM); %%%%%%%%%%%%%%%%%%%%%%%%%%%%% Post_Proccesing %%%%%%%%%%%%%%%%%%%%%%%%%%%%% UElem = zeros(6, nElements); FElem = zeros(6, nElements); ElemForce = zeros(1, nElements); for i=1:nElements UElem(:, i) = Frame2DExtractDisp(U,Frame2D.EndI(i), Frame2D.EndJ(i)); FElem(:, i) = KElements(:, :, i)UElem(:, i);
end
display(‘Frame2D,Forces’);
display(FTotal);
display(FElem);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Ploting_Part %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure;
axial = zeros(2,nElements);
Shear = zeros(2,nElements);
moment= zeros(2,nElements);
x = zeros(2,nElements);
for i=1:nElements
x(:,i) = [ Frame2D.X(Frame2D.EndI(i)) ; Frame2D.X(Frame2D.EndJ(i))];
end

for i= 1:nElements
y = [0 ; 0];
Shear(:,i) = [-FElem(1,i) ; FElem(4,i)];
hold on;
title(‘Axial Force Diagram’);
plot(x(:,i),Shear(:,i))
plot(x(:,i),y,’k’)
hold off;
end
figure;
for i= 1:nElements
y = [0 ; 0];
Shear(:,i) = [FElem(2,i) ; -FElem(5,i)];
hold on;
title(‘Shear Force Diagram’);
plot(x(:,i),Shear(:,i))
plot(x(:,i),y,’k’)
hold off;
end
figure;
for i=1:nElements
y = [0 ; 0];
moment(:,i) = [-FElem(3,i) ; FElem(6,i)];
hold on;
title(‘Bending Moment Diagram’);
plot(x(:,i),moment(:,i))
plot(x(:,i),y,’k’)
hold off;
end

NodeList = LoadFromFile( ‘Coordinates.txt’, ‘%f %f ‘, [2, Inf]);
position = zeros( 2 , nNodes);
for i= 1:nNodes
position(:,i) = NodeList(i,:);
end
x = zeros(1,nNodes);
y = zeros(1,nNodes);
for i = 1 : nNodes
x(i) = position(1,i);
y(i) = position(2,i);
end
node_connect(1, 1) = 1; % undeformed element 1
node_connect(2, 1) = 2;
node_connect(1, 2) = 2; % undeformed element 2
node_connect(2, 2) = 3;
node_connect(1, 3) = 2; % undeformed element 3
node_connect(2, 3) = 4;
node_connect(1, 4) = 3; % undeformed element 4
node_connect(2, 4) = 5;
node_connect(1, 5) = 4; % undeformed element 5
node_connect(2, 5) = 6;
node_connect(1, 6) = 5; % undeformed element 6
node_connect(2, 6) = 7;
node_connect(1, 7) = 6; % undeformed element 7
node_connect(2, 7) = 8;
node_connect(1, 8) = 7; % undeformed element 8
node_connect(2, 8) = 8;
node_connect(1, 9) = 8; % undeformed element 9
node_connect(2, 9) = 9;

figure ;
  for i =  1 : nElements 

  node_1 = node_connect(1,i);
  node_2 = node_connect(2,i);

  xx = [x(node_1),x(node_2)];
  yy = [y(node_1),y(node_2)];
  title (' Comparing Deformed and Undeformed Shapes of frame ')
  plot(xx,yy,'--rs' , 'Linewidth' , 2 , 'Markersize' , 10 ...
      , 'MarkerFaceColor' , 'g' , 'MarkerEdgeColor' , 'k' )
  grid on
  hold on

  end

  position_D = zeros(  2  , nNodes);

for i= 1:nNodes
position_D(:,i) = NodeList(i,:)+ [ U(3i-2) … ,U(3i-1)];
end
x_D = zeros(1,nNodes);
y_D = zeros(1,nNodes);
for i = 1 : nNodes
x_D(i) = position_D(1,i);
y_D(i) = position_D(2,i);
end
node_connect_D(1, 1) = 1; % deformed element 1
node_connect_D(2, 1) = 2;
node_connect_D(1, 2) = 2; % deformed element 2
node_connect_D(2, 2) = 3;
node_connect_D(1, 3) = 2; % deformed element 3
node_connect_D(2, 3) = 4;
node_connect_D(1, 4) = 3; % deformed element 4
node_connect_D(2, 4) = 5;
node_connect_D(1, 5) = 4; % deformed element 5
node_connect_D(2, 5) = 6;
node_connect_D(1, 6) = 5; % deformed element 6
node_connect_D(2, 6) = 7;
node_connect_D(1, 7) = 6; % deformed element 7
node_connect_D(2, 7) = 8;
node_connect_D(1, 8) = 7; % deformed element 8
node_connect_D(2, 8) = 8;
node_connect_D(1, 9) = 8; % deformed element 9
node_connect_D(2, 9) = 9;

for i =  1 : nElements 

  node_1_D = node_connect_D(1,i);
  node_2_D = node_connect_D(2,i);

  xx_D = [x_D(node_1_D),x_D(node_2_D)];
  yy_D = [y_D(node_1_D),y_D(node_2_D)];

  plot(xx_D,yy_D,'--' , 'Linewidth' , 2 , 'Markersize' , 10 ...
      , 'MarkerFaceColor' , 'b' , 'MarkerEdgeColor' , 'y' )
  grid on
  hold on

end

display(‘The End’);

Matlab output Figure of 2D frame under applied loads
ABAQUS Verification