% main.m
% This is the classical �main� routine of the code,
% where the codeflow can be traced and all relevent subfunctions are called.
% The flow of the code will be described in a step by step approach.
%
% written by Ethem Hakan Orhan - Dec 01, 2018
clear all; close all;
% --------------------------------------------
% Step 1: Select Case Folder
% --------------------------------------------
% The program requires 5 files for each problem which includes the node list,
% element list, material properties, boundary conditions and force data.
% These files are packed together in folders with names starting with �case_�.
% The desired case name should be set to the case folder name by commenting out it,
% and commenting in all other case_name lines in this part of the script.
tic;
% case_name = 'case_patch_test';
case_name = 'case_open_hole';
% case_name = 'case_test_1_1';
% case_name = 'case_test_2_2';
% case_name = 'case_test_20_30';
% case_name = 'case_test_32_48';
file_nodes = ['.\',case_name,'\nodes.dat'];
file_elements = ['.\',case_name,'\elements.dat'];
file_forces = ['.\',case_name,'\forces.dat'];
file_BCs = ['.\',case_name,'\BCs.dat'];
file_material = ['.\',case_name,'\material.dat'];
tt1 = toc;
% --------------------------------------------
% Step 2: Load Data - Create Lists
% --------------------------------------------
% Once the case folder is selected and code executed,
% the data in the files is loaded to Matlab workspace in matrix form.
tic;
list_nodes = import_nodes(file_nodes);
list_elements = import_elements(file_elements);
list_forces = import_forces(file_forces);
list_BCs = import_bc(file_BCs);
data_material = import_material(file_material);
E = data_material(1);
nu = data_material(2);
tt2 = toc;
% --------------------------------------------
% Step 3: Construct Nodes
% --------------------------------------------
% Once the node list is created, cNode objects are created using the data
% in the list and all stored in an array: arrNodes
tic;
for i_node = 1:size(list_nodes,1)
n_no = list_nodes(i_node,1);
n_x = list_nodes(i_node,2);
n_y = list_nodes(i_node,3);
arrNodes(i_node) = cNode(n_no, n_x, n_y);
end
tt3 = toc;
% --------------------------------------------
% Step 4: Construct Elements
% --------------------------------------------
% Once the element list and cNode objects are created,
% cElement objects are created using the data in the list and cNode objects
% in the node array, and all stored in an array: arrElements
tic;
for i_ele = 1:size(list_elements,1)
e_no = list_elements(i_ele,1);
n_lst = list_elements(i_ele,[2,3,4,5]);
arrElements(i_ele) = cElement(e_no, arrNodes(n_lst), E, nu );
end
tt4 = toc;
% --------------------------------------------
% Step 5: Calculate Local Stiffness Matrices
% --------------------------------------------
% Looping over all the cElement objects stored in arrElements,
% calculateK function is called at each element to calculate the local stiffness matrices.
tic;
for i_ele = 1:size(list_elements,1)
arrElements(i_ele).calculateK();
end
tt5 = toc;
% --------------------------------------------
% Step 6: Calculate Local Load Vectors
% --------------------------------------------
% Looping over forces defined in force list and the cElement objects stored in arrElements,
% calculateRf function is called at each element to calculate the local force vectors.
% Local force vectors are calculated for the elements which the forces are applied on.
% For the others, the force vector is a zero vector.
tic;
for i_force = 1:size(list_forces,1)
xpos_l = list_forces(i_force, 2);
ypos_l = list_forces(i_force, 3);
xfor_l = list_forces(i_force, 4);
yfor_l = list_forces(i_force, 5);
for i_ele = 1:size(list_elements,1)
selEle = arrElements(i_ele);
[hit] = selEle.calculateRf(xpos_l, ypos_l, xfor_l, yfor_l);
if (hit > 0.5)
disp(['External Force applied on element: ',num2str(i_ele)]);
break;
end
end
end
tt6 = toc;
% --------------------------------------------
% Step 7: Global Stiffness Matrix Reconstruction
% --------------------------------------------
% A global stiffness matrix, K_glob is created with zero elements.
% Looping over the cElement objects stored in arrElements,
% the local stiffness matrices are decomposed into the global matrix.
tic;
n_dof = size(list_nodes,1)*2; % 2D - 2dof at each node.
% initialize K_glob with zeroes
K_glob = zeros(n_dof);
for i_ele = 1:size(list_elements,1)
selEle = arrElements(i_ele);
k = selEle.k;
for li=1:4
gi = list_elements(i_ele, li+1);
for lj=1:4
gj = list_elements(i_ele, lj+1);
l22 = k((2*li-1):(2*li),(2*lj-1):(2*lj));
g22 = K_glob((2*gi-1):(2*gi),(2*gj-1):(2*gj));
K_glob((2*gi-1):(2*gi),(2*gj-1):(2*gj)) = g22 + l22;
end
end
end
tt7 = toc;
% --------------------------------------------
% Step 8: Global Force Vector Reconstruction
% --------------------------------------------
% A global force vector, R_glob is created with zero elements.
% Looping over the cElement objects stored in arrElements,
% the local force vectors are decomposed into the global vector.
tic;
% initialize R_glob with zeroes
R_glob = zeros(n_dof,1);
for i_ele = 1:size(list_elements,1)
selEle = arrElements(i_ele);
Rtot = selEle.Rtot;
for li=1:4
gi = list_elements(i_ele, li+1);
l21 = Rtot((2*li-1):(2*li));
g21 = R_glob((2*gi-1):(2*gi));
R_glob((2*gi-1):(2*gi)) = g21 + l21;
end
end
tt8 = toc;
% --------------------------------------------
% Step 9: Application of Boundary Conditions
% --------------------------------------------
% Looping over the boundary conditions defined in BC list,
% R_glob vector and K_glob matrix are modified according to the BCs.
tic;
bc_rows = [];
bc_vals = [];
for i_bc = 1:size(list_BCs,1)
i_node = list_BCs(i_bc,1);
in_x = list_BCs(i_bc,2);
in_y = list_BCs(i_bc,3);
d_bc = list_BCs(i_bc,4);
if (in_x)
ix = (2*i_node-1);
R_glob = R_glob - K_glob(:,ix)*d_bc;
R_glob(ix) = d_bc;
K_glob(:,ix) = K_glob(:,ix)*0;
K_glob(ix,:) = K_glob(ix,:)*0;
K_glob(ix,ix) = 1;
bc_rows = [bc_rows; ix];
bc_vals = [bc_vals; d_bc];
end
if (in_y)
iy = (2*i_node);
R_glob = R_glob - K_glob(:,iy)*d_bc;
R_glob(iy) = d_bc;
K_glob(:,iy) = K_glob(:,iy)*0;
K_glob(iy,:) = K_glob(iy,:)*0;
K_glob(iy,iy) = 1;
bc_rows = [bc_rows; iy];
bc_vals = [bc_vals; d_bc];
end
end
tt9 = toc;
% --------------------------------------------
% Step 10: Solution of Matrix Eqn for Displacements
% --------------------------------------------
% After the application of BCs, the global stiffness matrix and force vector are simplified.
% Displacements are solved using Matlab matrix operations for these.
% Then the global displacement vector is filled with this solutions and defined BCs appropriately.
tic;
D_glob = K_glob\R_glob;
% Put in lines from D_aux
i_aux = 1;
for i_glob = 1:size(D_glob,1)
is_odd = mod(i_glob,2);
i_xy = floor((i_glob+1)/2);
if (is_odd)
Dxy_glob(i_xy, 1) = D_glob(i_glob);
else
Dxy_glob(i_xy, 2) = D_glob(i_glob);
end
end
% Update nodal displacements in node objects
for i_node = 1:size(list_nodes,1)
x_dis = Dxy_glob(i_node,1);
y_dis = Dxy_glob(i_node,2);
arrNodes(i_node).setDisp(x_dis, y_dis);
end
tt10 = toc;
% ----------------------------------------
没有合适的资源?快使用搜索试试~ 我知道了~
matlab+二维有限元分析
共76个文件
dat:34个
fig:28个
m:10个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 1 下载量 194 浏览量
2022-07-06
19:45:04
上传
评论
收藏 3.35MB ZIP 举报
温馨提示
基于matlab实现了对一个二维的衍架结构的有限元分析,分析应力和应变,实现了数据的可视化,可以转变自己的数据和结构
资源推荐
资源详情
资源评论
收起资源包目录
2D Elasticity - Q4 FEM Solver.zip (76个子文件)
2D Elasticity - Q4 FEM Solver
main.m 13KB
import_nodes.m 3KB
mesh_gen.m 2KB
case_patch_test
elements.dat 104B
nodes.dat 291B
example_patch_test.inp 2KB
forces.dat 74B
BCs.dat 67B
forces_mult.dat 129B
material.dat 57B
cElement.m 10KB
lgwt.m 1KB
import_elements.m 3KB
case_test_2_2
elements.dat 188B
nodes.dat 210B
forces.dat 134B
BCs.dat 69B
nodes_r.dat 246B
material.dat 61B
fig
problem.bmp 1.1MB
stress_ctr.fig 118KB
disp_fld.fig 78KB
mesh.fig 20KB
strain_ctr.fig 115KB
disp_ctr.fig 68KB
cNode.m 1KB
case_test_32_48
elements.dat 93KB
nodes.dat 79KB
forces.dat 79B
BCs.dat 88B
nodes_r.dat 79KB
material.dat 61B
fig
stress_ctr.fig 112KB
disp_fld.fig 101KB
mesh.fig 1.05MB
strain_ctr.fig 117KB
disp_ctr.fig 77KB
case_test_1_1
elements.dat 92B
nodes.dat 110B
forces.dat 97B
BCs.dat 71B
material.dat 61B
fig
stress_ctr.fig 105KB
disp_fld.fig 76KB
single_sigy.bmp 867KB
mesh.fig 16KB
strain_ctr.fig 101KB
disp_ctr.fig 68KB
stress.fig 114KB
disp.fig 78KB
strain.fig 101KB
import_forces.m 2KB
import_bc.m 3KB
import_material.m 3KB
case_test_20_30
elements.dat 19KB
nodes.dat 13KB
forces.dat 99B
BCs.dat 108B
nodes_r.dat 20KB
material.dat 61B
fig
stress_ctr.fig 133KB
disp_fld.fig 103KB
mesh.fig 479KB
strain_ctr.fig 126KB
disp_ctr.fig 79KB
case_open_hole
elements.dat 367B
nodes.dat 981B
forces.dat 82B
BCs.dat 207B
example_open hole.inp 3KB
material.dat 61B
fig
stress_ctr.fig 187KB
disp_fld.fig 110KB
mesh.fig 37KB
strain_ctr.fig 167KB
disp_ctr.fig 118KB
共 76 条
- 1
资源评论
- litianyistudin2023-11-22资源和描述一致,质量不错,解决了我的问题,感谢资源主。
百川数据
- 粉丝: 1
- 资源: 6
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于python实现的多线程爬虫爬取电影天堂资源
- 基于MFC的教职工信息管理系统c++源码含代码注释.zip
- 毕业设计-基于Vue + Node的外卖系统设计与实现
- python烟花代码示例
- 中国各地级市工业三废数据(2006-2021年).xlsx
- 基于MFC的校园导航程序(使用最短路径dijkstra算法).rar
- Android Studio android APP 视频作为视图背景需要源代码或想了解其实现原理的可以私心我
- com.ZeroneGames.GreenProject.apk
- Python自动化开发入门教程
- 4399GameSem_116_13955_207551_6.apk
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功