Matlab网格划分程序Distmesh讲解.docx

上传人:工**** 文档编号:544024819 上传时间:2023-04-24 格式:DOCX 页数:8 大小:178.65KB
返回 下载 相关 举报
Matlab网格划分程序Distmesh讲解.docx_第1页
第1页 / 共8页
Matlab网格划分程序Distmesh讲解.docx_第2页
第2页 / 共8页
Matlab网格划分程序Distmesh讲解.docx_第3页
第3页 / 共8页
Matlab网格划分程序Distmesh讲解.docx_第4页
第4页 / 共8页
Matlab网格划分程序Distmesh讲解.docx_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《Matlab网格划分程序Distmesh讲解.docx》由会员分享,可在线阅读,更多相关《Matlab网格划分程序Distmesh讲解.docx(8页珍藏版)》请在金锄头文库上搜索。

1、Matlab网格划分程序Distmesh讲解(一)Distmesh 是一个matlab语言写的网格划分软件。源文件可以从上面的网址获取。这里按行讲解各个算例。p01_demo:概算例是一个单位圆(半径为1)的网格划分,划分后的网格为:以下逐行讲解该算例:function p01_demo ( iteration_max, h )% Parameters:% Input, integer ITERATION_MAX, the maximum number of iterations that DISTMESH% should take. (The program might take fewer

2、 iterations if it detects convergence.)% Input, real h, the mesh spacing parameter.% 这里有两个输入参数,一个是ITERATION_MAX,迭代的最大次数。% 另一个是h, 网格划分的大小。 0h1% 默认参数值为: ITERATION=200 h=0.1 p, t =distmesh_2d( fd, fh, h0, box, iteration_max, fixed );函数需要至少六个参数。d = fd ( p ), p=x yfd 给定任一点到边界的距离函数,本例中定义为: d = sqrt(x2+y2)

3、-1;fh, scaled edge length function h(x,y). 也就是网格大小的函数。h0 也就是h, 网格的大小real BOX(2,2), the bounding box xmin,ymin; xmax,ymax.最大外围矩形范围。 本例中为0,0;1,1ITERATION_MAX, the maximum number of iterations.real PFIX(NFIX,2), the fixed node positions. 网格中需要固定的点坐标,也就是一定需要出现在网格中的点。输出参数:real P(N,2), the node positions.

4、 网格点的x,y坐标integer T(NT,3), the triangle indices. 输出网格任一一个三角形的三个顶点。第一步: x, y = meshgrid ( box(1,1) : h0 : box(2,1), .box(1,2) : h0*sqrt(3)/2 : box(2,2) );根据h0,网格的大小,先把能涵盖欲划分区域的最大矩形划分为结构网格。然后把偶数行的点整体向右平移半格,x(2:2:end,:) = x(2:2:end,:) + h0 / 2;效果如下:第二步:根据fd的函数定义,移除边界外的点。p = p( feval_r( fd, p, varargin:

5、 ) = geps, : );varagin为fd,fh的附加参数,这里为空。geps = 0.001 * h0;也就是保留了到边界的距离以外0.001 * h0以内的点。根据网格密度函数fh,每个点上产生一个0-1随机数,判断是否小于r0/max(r0)大于的话,改点被删除。p = pfix; p(rand(size(p,1),1) r0 ./ max ( r0 ),: ) ; nfix, dummy = size ( pfix );当指定了某些点要保留的时候,把保留的点加入,删除重复的点。% Especially when the user has included fixed point

6、s, we may have a few% duplicates. Get rid of any you spot.%p = unique ( p, rows );N = size ( p, 1 );这个时候产生的网格如下:第三步:迭代pold = inf; %第一次迭代前设置旧的点的坐标为无穷while ( iteration iteration_max ) iteration = iteration + 1;%先判断上次移动后的点和旧的点之间的移动距离,如果小于某个阀值,停止迭代if ( ttol max ( sqrt ( sum ( ( p - pold ).2, 2 ) ) / h0

7、) )pold = p; %如果还可以移动,保存当前的节点t = delaunayn ( p ); %利用delauny算法,生成三角形网格triangulation_count = triangulation_count + 1;pmid = ( p(t(:,1),:) + p(t(:,2),:) + p(t(:,3),:) ) / 3; %计算三角形的重心。t = t( feval_r( fd, pmid, varargin: ) 0;%计算移动梯度,相对边界dgradx = ( feval_r(fd,p(ix,1)+deps,p(ix,2),varargin:) - d(ix) ) /

8、deps;dgrady = ( feval_r(fd,p(ix,1),p(ix,2)+deps,varargin:) - d(ix) ) / deps;%将这些移动到边界外的投射回边界上p(ix,:) = p(ix,:) - d(ix) .* dgradx, d(ix) .* dgrady ;% I needed the following modification to force the fixed points to stay.% Otherwise, they can drift outside the region and be lost.% JVB, 21 August 2008.%p(1:nfix,1:2) = pfix;N = size ( p, 1 );% 8. Termination criterion: All interior nodes move less than dptol (scaled)%if ( max ( sqrt ( sum ( deltat * Ftot ( d -geps,:).2, 2 ) ) / h0 ) dptol )break;endend

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 商业/管理/HR > 其它文档 > 租房合同

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号