二维有限元的MATLAB仿真
%Xiamen University, FEM Class - Fall, 2006
%Patch test of 2D code
clear all; close all;
% Geometry properties for a rectangular shape
length = 10; height = 10;
% number of elements in each direction
ndivl = 4;
ndivw = ndivl;
% x,y:the coordinate of every node; node:the relationship of every node; numele;number of elements; total numnod:number of nodes
[x,y,x1,y1,node,numele,numnod] = fem2d_mesh(length,height,ndivl,ndivw);
y1=y1*1.9;
for i=1:ndivw+1
A=y1(i,i);
B=(120-(3+2)*A)/10;
x1(i,:)=B*x1(i,:)+3*A;
end
for i = 1:(ndivl+1)
for j=1:(ndivw+1)
x((ndivw+1)*(i-1)+j) = x1(j,i);
y((ndivw+1)*(i-1)+j) = y1(j,i);
end
end
% Material properties
% Force and Displacement BC'S
[ifix,disp] = fem2d_ebcs(x,y,numnod,ndivl,ndivw);
% Construct Stifffness
ndof = 2; %degrees of freedom per node
% Guass integration points and weights
ksi(1)=-1/sqrt(3); ksi(2)=1/sqrt(3);
weight(1)=1; weight(2)=1;
% numequns:total number of equations; bigk:global stiffness; force:global force
numeqns = numnod*ndof;
bigk = zeros(numeqns);
force = zeros(numeqns,1);
% Loop over elements
% nen is number of nodes per element
nen = 4;
for e = 1:numele
% ke:element stiffness
[ke] = fem2d_stiffness(node,x,y,ksi,weight,e);
% assemble ke into bigk
n1 = ndof-1;
for i=1:nen;
for j=1:nen;
rbk = ndof*(node(i,e)-1) + 1; % row number of bigk
cbk = ndof*(node(j,e)-1) + 1; % colunm number of bigk
rbk1 = ndof*node(i,e); % row number of bigk
cbk1 = ndof*node(j,e); % colunm number of bigk
re = ndof*(i-1)+1; % row number of ke
ce = ndof*(j-1)+1; % colunm number of ke
re1 = ndof*i; % row number of ke
ce1 = ndof*j; % colunm number of ke
bigk(rbk:rbk+n1, cbk:cbk+n1) = bigk(rbk:rbk+n1, cbk:cbk+n1) + ke(re:re+n1, ce:ce+n1);
end
end
end
% Apply zero essential boundary conditions
for n=1:numnod
if (ifix(n) == 1)
force(:) = force(:) - disp(2*n-1)*bigk(:,2*n-1);
bigk(2*n-1,:) = 0;
bigk(:,2*n-1) = 0;
bigk(2*n-1,2*n-1) = 1.0;
force(:) = force(:) - disp(2*n)*bigk(:,2*n);
bigk(2*n,:) = 0;
bigk(:,2*n) = 0;
bigk(2*n,2*n) = 1.0;
end
end
for n=1:numnod
if (ifix(n) == 1)
force(2*n) = disp(2*n);
force(2*n-1) = disp(2*n-1);
end
end
% Solve stiffness equations
disp = bigk\force;
% Put the x,y & disp into matrix, calculate the exact solution
for i=1:(ndivl+1)
for j=1:(ndivw+1)
xh(j,i) = x((i-1)*(ndivw+1)+j);
yh(j,i) = y((i-1)*(ndivw+1)+j);
ux(j,i) = disp(2*((i-1)*(ndivw+1)+j)-1);
uy(j,i) = disp(2*((i-1)*(ndivw+1)+j));
end
end
% plot mesh
figure
for i=1:numele
plot(x(node([1:4,1],i)),y(node([1:4,1],i)),'k-o','linewidth',2,'markersize',12)
hold on
end
for i=1:numnod
text(x(i)+0.2,y(i)-0.3,[num2str(i)],'fontsize',12)
end
figure
surf(xh,yh,ux)
shading interp
title('Patch Test','fontsize',12)
xlabel('x(m)','fontsize',12);ylabel('y(m)','fontsize',12);zlabel('uh(m)','fontsize',12)
set(gca,'fontsize',12)
figure
surf(xh,yh,uy)
shading interp
title('Patch Test','fontsize',12)
xlabel('x(m)','fontsize',12);ylabel('y(m)','fontsize',12);zlabel('uh(m)','fontsize',12)
set(gca,'fontsize',12)
D142
相关文章
- 【电力系统优化调度】计及源荷两侧不确定性的含风电电力系统低碳调度(Matlab代码实现)
- 综合能源系统电压稳定研究(Matlab代码实现)
- 基于粒子群算法优化BP神经网络的PID控制算法(Matlab代码实现)
- 基于重要抽样技术的非序贯蒙特卡洛法(Matlab代码实现)
- 考虑“源-荷-储”协同互动的主动配电网优化调度研究【IEEE33节点】(Matlab代码实现)
- 配电网络扩展规划:考虑使用概率性能源生产和消费概况的决策(Matlab代码实现)
- 【MATLAB】改变坐标轴范围
- 【MATLAB】MATLAB 仿真 — 基于matlab的QPSK系统仿真
- m基于GRNN神经网络和高阶累积量的信号类型识别matlab仿真
- m基于FPGA的MSK调制解调系统verilog开发,并带FPGA误码检测模块和matlab仿真程序
- 通过matlab对比不同调制方式下的球形译码误码率仿真,包括BPSK,QPSK,8PSK,4QAM以及16QAM
- m基于效用函数的联合资源分配matlab仿真,对比PF,CUBP以及DUBP三种方法
- m基于MATLAB的码分多址复用技术的仿真
- m基于MIMO中继通信和非规则LDPC编译码的matlab仿真,其中波束形成为SVD,MMSE,中继包括AF,DF,CF
- m基于MATLAB数字调制解调仿真,包括ASK,FSK,DPSK及MDPSK,对比误码率
- 基于GOA蚱蜢优化算法的KNN分类器最优特征选择matlab仿真
- m基于蚁群优化模糊控制的机器人路线规划和避障算法matlab仿真
- 基于蚁群算法的二维路径规划matlab仿真
- m基于GA遗传优化的三维工程施工设施布局算法matlab仿真,显示二维和三维布局优化效果
- 基于SIFT特征提取的图像特征提取配准和拼接matlab仿真
- 基于Surf+GTM的图像配准和拼接算法matlab仿真
- 基于kmeans算法的数据聚类matlab仿真
- 【MATLAB】matlab 文档使用 ( 文档查询 | 文档层次 | 自带搜索工具 | 帮助命令 | 学习导引 )
- MATLAB学习笔记(五)——MATLAB绘图
- 电力系统经济调度(Matlab代码实现)[Yalmip + Gurobi]
- 【信号处理】MIMO信道容量(Matlab代码实现)
- 【信号检测】基于长短期记忆(LSTM)在OFDM系统中基于深度学习的信号检测(Matlab代码实现)
- 基于UKF的智能泊车MATLAB的仿真,带GUI界面
- m基于遗传优化的凸松弛算法完成从二维人体图像中提取三维姿态的matlab仿真
- 基于基于全局差错能量函数的双目图像立体匹配算法matlab仿真,并提取图像的深度信息
- Matlab使用笔记(九):matlab实现交通流仿真/车感知/城市交通交叉路口