




已阅读5页,还剩2页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Matlab 计算效率的提高 参照文On efficient finite element assembly in Matlabby Alejandro A. Ortiz. 用Matlab进行有限元计算,往往采用稀疏矩阵节约内存,一般是一开始就定义整体刚度矩阵为稀疏矩阵,然后再组集,但需要耗费大量时间(见Alejandro A.Ortiz),而作者先使用全矩阵方式求得每个单元矩阵,然后利用K=sparse(I,J,X,freedom,freedom)组集整体刚度矩阵,随着网格的细分,组集效率的提高变得明显。但是作者只举了一个常规有限元三角形单元分析温度场的例子,而我们常常用常规有限元四节点等参单元(更高阶单元)来进行分析问题。需要对该程序进行一些修改。 首先说一下 sparse的用法。 一般我们将full矩阵转换为稀疏矩阵直接采用K=sparse(K)。但是采用K=sparse(I,J,X,freedom,freedom)使得生成稀疏矩阵变得灵活。其中I为freedom X freedom的稀疏矩阵K的非零元素的行标,J为列标,X则为K(I,J)的值。这样只需要知道非零元素在整个矩阵K的位置,即可生成稀疏矩阵。比如I=1 3 2 3;J=1 1 2 4; X=1 3 2 -1;Freedom=5;则 输入 K=sparse(I,J,X,freedom,freedom)得到:K = (1,1) 1 (3,1) 3 (2,2) 2 (3,4) -1 有限元中:一般组集方法:先设置整体刚度矩阵K=sparse(freedom,freedom),然后组集整体刚度矩阵新的组集方法:根据Alejandro A.Ortiz的组集方法是先确定单元full矩阵在整体矩阵的位置,最后K=sparse(I,J,X,freedom,freedom)组集整体刚度矩阵。算例1. 下面分别使用两种组集方法测试尺寸为1m x 1m,弹性模量为1,泊松比取0.3,密度取1的块体在重力作用下组集整体刚度矩阵所需时间。新的组集的程序:% Compute KI=zeros(64*numelem,1);J=zeros(64*numelem,1);K_c=zeros(64*numelem,1); %这里若使用I=,J=,K_c=;在下面循环计算反而要花更多的时间,因为四节点等参单元生成的单元刚度矩阵为8X8,故I维数为64numelem.s=1;q=;ticfor iel=1:numelem sctr = element(iel,:) ; nn = length(sctr); ke = 0; sctr = element(iel,:); % element connectivity %choose Gauss quadrature rules for elements W,Q=quadrature(2,GAUSS,2); %Transfrom these Gauss points to global coords for plotting ONLY for igp = 1:size(W,1) gpnt = Q(igp,:) ; N,dNdxi = lagrange_basis(elemType,gpnt) ; Gpnt = N*node(sctr,:) ; q = q;Gpnt ; end % Determine the position in the global matrix K sctr=element(iel,:); for i=1:length(sctr) sctrB(2*i-1)=2*sctr(i)-1; sctrB(2*i)=2*sctr(i); end r=s; % - % Loop on Gauss points % - for kk = 1 : size(W,1) B=; pt = Q(kk,:); % quadrature point % Jacobian N,dNdxi = lagrange_basis(elemType,pt); % element shape functions J0 = node(sctr,:)*dNdxi; % element Jacobian matrix % B matrix %one node can be related to more than one crack! B=B BbmatQ4(pt,elemType,iel); % Stiffness matrix K_c(r:r+63)= K_c(r:r+63)+reshape(B*C*B*W(kk)*det(J0),64,1); end % end of looping on GPs nb=length(sctrB); numl=nb*nb; IJ=repmat(sctrB,nb,1); I(r:r+numl-1)=repmat(sctrB,1,nb); J(r:r+numl-1)=reshape(IJ,numl,1); %I=I;repmat(sctrB,1,nb); %将耗费更多时间 %J=J;reshape(IJ,numl,1); s=s+64; end % end of looping on elementsK=sparse(I,J,K_c,2*numnode,2*numnode);toc相同网格下所耗时间网格50x50时一般方法please input the x direction divide:50please input the y direction divide:50Elapsed time is 4.989717 seconds.新方法please input the x direction divide:50please input the y direction divide:50Elapsed time is 2.463251 seconds. 80x80的网格一般方法please input the x direction divide:80please input the y direction divide:80Elapsed time is 37.003733 seconds.新方法please input the x direction divide:80please input the y direction divide:80Elapsed time is 9.246477 seconds. 100x100的网格一般的方法please input the x direction divide:100please input the y direction divide:100Elapsed time is 91.080788 seconds.新方法please input the x direction divide:100please input the y direction divide:100Elapsed time is 18.478487 seconds.200x200的网格一般方法please input the x direction divide:200please input the y direction divide:200Elapsed time is 1750.599756 seconds.新方法please input the x direction divide:200please input the y direction divide:200Elapsed time is 231.757482 seconds.可以看出效果十分明显。如果能够加上并行,效果将大增。这种方法其实和谢老的方法十分相似,过程相对复杂,却赢得了时间。算例2:边界裂纹扩展有限元分析(平面板的尺寸1mX2m,裂纹长度a=0.45m,弹性模量E=1e3Pa,泊松比nu=0.3)% -% Loop on elements% -ticI=zeros(64*numelem+1600*8,1);J=zeros(64*numelem+1600*8,1);K_c=zeros(64*numelem+1600*8,1);%由于需要考虑加强自由度(见上图),将预设矩阵放大,再计算完所有单元刚度矩阵后,再将多余的数据去掉。即64*numelem+1600*8需根据网格细分来调整s_i=1;for iel = 1 : numelem sctr = element(iel,:); % element connectivity nn = length(sctr); % number of nodes per element ke = 0 ; % elementary stiffness matrix % - % Choose Gauss quadrature rules for elements if (ismember(iel,split_elem) % split element order = 2 ; phi = ls(sctr,1); W,Q = discontQ4quad(order,phi); elseif (ismember(iel,tip_elem) % tip element order = 7; phi = ls(sctr,1); nodes = node(sctr,:); W,Q = disTipQ4quad(order,phi,nodes,xTip); elseif ( any(intersect(tip_nodes,sctr) = 0)% having tip enriched nodes order = 4 ; W,Q = quadrature(order,GAUSS,2); else order = 2 ; W,Q = quadrature(order,GAUSS,2); end % - % - % Transform these Gauss points to global coords % for plotting only for igp = 1 : size(W,1) gpnt = Q(igp,:); N,dNdxi=lagrange_basis(Q4,gpnt); Gpnt = N * node(sctr,:); % global GP q = q;Gpnt; end % - % Stiffness matrix Ke = BT C B % B = Bfem | Bxfem % The nodal parameters are stored in the following manner: % u = u1 v1 u2 v2 . un vn | a1 b1 . an bn; % It means that the additional unknowns are placed at the end of vector % u. Hence, the true nodal displacement is simply : % u_x = u(1:2:2*numnode) and u_y = u(2:2:2*numnode) % There are two kinds of element: % 1. Non-enriched one (usual element) : calculer comme dhabitude % 2. Enriched one (fully and partially as well): special traitement % Determine the position in the global matrix K sctrB = assembly(iel,enrich_node,pos); nb=length(sctrB); numl=nb*nb; r=s_i; % - % Loop on Gauss points % - for kk = 1 : size(W,1) pt = Q(kk,:); % quadrature point % B matrix B,J0 = xfemBmatrix(pt,elemType,iel,enrich_node,xCr,xTip,alpha); % Stiffness matrix %ke = ke + B*C*B*W(kk)*det(J0); K_c(r:r+numl-1)= K_c(r:r+numl-1)+reshape(B*C*B*W(kk)*det(J0),numl,1); end % end of looping on GPs IJ=repmat(sctrB,nb,1); I(r:r+numl-1)=repmat(sctrB,1,nb); J(r:r+numl-1)=reshape(IJ,numl,1); s_i=s_i+numl;end% end of looping on elementsnd=find(I=0);%找出I多余的数I(nd)=;J(nd)=;K_c(nd)=;K=sparse(I,J,K_c,total_unknown,total_unknown);Toc组集所耗时间20x40的网格旧方法Elapsed time is 1.368753 seconds新方法Elapsed time is 0.993688 seconds.4080的网格旧方法Elapsed time is 9.9833
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 医院配套辅助用房建设项目招商引资报告
- 职业健康法律法规体系解析
- 农文旅融合项目商业计划书(模板范文)
- 电工实习生个人成长总结
- 《农产品地理标志 融水灵芝茶》编制说明
- 电子商务实习个人总结
- 2025学校党委书记年终述职报告范文-1
- 2025年6月部门述职报告
- 关于-面试时简短的自我介绍范文合集六篇
- 代职实习个人总结
- 疗愈人心的创业:90后打造“青年养老院”
- 2024新版(外研版三起孙有中)三年级英语上册单词带音标
- 2025届高三数学一轮复习备考经验交流
- 2024年兴业银行分期还款协议书范文减免利息
- 广西崇左市广西大学附属中学2024-2025学年高一上学期分班测试数学试题A(解析版)
- 核级设备设计制造规范ASME介绍
- 人教版三年级数学上册第六单元《多位数乘一位数》(大单元教学设计)
- 最简单封阳台安全免责协议书
- 成人住院患者静脉血栓栓塞症的预防护理-2023中华护理学会团体标准
- (正式版)JBT 3300-2024 平衡重式叉车 整机试验方法
- 多渠道外贸客户开发
评论
0/150
提交评论