Space Frame

clc;
clear all ;
close all ;

Connectivity= LoadFromFile(‘Connectivity.txt’ ,…
‘%f %f %f %f %f %f %f %f %f ‘ , [ 9 Inf] ) ;
nodeCoordinates= LoadFromFile(‘Coordinates.txt’ , ‘%f %f %f ‘ , [ 3 Inf] );
%%%%%%%%%%%%%%%%%%%%%%%%%%%Make All in Struct%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Frame3D.X = nodeCoordinates (:,1);
Frame3D.Y = nodeCoordinates (:,2);
Frame3D.Z = nodeCoordinates (:,3);
Frame3D.ID = Connectivity (:,1);
Frame3D.EndI = Connectivity (:,2);
Frame3D.EndJ = Connectivity (:,3);
Frame3D.E = Connectivity (:,4);
Frame3D.A = Connectivity (:,5);
Frame3D.Iy = Connectivity (:,6);
Frame3D.Iz = Connectivity (:,7);
Frame3D.J = Connectivity (:,8);
Frame3D.G = Connectivity (:,9);
% generation of coordinates and connectivities
elementNodes=Connectivity;
elementNodes(:,1) = [] ;
elementNodes(:,3:8)=[];
numberNodes=length(Frame3D.X);
numberElements=max(Frame3D.ID);
% for structure:
% displacements: displacement vector
% force : force vector
% GDof: global number of degrees of freedom
GDof=6*numberNodes;
force=zeros(GDof,1);
%force vector
force(69)=-10E3;
force(57)=-10E3;
force(45)=-10E3;
force(81)=-10E3;
force(93)=-10E3;
force(105)=-10E3;
% calculation of the system stiffness matrix
[KTotal]=…
MakeFrame3DStiff(GDof,numberElements,…
elementNodes,nodeCoordinates,Frame3D.E(1),Frame3D.A(1)…
,Frame3D.Iz(1),Frame3D.Iy(1),Frame3D.G(1),Frame3D.J(1));

% boundary conditions and solution
Supports = LoadFromFile(‘Supports.txt’ , ‘%d’ , [1 Inf] ) ;
UTotal=MakeDisp(GDof,Supports,KTotal,force);
UElem = zeros (12 , numberElements ) ;
for i =1:numberElements
UElem(:,i) = SpaceFrameExtractDisp(UTotal ,…
Frame3D.EndI(i) , Frame3D.EndJ(i));
end

ElemForce = zeros ( 12 , numberElements );
x1 = zeros ( 1 , numberElements );
x2 = zeros ( 1 , numberElements );
y1 = zeros ( 1 , numberElements );
y2 = zeros ( 1 , numberElements );
z1 = zeros ( 1 , numberElements );
z2 = zeros ( 1 , numberElements );
for i=1:numberElements
x1(1,i)=Frame3D.X(Frame3D.EndI(i));
y1(1,i)=Frame3D.Y(Frame3D.EndI(i));
z1(1,i)=Frame3D.Z(Frame3D.EndI(i));
x2(1,i)=Frame3D.X(Frame3D.EndJ(i));
y2(1,i)=Frame3D.X(Frame3D.EndJ(i));
z2(1,i)=Frame3D.X(Frame3D.EndJ(i));

ElemForce(:,i) = MakeElemForce (x1(1,i) ,y1(1,i) ,z1(1,i) , x2(1,i)...
    , y2(1,i),z2(1,i), Frame3D.E(1) , Frame3D.G(1) , Frame3D.A(1)...
    , Frame3D.Iy(1), Frame3D.Iz(1) , Frame3D.J(1) , UElem (:,i));

end
% displacements
disp(‘Displacements’)
jj=1:GDof; format long
f=[jj; UTotal’];
fprintf(‘node U\n’)
fprintf(‘%3d %12.8f\n’,f)

%drawing mesh and deformed shape
U=UTotal;
clf;
drawingMesh(nodeCoordinates+500[U(1:6:6numberNodes)…
U(2:6:6numberNodes) U(3:6:6numberNodes)],…
elementNodes,’L2′,’k.-‘);
drawingMesh(nodeCoordinates,elementNodes,’L2′,’k–‘);

%NodeList = LoadFromFile( ‘Coordinates.txt’, ‘%f %f %f’, [3, Inf]);
%position = zeros( 3 , numberNodes);
% for i= 1:numberNodes
% position(:,i) = NodeList(i,:);
%end
%x = zeros(1,numberNodes);
% y = zeros(1,numberNodes);
%z = zeros(1,numberNodes);
% for i = 1 : numberNodes
% x(i) = position(1,i);
% y(i) = position(2,i);
% z(i) = position(3,i);
% end
%node_connect = zeros ( 2 , numberElements) ;

%for i=1:numberElements
% node_connect(1,i) = Frame3D.EndI(Frame3D.ID(i));
% node_connect(2,i) = Frame3D.EndJ(Frame3D.ID(i));
% end

% for i = 1 : numberElements

% 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)];
% zz = [z(node_1),z(node_2)];

% plot3(xx,yy,zz,’b+:’)
% grid on
% hold on
% end
%%%%%%%%%%%%%%%%%%%%% Plotting the Deformed Truss3D%%%%%%%%%%%%%%%%%%%%%%%%
%position_D = zeros( 3 , numberNodes);
%for i= 1:numberNodes
% position_D(:,i) = NodeList(i,:)+ [ UTotal(6i-5) … % ,UTotal(6i-4) , UTotal(6*i-3)];
%end
% x_D = zeros(1,numberNodes);
% y_D = zeros(1,numberNodes);
% z_D = zeros(1,numberNodes);
% for i = 1 : numberNodes
% x_D(i) = position_D(1,i);
% y_D(i) = position_D(2,i);
% z_D(i) = position_D(3,i);
% end
% node_connect_D = zeros ( 2 , numberElements) ;
% for i=1:numberElements
% node_connect_D(1,i) = Frame3D.EndI(Frame3D.ID(i));
% node_connect_D(2,i) = Frame3D.EndJ(Frame3D.ID(i));
%end

% for i = 1 : numberElements

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

% xx_D = [x(node_1_D),x(node_2_D)];
% yy_D = [y(node_1_D),y(node_2_D)];
% zz_D = [z_D(node_1_D),z_D(node_2_D)];

% plot3(xx_D,yy_D,zz_D,’b+:’)
% grid on
% hold on
% end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PLotting Part %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

x = zeros( numberElements ,2 );
y1 = zeros( numberElements ,2 );
y2 = zeros( numberElements ,2 );
y3 = zeros( numberElements ,2 );
y4 = zeros( numberElements ,2 );
y5 = zeros( numberElements ,2 );
y6 = zeros( numberElements ,2 );
for i= 1:numberElements
x (i,:) = [ Frame3D.X(Frame3D.EndI(i)) , Frame3D.Y(Frame3D.EndJ(i))];
y1 (i,:) = [ -ElemForce(1, i) ElemForce(7,i) ] ;
y2 (i,:) = [ ElemForce(2, i) -ElemForce(8,i) ] ;
y3 (i,:) = [ ElemForce(3, i) -ElemForce(9,i) ] ;
y4 (i,:) = [ ElemForce(4, i) -ElemForce(10,i) ] ;
y5 (i,:) = [ ElemForce(5, i) -ElemForce(11,i) ] ;
y6 (i,:) = [ ElemForce(6, i) -ElemForce(12,i) ] ;

figure; 
hold on 
plot( x(i,:) , y1(i,:) ,'k', x(i,:) , y2(i,:) ,'b--',x(i,:)...
    , y3(i,:) ,'r', x(i,:) , y4(i,:) ,'g',x(i,:) , y5(i,:) ,'y-.'...
    , x(i,:) , y6(i,:) ,'c--')
legend('Axial Force Diag' , 'shear Force YDiag ' , 'shear Force ZDiag' ,...
    'Torsion Force Diag' , 'Moment Force YDiag' , 'Moment Force ZDiag')
z = [0 ; 0];
plot(x,z,'k')

end

Matlab output Figure