使用了mVEM包
[node,elem] = nonConvexMesh(box,10,10);
showmesh(node,elem)
n = 25;
[node,elem] = squaremesh([0 1 0 1],1/n,1/n,'rec'); % or input 'tri'
% diameter
NT = size(elem,1);
if ~iscell(elem) % transform to cell
elem = mat2cell(elem,ones(NT,1),length(elem(1,:)));
end
diameter = cellfun(@(index) max(pdist(node(index,:))), elem);
% random perturbation
xrand = sin(2*pi*node(:,1)).*sin(2*pi*node(:,2));
yrand = xrand;
% width = 4;
% xrand = 2*width*(xrand-min(xrand))/(max(xrand)-min(xrand)) - width;
% yrand = 2*width*(yrand-min(yrand))/(max(yrand)-min(yrand)) - width;
% shift length
% tc = 0.1; hmax = max(diameter);
% xs = xrand*hmax/2;
% ys = yrand*hmax/2;
tc = 0.1;
xs = xrand; ys = yrand;
node = node + tc*[xs, ys];
showmesh(node,elem);
box = [-1,1,-1,1];
[p, t] = squaremesh(box, 0.2);
[node,elem] = dualMesh(p,t);
showmesh(node,elem);
由于函数dualMesh
是对原有的三角形网格数据进行处理转化为hex网格的,所以我们也可以先取非一致的三角形剖分在进行hex网格的转换:
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);
[node,elem] = dualMesh(p,t);
showmesh(node,elem);