71 lines
2.4 KiB
Matlab
71 lines
2.4 KiB
Matlab
%**************************************************************************
|
|
function [U]=PlaneTrussFEA(x,y,ele,Load,Constr,Scale)
|
|
Dofs=3*size(x,2); %总自由度数
|
|
EleCount=size(ele,1); %单元总数
|
|
K=zeros(Dofs,Dofs); %总体刚度矩阵
|
|
F=zeros(Dofs,1); %总体载荷列阵
|
|
U=zeros(Dofs,1); %总体位移列阵
|
|
BarLength=BarsLength(x,y,ele);
|
|
figure('Name','Undeformed Truss')
|
|
RenderFrame(ele,Load,Constr,x,y,U,1,'-k',1) %绘制桁架
|
|
figure('Name','Deformed Truss')
|
|
RenderFrame(ele,Load,Constr,x,y,U,0.5,'-k',1) %绘制变形后桁架
|
|
hold on
|
|
%遍历所有单元,将各单元刚度阵分块组装到总体刚度阵
|
|
for iEle =1:EleCount
|
|
%该单元的两个节点的编号
|
|
n1=ele(iEle,2);n2=ele(iEle,3);
|
|
%计算坐标变换矩阵
|
|
R=CoordTransform([x(n1) x(n2)],[y(n1) y(n2)],BarLength(iEle));
|
|
%计算单元刚度矩阵 Ke=R'*ke*R;局部坐标系下的单元刚度阵转换为全局坐标下的单元刚度阵
|
|
ke= FrameElementKe(ele(iEle,4),ele(iEle,5),ele(iEle,6),R,BarLength(iEle));
|
|
%将各单元刚度分块组装到总刚相应位置
|
|
eleDof=[n1*3-2:n1*3,n2*3-2:n2*3];
|
|
K(eleDof,eleDof)=K(eleDof,eleDof)+ke;
|
|
|
|
end
|
|
%形成载荷列阵--1、2、3、4自由度赋载荷值
|
|
for LoadNum=1:size(Load,1)
|
|
for i=1:3
|
|
F(3*Load(LoadNum)+i-3,1)=Load(LoadNum,i);
|
|
end
|
|
end
|
|
%施加约束--乘大数法
|
|
for iConstr=1:size(Constr,1)
|
|
for j=1:3
|
|
if ~isnan(Constr(iConstr,j))
|
|
K(3*Constr(iConstr,1 )+j-3,3*Constr(iConstr,1 )+j-3)=...
|
|
1e12*K(3*Constr(iConstr,1 )+j-3,3*Constr(iConstr,1 )+j-3);
|
|
F(3*Constr(iConstr,1)+j-3)=1e12*Constr(iConstr,j)*...
|
|
K(3*Constr(iConstr,1 )+j-3,3*Constr(iConstr,1)+j-3);
|
|
end
|
|
end
|
|
end
|
|
U=K\F; %全局坐标系下位移,此处原来为逆但是矩阵奇异,故改成伪逆
|
|
for iEle =1:EleCount
|
|
%计算杆局部坐标下的位移
|
|
n1=ele(iEle,2);n2=ele(iEle,3);
|
|
R=CoordTransform([x(n1) x(n2)],[y(n1) y(n2)],BarLength(iEle));
|
|
localU = R*[U(3*n1-2:3*n1,1);U(3*n2-2:3*n2,1)];
|
|
[Ke_local] = FrameElementKeLocal(ele(iEle,4),ele(iEle,5),ele(iEle,6),R,BarLength(iEle))
|
|
EleForce(:, iEle)=Ke_local*localU; %轴力
|
|
end
|
|
|
|
%保存位移,应力与轴力到文本文件
|
|
% fp=fopen('Result.txt','a');
|
|
% str = [char(13,10)','U',' ',num2str(U'),char(13,10)','Stress',' ',...
|
|
% num2str(Stress),char(13,10)','AxialForce',' ',num2str(AxialForce)];
|
|
% fprintf(fp,str);
|
|
% fclose(fp);
|
|
RenderFrame(ele,Load,Constr,x,y,U,1,'-.b',Scale) %绘制变形后桁架
|
|
% figure
|
|
% AxisForcePlot(ele,Load,Constr,x,y,U,3,'-b',Scale,AxialForce)%绘制轴力图
|
|
|
|
end %主程序结束
|
|
|
|
|
|
|
|
|
|
|
|
|