IFEM网格剖分(一):普通网格剖分

本文介绍了如何使用陈龙包IFEM进行多种类型的网格生成,包括三角形、正方形及非结构性网格,还演示了如何利用PolyMesher生成Voronoi多边形网格,并通过Distmesh实现了非一致的三角形剖分。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先在github上下载陈龙包IFEM.
然后把包添加到当前的依赖函数库里:File -> Set Path(IFEM) -> Add with Subfolders

1、三角形一致网格剖分

>> box = [-1, 1, -1, 1];
>> h = 0.1;
>> [node, elem] = squaremesh(box, h);
>> showmesh(node, elem)

请添加图片描述

2、正方形一致网格剖分

>> [node,elem,T] = squarequadmesh(box,h);
>> showmesh(node,elem);

请添加图片描述

3、含退化单元的非结构性网格

在原有的一致三角形网格上使用公式:
x = x ^ + 0.1 ∗ sin ⁡ ( 2 π x ^ ) ∗ sin ⁡ ( 2 π y ^ ) y = y ^ + 0.1 ∗ sin ⁡ ( 2 π x ^ ) ∗ sin ⁡ ( 2 π y ^ ) x=\hat{x}+0.1*\sin(2\pi\hat{x})*\sin(2\pi\hat{y})\\y=\hat{y}+0.1*\sin(2\pi\hat{x})*\sin(2\pi\hat{y}) x=x^+0.1sin(2πx^)sin(2πy^)y=y^+0.1sin(2πx^)sin(2πy^)
在其他的网格上我们也可以使用同样的方法生成非结构网格

>> box = [-1, 1, -1, 1];
>> h = 0.1;
>> [node, elem] = squaremesh(box, h);
x = node(:,1);y=node(:,2);
node(:,1) = x+0.1.*sin(2*pi.*x).*sin(2*pi.*y);
node(:,2) = y+0.1.*sin(2*pi.*x).*sin(2*pi.*y);
>> showmesh(node, elem);

请添加图片描述

4、Voronoi多边形网格(Polymesher):

参考论文:PolyMesher: a general-purpose mesh generator for polygonal elements written in Matlab

[node, elem, ~, ~, ~] = PolyMesher(@MbbDomain,100, 100);

这里,参数中的第一个100是我们要生成的单元个数,第二个100是迭代次数(一般不会取太低,防止单元间尺寸差距过大)。
请添加图片描述
我们再使用showmesh(node, elem);绘制出熟悉的网格。
请添加图片描述

注意

由于一些版本中的陈龙包IFEM中的showmesh函数只能绘制三角形或四边形网格,而绘制多边形网格需要用函数showmeshpoly函数,但我认为showmeshpoly函数画出来的蓝色太丑了。于是绘制多边形网格时,使用mVEM包(Copyright © Terence Yu)里的showmesh函数,其可以展示2D的三角形和多边形网格,甚至3D的网格,功能更加强大,因此绘制多边形时我们采用该函数。

function showmesh(node,elem,options)
%Showmesh displays a mesh in 2-D and 3-D.
%
% Copyright (C) Terence Yu

if nargin==2, options.FaceAlpha = 0.4; end

dim = size(node,2);
if ~iscell(elem)
    h = patch('Faces', elem, 'Vertices', node);    
end
if iscell(elem)
    if iscell(elem{1}), elem = vertcat(elem{:}); end
    max_n_vertices = max(cellfun(@length, elem));
    padding_func = @(vertex_ind) [vertex_ind,...
        NaN(1,max_n_vertices-length(vertex_ind))];  % function to pad the vacancies
    tpad = cellfun(padding_func, elem, 'UniformOutput', false);
    tpad = vertcat(tpad{:});
    h = patch('Faces', tpad, 'Vertices', node);
end

if dim==3
    view(3); set(h,'FaceAlpha',options.FaceAlpha); % transparency
end

if isfield(options,'facecolor') 
    facecolor = options.facecolor;
else
    facecolor = [0.5 0.9 0.45];
end
set(h,'facecolor',facecolor,'edgecolor','k');
axis equal; axis tight;

5、非一致的三角形剖分(Distmesh)

Distmesh可以生成很多种形状的图形,包括在图形中掏一个洞等;

fd=inline('drectangle(p,-1,1,-1,1)','p');
box=[-1,-1;1,1];
fix=[-1,-1;-1,1;1,-1;1,1];
[p,t,~,~]=odtmesh2d(fd,@huniform,0.2,box,fix,1);

其中,变量p,t即为node,elem
请添加图片描述

fd=inline('ddiff(drectangle(p,-1,1,-1,1),dcircle(p,0,0,0.4))','p');
box=[-1,-1;1,1];
fix=[-1,-1;-1,1;1,-1;1,1];
[p,t,~,~]=odtmesh2d(fd,@huniform,0.1,box,fix,1);

在图形中掏一个洞

请添加图片描述

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值