流程和之前的一样,代码如下所示:
Matlab
clc
clear
tic
% 创建 PDE model
model = createpde('structural', 'static-solid');
% 创建需要计算的几何区域
x = [0; 0;5; 5;0; 0;5; 5;]*1e-3;
y = [0;30;0;30;0;30;0;30;]*1e-3;
z = [0; 0;0; 0;3; 3;3; 3;]*1e-3;
K = convhull(x,y,z);
nodes = [x';y';z'];
elements = K';
% 应用几何到模型
geometryFromMesh(model,nodes,elements);
figure(1)
pdegplot(model,"FaceLabels","on","FaceAlpha",0.5)
% Vertex
hold on
plot3(x(1),y(1),z(1),'o')
% 生成网格
generateMesh(model, 'GeometricOrder', 'quadratic', 'Hmax', 0.5e-3);
pdeplot3D(model);
% 定义材料属性
structuralProperties(model, 'YoungsModulus', 210e9, 'PoissonsRatio', 0.28);
% 定义固定的约束边界条件
structuralBC(model,'Face',3,'Constraint','fixed') ; % 固定位移约束
% 定义载荷
structuralBoundaryLoad(model,'Face',6,'Pressure',@myfunPressure);
% 模型求解
results = solve(model);
% 选数据出来
nodecoor = (model.Mesh.Nodes)';
Disa = results.Displacement.Magnitude;
Disy = Disa(nodecoor(:,1)==5e-3&nodecoor(:,3)==0e-3);
ycoor = nodecoor(nodecoor(:,1)==5e-3&nodecoor(:,3)==0e-3,2);
%
figure(1);
pdeplot3D(model,'ColorMapData',results.Displacement.Magnitude,...
'Deformation',results.Displacement,'DeformationScaleFactor',10);
axis equal
figure(2)
plot(ycoor,Disy,'o')
hold on
其中载荷函数通过自定义函数的方式施加:
Matlab
% 自定义施加压力的函数
function structuralVal = myfunPressure(location,~)
a = 1;
structuralVal = 0;
if(location.y<=17e-3&&location.y>=14e-3&&location.x<=3e-3&&location.x>=2e-3)
structuralVal = 20;
end
end
结果如图所示:
